initial Timer class
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 19 Aug 2014 16:41:38 +0000 (19:41 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 19 Aug 2014 18:33:47 +0000 (21:33 +0300)
src/agent/subagents/oracle/main.cpp
src/server/core/events.cpp
src/server/core/nxcore.vcproj
src/server/core/timer.cpp [new file with mode: 0644]
src/server/include/nms_core.h
src/server/include/nms_events.h
src/server/include/server_timers.h [new file with mode: 0644]

index 858a81a..2339eba 100644 (file)
@@ -425,9 +425,9 @@ bool getParametersFromDB( int dbIndex )
        return ret;
 }
 
-//
-// Subagent information
-//
+/**
+ * Supported parameters
+ */
 static NETXMS_SUBAGENT_PARAM m_parameters[] =
 {
        { _T("Oracle.Sessions.Count(*)"), getParameters, _T("X"), DCI_DT_INT, _T("Oracle/Sessions: Number of sessions opened") },
@@ -484,24 +484,20 @@ static NETXMS_SUBAGENT_INFO m_info =
        0,      NULL
 };
 
-
-//
-// Entry point for NetXMS agent
-//
-
+/**
+ * Entry point for NetXMS agent
+ */
 DECLARE_SUBAGENT_ENTRY_POINT(ORACLE)
 {
        *ppInfo = &m_info;
        return TRUE;
 }
 
-
-//
-// DLL entry point
-//
-
 #ifdef _WIN32
 
