summaryrefslogtreecommitdiff
path: root/swig/CommitCallbacks.h
diff options
context:
space:
mode:
authorKlaus Kämpf <kkaempf@suse.de>2010-11-07 15:51:54 +0100
committerKlaus Kämpf <kkaempf@suse.de>2010-11-07 15:51:54 +0100
commit3f472770771e5ed4717c3e50fbadac9d0423272e (patch)
treec8d42808527348d2cd537469896ce91a1cb9e837 /swig/CommitCallbacks.h
parentf90ebfce3d419a88db82e6f9c8b3d4923d7f4f62 (diff)
downloadlibzypp-bindings-3f472770771e5ed4717c3e50fbadac9d0423272e.tar.gz
libzypp-bindings-3f472770771e5ed4717c3e50fbadac9d0423272e.tar.bz2
libzypp-bindings-3f472770771e5ed4717c3e50fbadac9d0423272e.zip
Second iteration of callbacks
Define CommitCallbacks class with a connect() and disconnect() to a callbacks receiver instance. Add (passing) Ruby and (nonpassing) Python testcase.
Diffstat (limited to 'swig/CommitCallbacks.h')
-rw-r--r--swig/CommitCallbacks.h50
1 files changed, 41 insertions, 9 deletions
diff --git a/swig/CommitCallbacks.h b/swig/CommitCallbacks.h
index e02cb73..ac8b935 100644
--- a/swig/CommitCallbacks.h
+++ b/swig/CommitCallbacks.h
@@ -5,17 +5,12 @@ class CommitCallbacks {
PatchScriptReportReceiver _scriptReceiver;
RemoveResolvableReportReceiver _installReceiver;
InstallResolvableReportReceiver _removeReceiver;
-
Target_Type _instance;
+
public:
- CommitCallbacks(Target_Type instance)
- : _messageReceiver(instance)
- , _scriptReceiver(instance)
- , _installReceiver(instance)
- , _removeReceiver(instance)
+ CommitCallbacks()
+ : _instance(Target_Null)
{
- _instance = instance;
- Target_INCREF(_instance);
_messageReceiver.connect();
_scriptReceiver.connect();
_installReceiver.connect();
@@ -28,6 +23,43 @@ class CommitCallbacks {
_installReceiver.disconnect();
_scriptReceiver.disconnect();
_messageReceiver.disconnect();
- Target_DECREF(_instance);
+ disconnect();
+ }
+ /*
+ * Connect callback to receiver instance
+ * Pass NULL receiver to disconnect
+ *
+ */
+ void connect(Target_Type instance) {
+ disconnect();
+ if (instance) {
+ _instance = instance;
+ Target_INCREF(_instance);
+ _messageReceiver.instance = _instance;
+ _scriptReceiver.instance = _instance;
+ _installReceiver.instance = _instance;
+ _removeReceiver.instance = _instance;
+ }
+ }
+ /*
+ * Disconnect receiver instance
+ *
+ */
+ void disconnect() {
+ if (_instance != Target_Null) {
+ _messageReceiver.instance = Target_Null;
+ _scriptReceiver.instance = Target_Null;
+ _installReceiver.instance = Target_Null;
+ _removeReceiver.instance = Target_Null;
+ Target_DECREF(_instance);
+ _instance = Target_Null;
+ }
+ }
+ /*
+ * Get current receiver instance
+ *
+ */
+ Target_Type receiver() {
+ return _instance;
}
};