[PATCH 14/50] [mama] Add cache and closure to dqpublisher


Michael Schonberg <mschonberg@...>
 

From: Mike Schonberg <mschonberg@...>

These are both application supplied callbacks. The closure is intended for
application specific context for the publisher and the cache is for caching
data that the publisher may send. In practice the application may use them as
they see fit.

The follow accessors get and set these values:
mamaDQPublisher_setClosure()
mamaDQPublisher_getClosure()
mamaDQPublisher_setCache()
mamaDQPublisher_getCache()

Signed-off-by: Mike Schonberg <mschonberg@...>
---
mama/c_cpp/src/c/dqpublisher.c | 37 +++++++++++++++++++++++++++++++++
mama/c_cpp/src/c/dqpublishermanager.c | 4 +++
mama/c_cpp/src/c/mama/dqpublisher.h | 15 +++++++++++++
3 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/mama/c_cpp/src/c/dqpublisher.c b/mama/c_cpp/src/c/dqpublisher.c
index 4363a1f..d20cc1f 100644
--- a/mama/c_cpp/src/c/dqpublisher.c
+++ b/mama/c_cpp/src/c/dqpublisher.c
@@ -33,6 +33,8 @@ typedef struct mamaDQPublisherImpl_
mamaMsgStatus mStatus;
uint64_t mSenderId;
mama_seqnum_t mSeqNum;
+ void* mClosure;
+ void* mCache;
} mamaDQPublisherImpl;


@@ -300,3 +302,38 @@ void mamaDQPublisher_setSeqNum (mamaDQPublisher pub, mama_seqnum_t num)
}


+void mamaDQPublisher_setClosure (mamaDQPublisher pub, void* closure)
+{
+ mamaDQPublisherImpl* impl = (mamaDQPublisherImpl*) (pub);
+ if (impl)
+ impl->mClosure = closure;
+}
+
+
+void* mamaDQPublisher_getClosure (mamaDQPublisher pub)
+{
+ mamaDQPublisherImpl* impl = (mamaDQPublisherImpl*) (pub);
+
+ if (impl)
+ return impl->mClosure;
+ else
+ return NULL;
+}
+
+void mamaDQPublisher_setCache (mamaDQPublisher pub, void* cache)
+{
+ mamaDQPublisherImpl* impl = (mamaDQPublisherImpl*) (pub);
+ if (impl)
+ impl->mCache = cache;
+}
+
+
+void* mamaDQPublisher_getCache (mamaDQPublisher pub)
+{
+ mamaDQPublisherImpl* impl = (mamaDQPublisherImpl*) (pub);
+
+ if (impl)
+ return impl->mCache;
+ else
+ return NULL;
+}
diff --git a/mama/c_cpp/src/c/dqpublishermanager.c b/mama/c_cpp/src/c/dqpublishermanager.c
index c1bd7d0..0ee62de 100644
--- a/mama/c_cpp/src/c/dqpublishermanager.c
+++ b/mama/c_cpp/src/c/dqpublishermanager.c
@@ -381,6 +381,10 @@ mama_status mamaDQPublisherManager_createPublisher (
return status;
}

+ mamaDQPublisher_setCache(*newPublisher, cache);
+ mamaDQPublisher_setSenderId(*newPublisher, impl->mSenderId);
+ mamaDQPublisher_setStatus(*newPublisher, impl->mStatus);
+ mamaDQPublisher_setSeqNum(*newPublisher, impl->mSeqNum);
if (wtable_insert (impl->mPublisherMap, (char*)symbol, newTopic) != 1)
{
mamaDQPublisher_destroy(*newPublisher);
diff --git a/mama/c_cpp/src/c/mama/dqpublisher.h b/mama/c_cpp/src/c/mama/dqpublisher.h
index c8ae155..0f62030 100644
--- a/mama/c_cpp/src/c/mama/dqpublisher.h
+++ b/mama/c_cpp/src/c/mama/dqpublisher.h
@@ -85,6 +85,7 @@ extern mama_status
mamaDQPublisher_sendReplyWithHandle (mamaDQPublisher pub,
mamaMsgReply replyAddress,
mamaMsg reply);
+
MAMAExpDLL
extern void
mamaDQPublisher_destroy (mamaDQPublisher pub);
@@ -103,7 +104,21 @@ MAMAExpDLL
extern void
mamaDQPublisher_setSeqNum (mamaDQPublisher pub, mama_seqnum_t num);

+MAMAExpDLL
+extern void
+mamaDQPublisher_setClosure (mamaDQPublisher pub, void* closure);
+
+MAMAExpDLL
+extern void*
+mamaDQPublisher_getClosure (mamaDQPublisher pub);

+MAMAExpDLL
+extern void
+mamaDQPublisher_setCache (mamaDQPublisher pub, void* cache);
+
+MAMAExpDLL
+extern void*
+mamaDQPublisher_getCache (mamaDQPublisher pub);

#if defined( __cplusplus )
}
--
1.7.7.6

Join Openmama-dev@lists.openmama.org to automatically receive all group messages.