[PATCH 5/5] Add sendtime to DQPublisherManager


Ian Bell <IBell@...>
 

From 94d408a639db9d5de9ff91845eb313b2c0ae8bab Mon Sep 17 00:00:00 2001

Message-Id: <94d408a639db9d5de9ff91845eb313b2c0ae8bab.1348577193.git.ibell@...>

In-Reply-To: <c6056d16f347a98054cb70348d5fbcc988abbf60.1348577193.git.ibell@...>

References: <c6056d16f347a98054cb70348d5fbcc988abbf60.1348577193.git.ibell@...>

From: Ian Bell <ibell@...>

Date: Tue, 25 Sep 2012 13:45:38 +0100

Subject: [PATCH 5/5] Add sendtime to DQPublisherManager

 

Added the ability to add a timefield to the outgoing msg in the

dqpublisher

 

Signed-off-by: Ian Bell <ibell@...>

---

mama/c_cpp/src/c/dqpublisher.c             |  147 ++++++++++++++++++++++++++++

mama/c_cpp/src/c/dqpublishermanager.c      |    9 ++

mama/c_cpp/src/c/mama/dqpublisher.h        |    3 +

mama/c_cpp/src/c/mama/dqpublishermanager.h |    5 +

4 files changed, 164 insertions(+)

 

diff --git a/mama/c_cpp/src/c/dqpublisher.c b/mama/c_cpp/src/c/dqpublisher.c

index e100330..4f30c4b 100644

--- a/mama/c_cpp/src/c/dqpublisher.c

+++ b/mama/c_cpp/src/c/dqpublisher.c

@@ -28,6 +28,7 @@

#include "mama/msgfield.h"

 

+#define MAX_DATE_STR    50

 typedef struct mamaDQPublisherImpl_

{

@@ -37,6 +38,8 @@ typedef struct mamaDQPublisherImpl_

     mama_seqnum_t   mSeqNum;

     void*           mClosure;

     void*           mCache;

+    mamaDateTime    mSendTime;

+    char*           mSendTimeFormat;

} mamaDQPublisherImpl;

 

@@ -51,6 +54,7 @@ mama_status mamaDQPublisher_allocate (mamaDQPublisher* result)

     impl->mStatus = MAMA_MSG_STATUS_OK;

     impl->mSeqNum = 1;

+    impl->mSendTimeFormat = "%T%;";

     *result = impl;

     return MAMA_STATUS_OK;

@@ -152,6 +156,50 @@ mama_status mamaDQPublisher_send (mamaDQPublisher pub, mamaMsg msg)

                     MamaFieldSenderId.mFid, impl->mSenderId);

     }

+    if (impl->mSendTime)

+    {

+        mamaMsgField sendTimeField = NULL;

+        mama_u64_t sendTime =0;

+        char  sendtimestr[MAX_DATE_STR];

+        mamaMsg_getTempCopy (msg, &modifableMsg);

+        mamaDateTime_setToNow(impl->mSendTime);

+        if (MAMA_STATUS_OK == mamaMsg_getField(modifableMsg, MamaFieldSendTime.mName,

+                    MamaFieldSendTime.mFid, &sendTimeField))

+             {

+                             mamaFieldType sendTimeType = MAMA_FIELD_TYPE_UNKNOWN;

+            if (MAMA_STATUS_OK == mamaMsgField_getType(sendTimeField,

+                        &sendTimeType))

+                             {

+                                             switch(sendTimeType)

+                                                             {

+                                                                             case MAMA_FIELD_TYPE_I64:

+                        mamaDateTime_getEpochTimeMilliseconds(impl->mSendTime, &sendTime);

+                        mamaMsgField_updateI64(sendTimeField,(mama_i64_t)sendTime);

+                                                                                             break;

+

+                                                                             case MAMA_FIELD_TYPE_STRING:

+                        mamaDateTime_getAsFormattedString (impl->mSendTime,

+                                                            sendtimestr,

+                                                            MAX_DATE_STR,

+                                                            impl->mSendTimeFormat);

+                        mamaMsg_updateString(modifableMsg, MamaFieldSendTime.mName, 

+                                            MamaFieldSendTime.mFid, sendtimestr);

+                                                                                             break;

+

+                                                                             case MAMA_FIELD_TYPE_TIME:

+                                                                                             mamaMsgField_updateDateTime(sendTimeField, impl->mSendTime);

+                                                                                             break;

+                     default:

+                         mama_log(MAMA_LOG_LEVEL_FINEST, "Unsupported sendtime field format");

+                         break;

+                        

+                                                             }

+                             }

+             }

+             else

+            mamaMsg_addDateTime(modifableMsg, MamaFieldSendTime.mName,

+                    MamaFieldSendTime.mFid, impl->mSendTime);

+    }

     if (modifableMsg)

         return (mamaPublisher_send (impl->mPublisher, modifableMsg));

     else

