After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 752089 - make gsocketservice::active a property
make gsocketservice::active a property
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: network
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2015-07-07 17:26 UTC by Paolo Borelli
Modified: 2015-07-19 22:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch (6.13 KB, patch)
2015-07-10 19:35 UTC, Paolo Borelli
none Details | Review
patch (9.43 KB, patch)
2015-07-19 14:28 UTC, Paolo Borelli
accepted-commit_now Details | Review

Description Paolo Borelli 2015-07-07 17:26:37 UTC
GSocketService can be stopped and started and has an is_active() getter.

It would be nice if "active" was a real gobject property, since I would like my subclass to have

MySocketService *
my_socket_service_new()
{
  return g_objecy_new(MY_TYPE_SOCKET_SERVICE, "active", FALSE, NULL);
}

So that it can be create in the stopped state and then start only when the initialization of my app is done. I can of course just call stop() but a property would be nice... I can even imagine binding it to other things, e.g to some "state indicator" in the UI.

I can make a patch, unless I am missing some fundamental reason why it is not already a property.

The API could be minimal (just add the property) or add the more conventional set_active/get_active and deprecate start/stop/is_active.
Comment 1 Dan Winship 2015-07-09 15:45:15 UTC
(In reply to Paolo Borelli from comment #0)
> I can make a patch, unless I am missing some fundamental reason why it is
> not already a property.

Makes sense to me. I guess if there is some fundamental problem with the idea you'll discover it while writing the patch...

> The API could be minimal (just add the property) or add the more
> conventional set_active/get_active and deprecate start/stop/is_active.

I'd say just add the property.
Comment 2 Paolo Borelli 2015-07-10 19:35:28 UTC
Created attachment 307266 [details] [review]
patch

Here is the patch. It is pretty much the usual boiler plate so it should be safe, however I admit it is not heavily tested (make check still runs and has a couple of test cases using gsocketservice)
Comment 3 Dan Winship 2015-07-19 10:49:57 UTC
Comment on attachment 307266 [details] [review]
patch

> - it allows us to instanciate objects directly in the stopped state

"instantiate"

>+      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);

space before (

>   /**
>+   * GSocketService::active:

Only one colon between them. (gtk-doc uses class::name for signals, but class:name for properties)

Also, generally class_init functions define signals first and then properties, so put this after ::incoming


It would be good to at least add some assertions to gio/tests/socket-listener.c. (The second test there actually uses GSocketService, not plain GSocketListener, so you can assert that the property changes value when expected.)
Comment 4 Paolo Borelli 2015-07-19 14:28:30 UTC
Created attachment 307679 [details] [review]
patch

Fixed the issues pointed out and added a unit test.

I added the test case to socket-listener.c, but it may be better to split out a socket-service.c and move there also the threaded socket service testcase
Comment 5 Dan Winship 2015-07-19 17:10:23 UTC
Comment on attachment 307679 [details] [review]
patch

Feel free to split the service tests out if you'd like, but you don't have to. (I agree that would be better that way though.) (Remember to add the new test to .gitignore if you do.)
Comment 6 Paolo Borelli 2015-07-19 22:09:21 UTC
I split the file out and pushed