libnxcc: added option to inform cluster message receiver that message was queued...
authorVictor Kirhenshtein <victor@netxms.org>
Sat, 9 Jan 2016 09:05:55 +0000 (11:05 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Sat, 9 Jan 2016 09:05:55 +0000 (11:05 +0200)
include/nxcc.h
src/libnxcc/ceh.cpp
src/libnxcc/comm.cpp
tests/test-libnxcc/test-libnxcc.cpp

index e82751c..70cf27e 100644 (file)
@@ -39,6 +39,16 @@ enum ClusterNodeState
 };
 
 /**
+ * Cluster message processing result
+ */
+enum ClusterMessageProcessingResult
+{
+   CLUSTER_MSG_IGNORED = 0,
+   CLUSTER_MSG_PROCESSED = 1,
+   CLUSTER_MSG_QUEUED = 2
+};
+
+/**
  * Cluster node event handler
  */
 class LIBNXCC_EXPORTABLE ClusterEventHandler
@@ -52,7 +62,7 @@ public:
    virtual void onNodeDisconnect(UINT32 nodeId);
    virtual void onShutdown();
    
-   virtual bool onMessage(NXCPMessage *msg, UINT32 sourceNodeId);
+   virtual ClusterMessageProcessingResult onMessage(NXCPMessage *msg, UINT32 sourceNodeId);
 };
 
 /**
index e7b3e65..c6b9abd 100644 (file)
@@ -66,9 +66,12 @@ void ClusterEventHandler::onShutdown()
 
 /**
  * Incoming message handler
- * Should return true if message was processed
+ * Possible return values:
+ *    CLUSTER_MSG_PROCESSED - message is processed and should be deleted
+ *    CLUSTER_MSG_QUEUED - message is queued for deferred processing and should not be deleted by caller
+ *    CLUSTER_MSG_IGNORED - message is ignored and should be placed into wait queue
  */
-bool ClusterEventHandler::onMessage(NXCPMessage *msg, UINT32 sourceNodeId)
+ClusterMessageProcessingResult ClusterEventHandler::onMessage(NXCPMessage *msg, UINT32 sourceNodeId)
 {
-   return false;
+   return CLUSTER_MSG_IGNORED;
 }
index dd24ca1..7bc9a88 100644 (file)
@@ -154,10 +154,11 @@ static THREAD_RESULT THREAD_CALL ClusterReceiverThread(void *arg)
                node->m_msgWaitQueue->put(msg);
                break;
             default:
-               if (g_nxccEventHandler->onMessage(msg, node->m_id))
-                  delete msg;
-               else
+               ClusterMessageProcessingResult r = g_nxccEventHandler->onMessage(msg, node->m_id);
+               if (r == CLUSTER_MSG_IGNORED)
                   node->m_msgWaitQueue->put(msg);
+               else if (r == CLUSTER_MSG_PROCESSED)
+                  delete msg;
                break;
          }
       }
index ad1e520..5d439c2 100644 (file)
@@ -35,13 +35,14 @@ public:
       _tprintf(_T("** cluster shutdown\n"));
    }
 
-   virtual bool onMessage(NXCPMessage *msg, UINT32 sourceNodeId)
+   virtual ClusterMessageProcessingResult onMessage(NXCPMessage *msg, UINT32 sourceNodeId)
    {
       if (msg->getCode() == 111)
       {
          ClusterSendResponse(sourceNodeId, msg->getId(), NXCC_RCC_SUCCESS);
+         return CLUSTER_MSG_PROCESSED;
       }
-      return false;
+      return CLUSTER_MSG_IGNORED;
    }
 };