@@ -213,6 +261,52 @@ mama_status mamaDQPublisher_sendReply (mamaDQPublisher pub,

         }

     }

+    if (impl->mSendTime)

+    {

+        mamaMsgField sendTimeField = NULL;

+        mama_u64_t sendTime =0;

+        char  sendtimestr[MAX_DATE_STR];

+       

+        mamaDateTime_setToNow(impl->mSendTime);

+        if (MAMA_STATUS_OK == mamaMsg_getField(reply, MamaFieldSendTime.mName,

+                    MamaFieldSendTime.mFid, &sendTimeField))

+             {

+                             mamaFieldType sendTimeType = MAMA_FIELD_TYPE_UNKNOWN;

+            if (MAMA_STATUS_OK == mamaMsgField_getType(sendTimeField,

+                        &sendTimeType))

+                             {

+                                             switch(sendTimeType)

+                                                             {

+                                                                             case MAMA_FIELD_TYPE_I64:

+                        mamaDateTime_getEpochTimeMilliseconds(impl->mSendTime, &sendTime);

+                        mamaMsgField_updateI64(sendTimeField,(mama_i64_t)sendTime);

+                                                                                             break;

+

+                                                                             case MAMA_FIELD_TYPE_STRING:

+                        mamaDateTime_getAsFormattedString (impl->mSendTime,

+                                                            sendtimestr,

+                                                            MAX_DATE_STR,

+                                                            impl->mSendTimeFormat);

+                        mamaMsg_updateString(reply, MamaFieldSendTime.mName, 

+                                            MamaFieldSendTime.mFid, sendtimestr);

+                                                                                             break;

+

+                                                                             case MAMA_FIELD_TYPE_TIME:

+                                                                                             mamaMsgField_updateDateTime(sendTimeField, impl->mSendTime);

+                                                                                             break;

+                       

+                     default:

+                         mama_log(MAMA_LOG_LEVEL_FINEST, "Unsupported sendtime field format");

+                         break;

+                       

+                                                             }

+                             }

+             }

+             else

+            mamaMsg_addDateTime(reply, MamaFieldSendTime.mName,

+                    MamaFieldSendTime.mFid, impl->mSendTime);

+    }

+

     return (mamaPublisher_sendReplyToInbox (impl->mPublisher, request, reply));

}

@@ -271,6 +365,50 @@ mama_status mamaDQPublisher_sendReplyWithHandle (mamaDQPublisher pub,

         }

     }

+    if (impl->mSendTime)

+    {

+        mamaMsgField sendTimeField = NULL;

+        mama_u64_t sendTime =0;

+        char  sendtimestr[MAX_DATE_STR];

+       

+        mamaDateTime_setToNow(impl->mSendTime);

+        if (MAMA_STATUS_OK == mamaMsg_getField(reply, MamaFieldSendTime.mName,

+                    MamaFieldSendTime.mFid, &sendTimeField))

+             {

+                             mamaFieldType sendTimeType = MAMA_FIELD_TYPE_UNKNOWN;

+            if (MAMA_STATUS_OK == mamaMsgField_getType(sendTimeField,

+                        &sendTimeType))

+                             {

+                                             switch(sendTimeType)

+                                                             {

+                                                                             case MAMA_FIELD_TYPE_I64:

+                        mamaDateTime_getEpochTimeMilliseconds(impl->mSendTime, &sendTime);

+                        mamaMsgField_updateI64(sendTimeField,(mama_i64_t)sendTime);

+                                                                                             break;

+

+                                                                             case MAMA_FIELD_TYPE_STRING:

+                        mamaDateTime_getAsFormattedString (impl->mSendTime,

+                                                            sendtimestr,

+                                                            MAX_DATE_STR,

+                                                            impl->mSendTimeFormat);

+                        mamaMsg_updateString(reply, MamaFieldSendTime.mName, 

+                                            MamaFieldSendTime.mFid, sendtimestr);

+                                                                                             break;

+

+                                                                             case MAMA_FIELD_TYPE_TIME:

+                                                                                             mamaMsgField_updateDateTime(sendTimeField, impl->mSendTime);

+                                                                                             break;

+                     default:

+                         mama_log(MAMA_LOG_LEVEL_FINEST, "Unsupported sendtime field format");

+                         break;

+                       

+                                                             }

+                             }

+             }

+             else

+            mamaMsg_addDateTime(reply, MamaFieldSendTime.mName,

+                    MamaFieldSendTime.mFid, impl->mSendTime);

+    }

     return (mamaPublisher_sendReplyToInboxHandle (impl->mPublisher,

                 replyAddress, reply));

}

