From: dongkwan Date: Wed, 11 Sep 2024 05:44:54 +0000 (+0900) Subject: Add extension X-Git-Tag: accepted/tizen/unified/20240929.151844~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=353dc4dfc858b87daeca0e696779e37f84d92620;p=platform%2Fcore%2Fappfw%2Frpc-port.git Add extension add codes for rust -e(extension) option. - extern rpc_port_get_peer_info - extern rpc_port_stub_has_pending_request - has_pending_pending rust style wrap up function - get_peer_info rust style wrap up function - few unit tests code Change-Id: I8af83b5c1642ef4c47421b3ad2db33c5c6d80c28 Signed-off-by: dongkwan --- diff --git a/src/rust-rpc-port/src/lib.rs b/src/rust-rpc-port/src/lib.rs index 63967bc..7b634c2 100644 --- a/src/rust-rpc-port/src/lib.rs +++ b/src/rust-rpc-port/src/lib.rs @@ -49,6 +49,7 @@ extern "C" { ) -> i32; fn rpc_port_set_private_sharing(h: *mut c_void, path: *const c_char) -> i32; fn rpc_port_unset_private_sharing(h: *mut c_void) -> i32; + fn rpc_port_get_peer_info(rpc_port_h: *mut c_void, pid_t: *mut i32, uid_t: *mut u32) -> i32; } impl Port { @@ -115,4 +116,16 @@ impl Port { Ok(()) } } + + pub fn get_peer_info(&self) -> Result<(i32, u32), i32> + { + let mut pid = -1; + let mut uid = 0; + let ret = unsafe { rpc_port_get_peer_info(self.handle, &mut pid, &mut uid) }; + if ret != 0 { + Err(ret) + } else { + Ok((pid, uid)) + } + } } diff --git a/src/rust-rpc-port/src/stub/mod.rs b/src/rust-rpc-port/src/stub/mod.rs index 61f12b5..344e45b 100644 --- a/src/rust-rpc-port/src/stub/mod.rs +++ b/src/rust-rpc-port/src/stub/mod.rs @@ -11,6 +11,7 @@ extern "C" { fn rpc_port_stub_listen(h: *mut c_void) -> i32; fn rpc_port_stub_add_privilege(h: *mut c_void, privilege: *const c_char) -> i32; fn rpc_port_stub_set_trusted(h: *mut c_void, trusted: bool) -> i32; + fn rpc_port_stub_has_pending_request(rpc_port_h: *mut c_void, has_request: *mut bool) -> i32; fn rpc_port_stub_get_port( h: *mut c_void, port_type: super::CPortType, @@ -106,6 +107,16 @@ impl<'b> Stub<'b> { } } + pub fn has_pending_request(&self) -> Result { + let mut has_request: bool = false; + let ret = unsafe { rpc_port_stub_has_pending_request(self.handle, &mut has_request) }; + if ret == 0 { + Ok(has_request) + } else { + Err(ret) + } + } + pub fn add_privilege(&self, privilege: &str) { let pri = CString::new(privilege).expect("CString::new failed"); let ret = unsafe { rpc_port_stub_add_privilege(self.handle, pri.as_ptr()) }; diff --git a/src/rust-rpc-port/src/stub/tests.rs b/src/rust-rpc-port/src/stub/tests.rs index ccbc88f..7a8a1b2 100644 --- a/src/rust-rpc-port/src/stub/tests.rs +++ b/src/rust-rpc-port/src/stub/tests.rs @@ -42,3 +42,10 @@ fn test_stub_get_port_n() { let stub = Stub::try_new("test").unwrap(); let _ret = stub.get_port(&crate::PortType::Main, "inst1"); } + +#[test] +fn test_stub_has_pending_request() { + let stub = Stub::try_new("test").unwrap(); + let has_request = stub.has_pending_request().unwrap(); + assert_eq!(false, has_request); +} \ No newline at end of file diff --git a/src/rust-rpc-port/src/tests.rs b/src/rust-rpc-port/src/tests.rs index bf5701c..569c063 100644 --- a/src/rust-rpc-port/src/tests.rs +++ b/src/rust-rpc-port/src/tests.rs @@ -46,3 +46,10 @@ fn test_port_unset_private_sharing_n() { let port = Port::new(); port.unset_private_sharing(); } + +#[test] +#[should_panic] +fn test_port_get_peer_info_n() { + let port = Port::new(); + let (pid, uid) = port.get_peer_info().unwrap(); +}