+/**
+ * DLL entry point
+ */
 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
 {
        if (dwReason == DLL_PROCESS_ATTACH)
index 3fa9b8a..f2e9c3d 100644 (file)
@@ -936,6 +936,35 @@ BOOL NXCORE_EXPORTABLE PostEventWithNames(UINT32 eventCode, UINT32 sourceId, con
  *
  * @param eventCode Event code
  * @param sourceId Event source object ID
+ * @param parameters event parameters list
+ */
+BOOL NXCORE_EXPORTABLE PostEventWithNames(UINT32 eventCode, UINT32 sourceId, StringMap *parameters)
+{
+   int count = parameters->size();
+   if (count > 1023)
+      count = 1023;
+
+   char format[1024];
+   memset(format, 's', count);
+   format[count] = 0;
+
+   const TCHAR *names[1024];
+   const TCHAR *args[1024];
+   for(int i = 0; i < count; i++)
+   {
+      names[i] = parameters->getKeyByIndex(i);
+      args[i] = parameters->getValueByIndex(i);
+   }
+
+//   BOOL bResult = RealPostEvent(g_pEventQueue, eventCode, sourceId, NULL, format, names, args);
+   return bResult;
+}
+
+/**
+ * Post event to system event queue.
+ *
+ * @param eventCode Event code
+ * @param sourceId Event source object ID
  * @param userTag event's user tag
  * @param format Parameter format string, each parameter represented by one character.
  *    The following format characters can be used:
index ca66165..f9f30ee 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath=".\timer.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\tools.cpp"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath="..\include\server_timers.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\..\include\unicode.h"
                                >
                        </File>
diff --git a/src/server/core/timer.cpp b/src/server/core/timer.cpp
new file mode 100644 (file)
index 0000000..8818589
--- /dev/null
@@ -0,0 +1,83 @@
+/* 
+** NetXMS - Network Management System
+** Copyright (C) 2003-2014 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: timer.cpp
+**
+**/
+
+#include "nxcore.h"
+
+/**
+ * Timer queue
+ */
+#ifdef _WIN32
+HANDLE Timer::m_queue = CreateTimerQueue();
+#endif
+
+/**
+ * Timer constructor
+ */
+Timer::Timer(const TCHAR *name, time_t startTime, TimerAction action, UINT32 node, StringMap *parameters)
+{
+   m_name = _tcsdup_ex(name);
+   m_startTime = startTime;
+   m_action = action;
+   m_node = node;
+   m_parameters.addAll(parameters);
+}
+
+/**
+ * Destructor
+ */
+Timer::~Timer()
+{
+   free(m_name);
+#ifdef _WIN32
+   DeleteTimerQueueTimer(m_queue, m_id, NULL);
+#endif
+}
+
+/**
+ * Execute timer
+ */
+void Timer::execute()
+{
+   switch(m_action)
+   {
+      case TIMER_ACTION_SEND_EVENT:
+         PostEventWithNames();
+         break;
+      default:
+         DbgPrintf(4, _T("Unknown timer action %d"), m_action);
+         break;
+   }
+}
+
+/**
+ * Schedule timer
+ */
+void Timer::schedule(Timer *t)
+{
+}
+
+/**
+ * Cancel timer
+ */
+void Timer::cancel(Timer *t)
+{
+}
index 82ac027..b737f7b 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** NetXMS - Network Management System
-** Copyright (C) 2003-2012 Victor Kirhenshtein
+** Copyright (C) 2003-2014 Victor Kirhenshtein
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -97,6 +97,7 @@ typedef __console_ctx * CONSOLE_CTX;
 /**
  * Server includes
  */
+#include "server_timers.h"
 #include "nms_dcoll.h"
 #include "nms_users.h"
 #include "nxcore_winperf.h"
@@ -283,7 +284,6 @@ typedef struct
    void *pData;         // Pointer to data block
 } UPDATE_INFO;
 
-
 /**
  * Extended agent connection
  */
index 3b8468f..6d42de7 100644 (file)
@@ -212,6 +212,7 @@ EVENT_TEMPLATE *FindEventTemplateByName(const TCHAR *pszName);
 
 BOOL NXCORE_EXPORTABLE PostEvent(UINT32 eventCode, UINT32 sourceId, const char *format, ...);
 BOOL NXCORE_EXPORTABLE PostEventWithNames(UINT32 eventCode, UINT32 sourceId, const char *format, const TCHAR **names, ...);
+BOOL NXCORE_EXPORTABLE PostEventWithNames(UINT32 eventCode, UINT32 sourceId, StringMap *parameters);
 BOOL NXCORE_EXPORTABLE PostEventWithTag(UINT32 eventCode, UINT32 sourceId, const TCHAR *userTag, const char *format, ...);
 BOOL NXCORE_EXPORTABLE PostEventEx(Queue *queue, UINT32 eventCode, UINT32 sourceId, const char *format, ...);
 void NXCORE_EXPORTABLE ResendEvents(Queue *queue);
diff --git a/src/server/include/server_timers.h b/src/server/include/server_timers.h
new file mode 100644 (file)
index 0000000..c8fe2a1
--- /dev/null
@@ -0,0 +1,76 @@
+/* 
+** NetXMS - Network Management System
+** Copyright (C) 2003-2014 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: server_timers.h
+**
+**/
+
+#ifndef _server_timers_h_
+#define _server_timers_h_
+
+/**
+ * Timer ID type
+ */
+#if defined(_WIN32)
+#define TIMER_ID  HANDLE
+#elif HAVE_TIMER_T
+#define TIMER_ID  timer_t
+#else
+#define TIMER_ID  int
+#endif
+
+/**
+ * Timer actions
+ */
+enum TimerAction
+{
+   TIMER_ACTION_SEND_EVENT = 0,
+   TIMER_ACTION_EXECUTE_SCRIPT = 1,
+   TIMER_ACTION_EXECUTE_SERVER_ACTION = 2
+};
+
+/**
+ * Timer
+ */
+class NXCORE_EXPORTABLE Timer : public RefCountObject
+{
+private:
+   TIMER_ID m_id;
+   TCHAR *m_name;
+   time_t m_startTime;
+   TimerAction m_action;
+   UINT32 m_node;
+   StringMap m_parameters;
+
+   void execute();
+
+#ifdef _WIN32
+   static HANDLE m_queue;
+#endif
+
+public:
+   Timer(const TCHAR *name, time_t startTime, TimerAction action, UINT32 node, StringMap *parameters);
+   virtual ~Timer();
+
+   time_t getStartTime() { return m_startTime; }
+
+   static void schedule(Timer *t);
+   static void cancel(Timer *t);
+};
+
+#endif