@@ -308,6 +446,15 @@ void mamaDQPublisher_setSeqNum (mamaDQPublisher pub, mama_seqnum_t num)

     impl->mSeqNum=num;

}

+void mamaDQPublisher_enableSendTime (mamaDQPublisher pub, mama_bool_t enable)

+{

+    mamaDQPublisherImpl* impl = (mamaDQPublisherImpl*) (pub);

+

+    if (enable)

+        mamaDateTime_create(&impl->mSendTime);

+    else

+        impl->mSendTime=NULL;

+}

 void mamaDQPublisher_setClosure (mamaDQPublisher pub, void*  closure)

{

diff --git a/mama/c_cpp/src/c/dqpublishermanager.c b/mama/c_cpp/src/c/dqpublishermanager.c

index 4611a87..5142c47 100644

--- a/mama/c_cpp/src/c/dqpublishermanager.c

+++ b/mama/c_cpp/src/c/dqpublishermanager.c

@@ -58,6 +58,7 @@ typedef struct mamaDQPublisherManagerImpl_

     mamaQueue                           mQueue;

     char *                              mNameSpace;

     void*                               mClosure;

+    mama_bool_t                         mEnableSendTime;

 } mamaDQPublisherManagerImpl;

@@ -427,6 +428,7 @@ mama_status mamaDQPublisherManager_createPublisher (

             mamaDQPublisher_setSenderId(*newPublisher,  impl->mSenderId);

             mamaDQPublisher_setStatus(*newPublisher,  impl->mStatus);

             mamaDQPublisher_setSeqNum(*newPublisher, impl->mSeqNum);

+            mamaDQPublisher_enableSendTime(*newPublisher, impl->mEnableSendTime);

             length = strlen(impl->mNameSpace) + 1 + (strlen(symbol) + 1);

             topic = calloc(length, sizeof(char));

@@ -502,6 +504,13 @@ void mamaDQPublisherManager_setSeqNum (

     mamaDQPublisherManagerImpl* impl  = (mamaDQPublisherManagerImpl*) manager;

     impl->mSeqNum=num;

}

+void mamaDQPublisherManager_enableSendTime (

+        mamaDQPublisherManager manager,

+        mama_bool_t enable)

+{

+    mamaDQPublisherManagerImpl* impl  = (mamaDQPublisherManagerImpl*) manager;

+    impl->mEnableSendTime=enable;

+}

 mama_status mamaDQPublisherManager_sendSyncRequest (

         mamaDQPublisherManager manager,

diff --git a/mama/c_cpp/src/c/mama/dqpublisher.h b/mama/c_cpp/src/c/mama/dqpublisher.h

index 4d00eeb..32a4a01 100644

--- a/mama/c_cpp/src/c/mama/dqpublisher.h

+++ b/mama/c_cpp/src/c/mama/dqpublisher.h

@@ -107,6 +107,9 @@ mamaDQPublisher_setSeqNum (mamaDQPublisher pub, mama_seqnum_t num);

MAMAExpDLL

extern void

mamaDQPublisher_setClosure (mamaDQPublisher pub, void*  closure);

+MAMAExpDLL

+extern void

+mamaDQPublisher_enableSendTime (mamaDQPublisher pub, mama_bool_t enable);

 MAMAExpDLL

extern void*

diff --git a/mama/c_cpp/src/c/mama/dqpublishermanager.h b/mama/c_cpp/src/c/mama/dqpublishermanager.h

index 6bf2650..5d95b21 100644

--- a/mama/c_cpp/src/c/mama/dqpublishermanager.h

+++ b/mama/c_cpp/src/c/mama/dqpublishermanager.h

@@ -189,6 +189,11 @@ mamaDQPublisherManager_sendNoSubscribers (

         mamaDQPublisherManager manager,

         const char *symbol);

+MAMAExpDLL

+extern void

+mamaDQPublisherManager_enableSendTime (

+        mamaDQPublisherManager manager,

+        mama_bool_t enable);

#if defined( __cplusplus )

}

#endif /* defined( __cplusplus ) */

--

1.7.9.5

 




Please consider the environment before printing this e-mail.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

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