#define CT_IGNORE 6
#define CT_MB_STRING 7
#define CT_BOOLEAN64 8
+#define CT_SIZE_BYTES 9 /* 64 bit integer, automatically converts K, M, G, T suffixes using 1024 as base) */
+#define CT_SIZE_UNITS 10 /* 64 bit integer, automatically converts K, M, G, T suffixes using 1000 as base) */
/**
* Uninitialized value for override indicator
#define NXCC_RCC_INVALID_REQUEST 5
/**
+ * Base value for custom notifications
+ */
+#define NXCC_CUSTOM_NOTIFICATION_BASE 1000
+
+/**
* Cluster node states
*/
enum ClusterNodeState
virtual void onSplitBrain();
virtual ClusterMessageProcessingResult onMessage(NXCPMessage *msg, UINT32 sourceNodeId);
+ virtual void onNotification(int code, UINT32 sourceNodeId);
};
/**
}
/**
+ * Parse size specification (with K, M, G, or T suffixes)
+ */
+static UINT64 ParseSize(const TCHAR *s, UINT64 multiplier)
+{
+ TCHAR *eptr;
+ UINT64 value = _tcstoull(s, &eptr, 0);
+ if (*eptr == 'K')
+ return value * multiplier;
+ if (*eptr == 'M')
+ return value * multiplier * multiplier;
+ if (*eptr == 'G')
+ return value * multiplier * multiplier * multiplier;
+ if (*eptr == 'T')
+ return value * multiplier * multiplier * multiplier * multiplier;
+ return value;
+}
+
+/**
* Parse configuration template (emulation of old NxLoadConfig() API)
*/
bool Config::parseTemplate(const TCHAR *section, NX_CFG_TEMPLATE *cfgTemplate)
}
*curr = 0;
break;
+ case CT_SIZE_BYTES:
+ *((UINT64 *)cfgTemplate[i].buffer) = ParseSize(value, 1024);
+ break;
+ case CT_SIZE_UNITS:
+ *((UINT64 *)cfgTemplate[i].buffer) = ParseSize(value, 1000);
+ break;
case CT_IGNORE:
break;
default:
{
return CLUSTER_MSG_IGNORED;
}
+
+/**
+ * Incoming notification handler
+ */
+void ClusterEventHandler::onNotification(int code, UINT32 sourceNodeId)
+{
+}
/**
* Process cluster notification
*/
-static void ProcessClusterNotification(ClusterNodeInfo *node, ClusterNotificationCode code)
+static void ProcessClusterNotification(ClusterNodeInfo *node, int code)
{
ClusterDebug(4, _T("ProcessClusterNotification: code %d from node %d [%s]"), code, node->m_id, (const TCHAR *)node->m_addr->toString());
switch(code)
case CN_NODE_RUNNING:
ChangeClusterNodeState(node, CLUSTER_NODE_UP);
break;
+ default:
+ if (code >= CN_CUSTOM)
+ {
+ g_nxccEventHandler->onNotification(code, node->m_id);
+ }
+ break;
}
}
switch(msg->getCode())
{
case CMD_CLUSTER_NOTIFY:
- ProcessClusterNotification(node, (ClusterNotificationCode)msg->getFieldAsInt16(VID_NOTIFICATION_CODE));
+ ProcessClusterNotification(node, msg->getFieldAsInt16(VID_NOTIFICATION_CODE));
delete msg;
break;
case CMD_JOIN_CLUSTER:
enum ClusterNotificationCode
{
CN_NEW_MASTER = 1,
- CN_NODE_RUNNING = 2
+ CN_NODE_RUNNING = 2,
+ CN_CUSTOM = NXCC_CUSTOM_NOTIFICATION_BASE
};
#define ClusterDebug nxlog_debug