Skip to content

Commit 86d006a

Browse files
authored
RSDK-4755: accept entity string for rpc dial (#75)
1 parent 0036a1f commit 86d006a

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

examples/src/ffi/cpp/ffi_echo.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using proto::rpc::examples::echo::v1::EchoService;
1919
extern "C" void *init_rust_runtime();
2020
extern "C" int free_rust_runtime(void *ptr);
2121
extern "C" void free_string(char* s);
22-
extern "C" char *dial(const char *uri, const char *type, const char *payload,
22+
extern "C" char *dial(const char *uri, const char *entity, const char *type, const char *payload,
2323
bool allow_insecure, void *ptr);
2424

2525
class EchoServiceClient {

examples/src/ffi/cpp/ffi_robot.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using viam::robot::v1::ResourceNamesResponse;
1919
extern "C" void *init_rust_runtime();
2020
extern "C" int free_rust_runtime(void *ptr);
2121
extern "C" void free_string(char* s);
22-
extern "C" char *dial(const char *uri, const char *type, const char *payload,
22+
extern "C" char *dial(const char *uri, const char *entity, const char *type, const char *payload,
2323
bool allow_insecure, void *ptr);
2424

2525
class RobotServiceClient {

src/ffi/dial_ffi.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ fn dial_without_cred(
8787

8888
fn dial_with_cred(
8989
uri: String,
90+
entity: Option<String>,
9091
r#type: &str,
9192
payload: &str,
9293
allow_insec: bool,
9394
disable_webrtc: bool,
9495
) -> Result<DialBuilder<WithCredentials>> {
95-
let creds = RPCCredentials::new(None, String::from(r#type), String::from(payload));
96+
let creds = RPCCredentials::new(entity, String::from(r#type), String::from(payload));
9697
let c = DialOptions::builder().uri(&uri).with_credentials(creds);
9798
let c = if disable_webrtc {
9899
c.disable_webrtc()
@@ -117,6 +118,7 @@ fn dial_with_cred(
117118
#[no_mangle]
118119
pub unsafe extern "C" fn dial(
119120
c_uri: *const c_char,
121+
c_entity: *const c_char,
120122
c_type: *const c_char,
121123
c_payload: *const c_char,
122124
c_allow_insec: bool,
@@ -184,11 +186,25 @@ pub unsafe extern "C" fn dial(
184186
false => Some(CStr::from_ptr(c_payload)),
185187
}
186188
};
189+
let entity_opt = {
190+
match c_entity.is_null() {
191+
true => None,
192+
false => match CStr::from_ptr(c_entity).to_str() {
193+
Ok(ent) => Some(ent.to_string()),
194+
Err(e) => {
195+
log::error!("Error unexpectedly received an invalid entity string {:?}", e);
196+
return ptr::null_mut();
197+
}
198+
}
199+
}
200+
};
201+
187202
let (server, channel) = match runtime.block_on(async move {
188203
let channel = match (r#type, payload) {
189204
(Some(t), Some(p)) => {
190205
dial_with_cred(
191206
uri_str,
207+
entity_opt,
192208
t.to_str()?,
193209
p.to_str()?,
194210
allow_insec,

0 commit comments

Comments
 (0)