2009-01-26 Ramon Novoa <rnovoa@artica.es>

* win32/modules/pandora_module.h,
          win32/modules/pandora_module_factory.cc,
          win32/modules/pandora_module.cc: Added support for async data types.

        * win32/modules/pandora_module_proc.cc: Removed unnecessary call
          to Pandora_Wmi::runProgram.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1398 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
ramonn 2009-01-26 11:48:35 +00:00
parent c23a3d0d01
commit 1f2dfedead
5 changed files with 134 additions and 113 deletions

View File

@ -1,3 +1,12 @@
2009-01-26 Ramon Novoa <rnovoa@artica.es>
* win32/modules/pandora_module.h,
win32/modules/pandora_module_factory.cc,
win32/modules/pandora_module.cc: Added support for async data types.
* win32/modules/pandora_module_proc.cc: Removed unnecessary call
to Pandora_Wmi::runProgram.
2009-01-21 Ramon Novoa <rnovoa@artica.es> 2009-01-21 Ramon Novoa <rnovoa@artica.es>
* win32/bin/PandoraAgent.exe: Updated to r1371. * win32/bin/PandoraAgent.exe: Updated to r1371.

View File

@ -91,6 +91,12 @@ Pandora_Module::parseModuleTypeFromString (string type) {
return TYPE_GENERIC_DATA_STRING; return TYPE_GENERIC_DATA_STRING;
} else if (type == module_generic_proc_str) { } else if (type == module_generic_proc_str) {
return TYPE_GENERIC_PROC; return TYPE_GENERIC_PROC;
} else if (type == module_async_data_str) {
return TYPE_ASYNC_DATA;
} else if (type == module_async_proc_str) {
return TYPE_ASYNC_PROC;
} else if (type == module_async_string_str) {
return TYPE_ASYNC_STRING;
} else { } else {
return TYPE_0; return TYPE_0;
} }
@ -214,7 +220,8 @@ string
Pandora_Module::getDataOutput (Pandora_Data *data) { Pandora_Module::getDataOutput (Pandora_Data *data) {
double value; double value;
if (this->module_type == TYPE_GENERIC_DATA_STRING) { if (this->module_type == TYPE_GENERIC_DATA_STRING ||
this->module_type == TYPE_ASYNC_STRING) {
return data->getValue (); return data->getValue ();
} }

View File

@ -45,13 +45,19 @@ namespace Pandora_Modules {
TYPE_GENERIC_DATA_INC, /**< The value is an integer with TYPE_GENERIC_DATA_INC, /**< The value is an integer with
* incremental diferences */ * incremental diferences */
TYPE_GENERIC_PROC, /**< The value is a 0 or a 1 */ TYPE_GENERIC_PROC, /**< The value is a 0 or a 1 */
TYPE_GENERIC_DATA_STRING /**< The value is a string */ TYPE_GENERIC_DATA_STRING, /**< The value is a string */
TYPE_ASYNC_DATA, /**< Asynchronous generic_data */
TYPE_ASYNC_PROC, /**< Asynchronous generic_proc */
TYPE_ASYNC_STRING /**< Asynchronous generic_data_string */
} Module_Type; } Module_Type;
const string module_generic_data_str = "generic_data"; const string module_generic_data_str = "generic_data";
const string module_generic_data_inc_str = "generic_data_inc"; const string module_generic_data_inc_str = "generic_data_inc";
const string module_generic_proc_str = "generic_proc"; const string module_generic_proc_str = "generic_proc";
const string module_generic_data_string_str = "generic_data_string"; const string module_generic_data_string_str = "generic_data_string";
const string module_async_data_str = "async_data";
const string module_async_proc_str = "async_proc";
const string module_async_string_str = "async_string";
/** /**
* Defines the kind of the module. * Defines the kind of the module.

View File

@ -295,11 +295,14 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
case TYPE_GENERIC_DATA: case TYPE_GENERIC_DATA:
case TYPE_GENERIC_DATA_INC: case TYPE_GENERIC_DATA_INC:
case TYPE_GENERIC_PROC: case TYPE_GENERIC_PROC:
case TYPE_ASYNC_DATA:
case TYPE_ASYNC_PROC:
module->setType (module_type); module->setType (module_type);
numeric = true; numeric = true;
break; break;
case TYPE_GENERIC_DATA_STRING: case TYPE_GENERIC_DATA_STRING:
case TYPE_ASYNC_STRING:
module->setType (module_type); module->setType (module_type);
numeric = false; numeric = false;

View File

@ -18,18 +18,18 @@
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "pandora_module_proc.h" #include "pandora_module_proc.h"
#include "pandora_module_list.h" #include "pandora_module_list.h"
#include "../windows/pandora_wmi.h" #include "../windows/pandora_wmi.h"
#include "../windows/pandora_windows_info.h" #include "../windows/pandora_windows_info.h"
#include "../pandora_strutils.h" #include "../pandora_strutils.h"
#include "../pandora_windows_service.h" #include "../pandora_windows_service.h"
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
using namespace Pandora; using namespace Pandora;
using namespace Pandora_Modules; using namespace Pandora_Modules;
using namespace Pandora_Strutils; using namespace Pandora_Strutils;
using namespace Pandora_Windows_Info; using namespace Pandora_Windows_Info;
/** /**
@ -45,105 +45,101 @@ Pandora_Module_Proc::Pandora_Module_Proc (string name, string process_name)
transform (process_name.begin (), process_name.end (), transform (process_name.begin (), process_name.end (),
this->process_name.begin (), (int (*) (int)) tolower); this->process_name.begin (), (int (*) (int)) tolower);
this->setKind (module_proc_str); this->setKind (module_proc_str);
this->watchdog = false; this->watchdog = false;
this->start_command = ""; this->start_command = "";
} }
string string
Pandora_Module_Proc::getProcessName () const { Pandora_Module_Proc::getProcessName () const {
return this->process_name; return this->process_name;
} }
bool bool
Pandora_Module_Proc::isWatchdog () const { Pandora_Module_Proc::isWatchdog () const {
return this->watchdog; return this->watchdog;
} }
string string
Pandora_Module_Proc::getStartCommand () const { Pandora_Module_Proc::getStartCommand () const {
return this->start_command; return this->start_command;
} }
void void
Pandora_Module_Proc::setWatchdog (bool watchdog) { Pandora_Module_Proc::setWatchdog (bool watchdog) {
this->watchdog = watchdog; this->watchdog = watchdog;
} }
void void
Pandora_Module_Proc::setStartCommand (string command) { Pandora_Module_Proc::setStartCommand (string command) {
this->start_command = command; this->start_command = command;
} }
void void
async_run (Pandora_Module_Proc *module) { async_run (Pandora_Module_Proc *module) {
HANDLE *processes = NULL; HANDLE *processes = NULL;
int nprocess; int nprocess;
DWORD result; DWORD result;
Pandora_Module_List *modules; Pandora_Module_List *modules;
string str_res; string str_res;
string prev_res; string prev_res;
int res; int res;
int i; int i;
prev_res = module->getLatestOutput (); prev_res = module->getLatestOutput ();
modules = new Pandora_Module_List (); modules = new Pandora_Module_List ();
modules->addModule (module); modules->addModule (module);
Sleep (2000); Sleep (2000);
while (1) { while (1) {
processes = getProcessHandles (module->getProcessName ()); processes = getProcessHandles (module->getProcessName ());
if (processes == NULL) { if (processes == NULL) {
if (module->isWatchdog ()) { if (module->isWatchdog ()) {
Pandora_Wmi::runProgram (module->getStartCommand ()); Pandora_Wmi::runProgram (module->getStartCommand ());
} }
Sleep (2000); Sleep (2000);
continue; continue;
} }
/* There are opened processes */ /* There are opened processes */
res = Pandora_Wmi::isProcessRunning (module->getProcessName ()); res = Pandora_Wmi::isProcessRunning (module->getProcessName ());
str_res = inttostr (res); str_res = inttostr (res);
if (str_res != prev_res) { if (str_res != prev_res) {
module->setOutput (str_res); module->setOutput (str_res);
prev_res = str_res; prev_res = str_res;
Pandora_Windows_Service::getInstance ()->sendXml (modules); Pandora_Windows_Service::getInstance ()->sendXml (modules);
} }
/* Wait for this processes */ /* Wait for this processes */
nprocess = res; nprocess = res;
result = WaitForMultipleObjects (nprocess, processes, FALSE, 10000); result = WaitForMultipleObjects (nprocess, processes, FALSE, 10000);
if (result > (WAIT_OBJECT_0 + nprocess - 1)) { if (result > (WAIT_OBJECT_0 + nprocess - 1)) {
/* No event happened */ /* No event happened */
for (i = 0; i < nprocess; i++) for (i = 0; i < nprocess; i++)
CloseHandle (processes[i]); CloseHandle (processes[i]);
pandoraFree (processes); pandoraFree (processes);
continue; continue;
} }
/* Some event happened, probably the process was closed */ /* Some event happened, probably the process was closed */
res = Pandora_Wmi::isProcessRunning (module->getProcessName ()); res = Pandora_Wmi::isProcessRunning (module->getProcessName ());
str_res = inttostr (res); str_res = inttostr (res);
if (str_res != prev_res) { if (str_res != prev_res) {
module->setOutput (str_res); module->setOutput (str_res);
prev_res = str_res; prev_res = str_res;
Pandora_Windows_Service::getInstance ()->sendXml (modules); Pandora_Windows_Service::getInstance ()->sendXml (modules);
} }
if (res == 0 && module->isWatchdog ()) { /* Free handles */
Pandora_Wmi::runProgram (module->getStartCommand ()); for (i = 0; i < nprocess; i++)
} CloseHandle (processes[i]);
pandoraFree (processes);
/* Free handles */ }
for (i = 0; i < nprocess; i++)
CloseHandle (processes[i]); delete modules;
pandoraFree (processes); }
}
delete modules;
}
void void
Pandora_Module_Proc::run () { Pandora_Module_Proc::run () {
@ -153,16 +149,16 @@ Pandora_Module_Proc::run () {
Pandora_Module::run (); Pandora_Module::run ();
} catch (Interval_Not_Fulfilled e) { } catch (Interval_Not_Fulfilled e) {
return; return;
} }
res = Pandora_Wmi::isProcessRunning (this->process_name); res = Pandora_Wmi::isProcessRunning (this->process_name);
this->setOutput (inttostr (res)); this->setOutput (inttostr (res));
/* Launch thread if it's asynchronous */ /* Launch thread if it's asynchronous */
if (this->async) { if (this->async) {
this->thread = CreateThread (NULL, 0, this->thread = CreateThread (NULL, 0,
(LPTHREAD_START_ROUTINE) async_run, (LPTHREAD_START_ROUTINE) async_run,
this, 0, NULL); this, 0, NULL);
this->async = false; this->async = false;
} }
} }