GNOME Bugzilla – Bug 752089
make gsocketservice::active a property
Last modified: 2015-07-19 22:09:21 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.
(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.
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 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.)
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 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.)
I split the file out and pushed