-
-
Notifications
You must be signed in to change notification settings - Fork 131
gio: Fix nullability of various DBus method call related parameters #1584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
// Take a look at the license at the top of the repository in the LICENSE file. | ||
|
||
#[cfg(unix)] | ||
#[test] | ||
fn test_gdbus_peer_connection() { | ||
use gio::{ | ||
glib::{self, VariantTy}, | ||
prelude::*, | ||
DBusConnection, DBusConnectionFlags, DBusNodeInfo, Socket, | ||
}; | ||
use std::os::{fd::IntoRawFd, unix::net::UnixStream}; | ||
|
||
const EXAMPLE_XML: &str = r#" | ||
<node> | ||
<interface name='com.github.gtk_rs'> | ||
<method name='Hello'> | ||
<arg type='s' name='name' direction='in'/> | ||
<arg type='s' name='greet' direction='out'/> | ||
</method> | ||
</interface> | ||
</node> | ||
"#; | ||
|
||
pub async fn spawn_server(fd: UnixStream) -> DBusConnection { | ||
let socket = unsafe { Socket::from_fd(fd.into_raw_fd()) }.unwrap(); | ||
let socket_connection = socket.connection_factory_create_connection(); | ||
|
||
let guid = gio::dbus_generate_guid(); | ||
|
||
dbg!("server connecting"); | ||
|
||
let connection = DBusConnection::new_future( | ||
&socket_connection, | ||
Some(&guid), | ||
DBusConnectionFlags::AUTHENTICATION_SERVER | ||
.union(DBusConnectionFlags::DELAY_MESSAGE_PROCESSING), | ||
None, | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
dbg!("server connected"); | ||
|
||
let interface_info = DBusNodeInfo::for_xml(EXAMPLE_XML) | ||
.unwrap() | ||
.lookup_interface("com.github.gtk_rs") | ||
.unwrap(); | ||
|
||
let _id = connection | ||
.register_object("/com/github/gtk_rs", &interface_info) | ||
.method_call( | ||
|_connection, | ||
_sender, | ||
_object_path, | ||
_interface_name, | ||
_method_name, | ||
parameters, | ||
invocation| { | ||
dbg!( | ||
_sender, | ||
_object_path, | ||
_interface_name, | ||
_method_name, | ||
¶meters, | ||
&invocation | ||
); | ||
|
||
let name = parameters.child_get::<String>(0); | ||
invocation.return_value(Some(&(format!("Hello {name}!"),).to_variant())); | ||
}, | ||
) | ||
.build() | ||
.unwrap(); | ||
|
||
dbg!("server starts message processing"); | ||
|
||
connection.start_message_processing(); | ||
|
||
dbg!("server awaiting calls"); | ||
|
||
connection | ||
} | ||
|
||
pub async fn spawn_client(fd: UnixStream) -> DBusConnection { | ||
let socket_client = unsafe { Socket::from_fd(fd.into_raw_fd()) }.unwrap(); | ||
let socket_connection_client = socket_client.connection_factory_create_connection(); | ||
|
||
dbg!("client connecting"); | ||
|
||
let connection = DBusConnection::new_future( | ||
&socket_connection_client, | ||
None, | ||
DBusConnectionFlags::AUTHENTICATION_CLIENT, | ||
None, | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
dbg!("client connected"); | ||
|
||
connection | ||
} | ||
|
||
let ctx = glib::MainContext::default(); | ||
|
||
let (x, y) = std::os::unix::net::UnixStream::pair().unwrap(); | ||
|
||
x.set_nonblocking(true).unwrap(); | ||
y.set_nonblocking(true).unwrap(); | ||
|
||
ctx.block_on(async move { | ||
let ctx = glib::MainContext::default(); | ||
|
||
let server = ctx.spawn_local(spawn_server(x)); | ||
let client = ctx.spawn_local(spawn_client(y)); | ||
|
||
let server = server.await.unwrap(); | ||
let client = client.await.unwrap(); | ||
|
||
dbg!("calling method"); | ||
|
||
let result = client | ||
.call_future( | ||
None, | ||
"/com/github/gtk_rs", | ||
"com.github.gtk_rs", | ||
"Hello", | ||
Some(&("World",).into()), | ||
Some(VariantTy::new("(s)").unwrap()), | ||
gio::DBusCallFlags::NONE, | ||
10000, | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
dbg!("method called"); | ||
|
||
dbg!(&result); | ||
|
||
dbg!("closing client"); | ||
client.close_future().await.unwrap(); | ||
dbg!("closed client, closing server"); | ||
server.close_future().await.unwrap(); | ||
dbg!("closed server"); | ||
|
||
drop(client); | ||
drop(server); | ||
|
||
assert_eq!(result.child_get::<String>(0), "Hello World!"); | ||
|
||
glib::timeout_future_with_priority( | ||
glib::Priority::LOW, | ||
std::time::Duration::from_millis(50), | ||
) | ||
.await; | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.