Add notifyRemoteUpdate and notifyLocalChange functions in serializable#53
Add notifyRemoteUpdate and notifyLocalChange functions in serializable#53jafyvilla merged 1 commit intoHBPVIS:masterfrom
Conversation
|
servus/serializable.h
Outdated
| /** @internal used by ZeroEQ to invoke updated function */ | ||
| /** @internal used by ZeroEQ to invoke 'localChange' function */ | ||
| SERVUS_API void notifyLocalChange() const; | ||
| /** @internal used by ZeroEQ to invoke 'remoteUpdate' function */ |
There was a problem hiding this comment.
Very good, I was also suggesting in the other(?) PR that notifyRemoteUpdate() and notifyRequested() can be made private and called internally by the public to/fromJSON/Binary().
There was a problem hiding this comment.
If possible, yes and agreed.
servus/serializable.h
Outdated
| * Set a new function called after the object has been updated remotely | ||
| * (via a subscriber, a http server, loading from file...). | ||
| */ | ||
| SERVUS_API void setRemoteUpdateFunction( const ChangeFunc& func ); |
There was a problem hiding this comment.
What about setUpdatedFunction and setReceivedFunction?
There was a problem hiding this comment.
I'm bad with naming, but I thought that specifying the source of the change/update in the name of the method (local or remote) helps to understand the semantics. Maybe not...
There was a problem hiding this comment.
could work as well. In fact, the distinction between 'remote' and 'local' does not make sense for file (de)serialization (provided by Lunchbox), and 'received' would also be inaccurate in this case. It is hard to find good names, but what about:
setSerializeCallback(), setDeserializedCallback(), setChangedCallback()?
There was a problem hiding this comment.
I'm fine with Raphael's propositions, also because I can't come up with better ones :)
For more API safety, the three functions should be different types. Today they have the same signature, but for instance the changed callback could hint which member has changed. This change won't break then the other two functions.
There was a problem hiding this comment.
Whether it it's set- or add- callbacks, a remove/unset is needed as well. For symmetry, for temporary listeners, etc.
There was a problem hiding this comment.
True, a mechanism to unset is needed. To keep the API simple is it possible to get away with setting a "null" function instead of having an explicit unset? (This only works in the case of a single callback of course.)
There was a problem hiding this comment.
I disagree here. As a library user, 'set' implies a single instance and 'add' multiple. Having 'set' maintain multiple is a hack for the debatable reason of not changing the API (but the semantics!)
|
Good with me. For the record: This means we will likely break the API when we need multiple observers, because setFoo has not the same semantics as addFoo in an API, i.e., the current set API cannot be used for multi-observers. |
|
We can try to avoid that by already renaming it to addFoo, even if it's just a set for now; or leaving it as setFoo and, when we need multiple, specify in the documentation that it supports setting more than one function. |
servus/serializable.h
Outdated
| /** | ||
| * Set a new function called when a request has been received. | ||
| * | ||
| * Invoked before the object is published. |
There was a problem hiding this comment.
published -> serialized
published is very specific to ZeroEQ
e7c5346 to
96b4143
Compare
|
Updated |
96b4143 to
2b86715
Compare
|
Adapted other projects to this change: But don't merge any of them yet |
servus/serializable.h
Outdated
| ChangeFunc _updated; | ||
| ChangeFunc _requested; | ||
| SERVUS_API void _notifyDeserialized() const; | ||
| SERVUS_API void _notifySerialize() const; |
There was a problem hiding this comment.
since we have a pimpl now they don't need to appear in the private section
|
C&P since the other one is not default visible: I disagree here. As a library user, 'set' implies a single instance and 'add' multiple. Having 'set' maintain multiple is a hack for the debatable reason of not changing the API (but the semantics!) |
servus/serializable.cpp
Outdated
| void registerSerializeCallback( const Serializable::SerializeFunc& func ) | ||
| { | ||
| serialize = func; | ||
| } |
There was a problem hiding this comment.
Are these needed? funcs are public...
There was a problem hiding this comment.
The idea here is that when we need more than one observer and start using signals, we can keep the same interface for the connection of the signals/slots. That way the signals remain hidden in the implementation, and if we use boost, for example, the dependency doesn't leak through the header.
There was a problem hiding this comment.
No, a least for me it was just a code style comment :-)
instead of having these functions just _impl->serialize = func instead of _impl->registerChangedCallback( func )
There was a problem hiding this comment.
Ah, got it. Sure.
|
I'm confused... in the latest patch I replaced the 'set' naming with 'register' |
I had missed this patch. It feels slightly better, although we still would change semantics 'on the fly'. |
|
To me, if I read the code |
|
Then we should throw today if there is already one registered. |
|
True. |
588e330 to
af6c9c1
Compare
servus/serializable.h
Outdated
| { return _fromBinary( data.ptr.get(), data.size ); } | ||
| bool fromBinary( const void* data, const size_t size ) | ||
| { return _fromBinary( data, size ); } | ||
| bool fromBinary( const Data& data ); |
There was a problem hiding this comment.
Please add SERVUS_API for non-inline functions
af6c9c1 to
6ed18ec
Compare
servus/serializable.h
Outdated
| * | ||
| * Invoked before the object is published. | ||
| * @return the previously set function. | ||
| * Register a new function called when a request has been received. |
There was a problem hiding this comment.
when the serializable is about to be serialized.
40dc31e to
273d9a8
Compare
|
Retest this please |
|
Everything seems to work again. Please review this together with: and then I will start merging and updating sha1 sums. |
servus/serializable.cpp
Outdated
| { | ||
| if( _updated ) | ||
| _updated(); | ||
| _impl->deserialized = func; |
There was a problem hiding this comment.
throw if current func exists still missing?
There was a problem hiding this comment.
If it throws, then it has to be documented and unit tested.
For the record, my preference still remains to support a single callback unless someone finds a really good use case for multiple callbacks, which I don't foresee is going to be needed.
There was a problem hiding this comment.
I forgot about that, and I'm actually not sure about it. That means that if users want to replace the registered function, they can't unless they deregister it first (which at the moment is only possible by registering a void function). We don't have the use case though, so I can implement the throw until multiple callbacks are supported. I'll update the change including also the bool() type callbacks.
There was a problem hiding this comment.
Whichever way: consistency matters. If the API is designed for multi callback as it is now, at least it should throw if stuff is unimplemented so we won't change semantics when we implement them.
There was a problem hiding this comment.
if users want to replace the registered function, they can't unless they deregister it first
Which is exactly the semantics of the API. register adds a callback, if you call it twice you've got two callbacks. Right now we silently do something else, hence we will break semantics later.
Iff we want a single callback, the methods should be get/set and we'll break the API when we need multiples.
|
+1 for this change and the dependent ones, after the get/set() (or throw) solution is implemented. |
2dbbed4 to
19bc6dd
Compare
|
Updated with the throw mechanism |
| ChangeFunc _updated; | ||
| ChangeFunc _requested; | ||
| class Impl; | ||
| Impl* _impl; |
There was a problem hiding this comment.
You need to deactivate or implement the assignment operator and copy constructor, otherwise will lead to double free/missing free of _impl.
|
+1 otherwise |
2e68bd6 to
483c2d6
Compare
Separated semantics for local changes (Collage::Distributable use case) and remote updates (ZeroEQ events). Use pimpl in serializable.
483c2d6 to
2c9e541
Compare
|
Retest this please |
Separated semantics for local changes (Collage::Distributable use case)
and remote updates (ZeroEQ events).
Use pimpl in serializable.