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:
parent
c23a3d0d01
commit
1f2dfedead
|
@ -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>
|
||||
|
||||
* win32/bin/PandoraAgent.exe: Updated to r1371.
|
||||
|
|
|
@ -91,6 +91,12 @@ Pandora_Module::parseModuleTypeFromString (string type) {
|
|||
return TYPE_GENERIC_DATA_STRING;
|
||||
} else if (type == module_generic_proc_str) {
|
||||
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 {
|
||||
return TYPE_0;
|
||||
}
|
||||
|
@ -214,7 +220,8 @@ string
|
|||
Pandora_Module::getDataOutput (Pandora_Data *data) {
|
||||
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 ();
|
||||
}
|
||||
|
||||
|
|
|
@ -45,13 +45,19 @@ namespace Pandora_Modules {
|
|||
TYPE_GENERIC_DATA_INC, /**< The value is an integer with
|
||||
* incremental diferences */
|
||||
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;
|
||||
|
||||
const string module_generic_data_str = "generic_data";
|
||||
const string module_generic_data_inc_str = "generic_data_inc";
|
||||
const string module_generic_proc_str = "generic_proc";
|
||||
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.
|
||||
|
|
|
@ -295,11 +295,14 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||
case TYPE_GENERIC_DATA:
|
||||
case TYPE_GENERIC_DATA_INC:
|
||||
case TYPE_GENERIC_PROC:
|
||||
case TYPE_ASYNC_DATA:
|
||||
case TYPE_ASYNC_PROC:
|
||||
module->setType (module_type);
|
||||
numeric = true;
|
||||
|
||||
break;
|
||||
case TYPE_GENERIC_DATA_STRING:
|
||||
case TYPE_ASYNC_STRING:
|
||||
module->setType (module_type);
|
||||
numeric = false;
|
||||
|
||||
|
|
|
@ -18,18 +18,18 @@
|
|||
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 "../windows/pandora_wmi.h"
|
||||
#include "../windows/pandora_wmi.h"
|
||||
#include "../windows/pandora_windows_info.h"
|
||||
#include "../pandora_strutils.h"
|
||||
#include "../pandora_strutils.h"
|
||||
#include "../pandora_windows_service.h"
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
using namespace Pandora;
|
||||
using namespace Pandora_Modules;
|
||||
using namespace Pandora_Strutils;
|
||||
using namespace Pandora_Strutils;
|
||||
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 (),
|
||||
this->process_name.begin (), (int (*) (int)) tolower);
|
||||
|
||||
this->setKind (module_proc_str);
|
||||
|
||||
this->watchdog = false;
|
||||
this->setKind (module_proc_str);
|
||||
|
||||
this->watchdog = false;
|
||||
this->start_command = "";
|
||||
}
|
||||
|
||||
string
|
||||
Pandora_Module_Proc::getProcessName () const {
|
||||
return this->process_name;
|
||||
}
|
||||
|
||||
bool
|
||||
Pandora_Module_Proc::isWatchdog () const {
|
||||
return this->watchdog;
|
||||
}
|
||||
|
||||
string
|
||||
Pandora_Module_Proc::getStartCommand () const {
|
||||
return this->start_command;
|
||||
}
|
||||
|
||||
void
|
||||
Pandora_Module_Proc::setWatchdog (bool watchdog) {
|
||||
this->watchdog = watchdog;
|
||||
}
|
||||
|
||||
void
|
||||
Pandora_Module_Proc::setStartCommand (string command) {
|
||||
this->start_command = command;
|
||||
}
|
||||
|
||||
void
|
||||
async_run (Pandora_Module_Proc *module) {
|
||||
HANDLE *processes = NULL;
|
||||
int nprocess;
|
||||
DWORD result;
|
||||
Pandora_Module_List *modules;
|
||||
string str_res;
|
||||
string prev_res;
|
||||
int res;
|
||||
int i;
|
||||
|
||||
prev_res = module->getLatestOutput ();
|
||||
modules = new Pandora_Module_List ();
|
||||
modules->addModule (module);
|
||||
Sleep (2000);
|
||||
|
||||
while (1) {
|
||||
processes = getProcessHandles (module->getProcessName ());
|
||||
if (processes == NULL) {
|
||||
if (module->isWatchdog ()) {
|
||||
Pandora_Wmi::runProgram (module->getStartCommand ());
|
||||
}
|
||||
Sleep (2000);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* There are opened processes */
|
||||
res = Pandora_Wmi::isProcessRunning (module->getProcessName ());
|
||||
str_res = inttostr (res);
|
||||
if (str_res != prev_res) {
|
||||
module->setOutput (str_res);
|
||||
prev_res = str_res;
|
||||
Pandora_Windows_Service::getInstance ()->sendXml (modules);
|
||||
}
|
||||
|
||||
/* Wait for this processes */
|
||||
nprocess = res;
|
||||
result = WaitForMultipleObjects (nprocess, processes, FALSE, 10000);
|
||||
|
||||
if (result > (WAIT_OBJECT_0 + nprocess - 1)) {
|
||||
/* No event happened */
|
||||
for (i = 0; i < nprocess; i++)
|
||||
CloseHandle (processes[i]);
|
||||
pandoraFree (processes);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Some event happened, probably the process was closed */
|
||||
res = Pandora_Wmi::isProcessRunning (module->getProcessName ());
|
||||
str_res = inttostr (res);
|
||||
if (str_res != prev_res) {
|
||||
module->setOutput (str_res);
|
||||
prev_res = str_res;
|
||||
Pandora_Windows_Service::getInstance ()->sendXml (modules);
|
||||
}
|
||||
|
||||
if (res == 0 && module->isWatchdog ()) {
|
||||
Pandora_Wmi::runProgram (module->getStartCommand ());
|
||||
}
|
||||
|
||||
/* Free handles */
|
||||
for (i = 0; i < nprocess; i++)
|
||||
CloseHandle (processes[i]);
|
||||
pandoraFree (processes);
|
||||
}
|
||||
|
||||
delete modules;
|
||||
}
|
||||
|
||||
string
|
||||
Pandora_Module_Proc::getProcessName () const {
|
||||
return this->process_name;
|
||||
}
|
||||
|
||||
bool
|
||||
Pandora_Module_Proc::isWatchdog () const {
|
||||
return this->watchdog;
|
||||
}
|
||||
|
||||
string
|
||||
Pandora_Module_Proc::getStartCommand () const {
|
||||
return this->start_command;
|
||||
}
|
||||
|
||||
void
|
||||
Pandora_Module_Proc::setWatchdog (bool watchdog) {
|
||||
this->watchdog = watchdog;
|
||||
}
|
||||
|
||||
void
|
||||
Pandora_Module_Proc::setStartCommand (string command) {
|
||||
this->start_command = command;
|
||||
}
|
||||
|
||||
void
|
||||
async_run (Pandora_Module_Proc *module) {
|
||||
HANDLE *processes = NULL;
|
||||
int nprocess;
|
||||
DWORD result;
|
||||
Pandora_Module_List *modules;
|
||||
string str_res;
|
||||
string prev_res;
|
||||
int res;
|
||||
int i;
|
||||
|
||||
prev_res = module->getLatestOutput ();
|
||||
modules = new Pandora_Module_List ();
|
||||
modules->addModule (module);
|
||||
Sleep (2000);
|
||||
|
||||
while (1) {
|
||||
processes = getProcessHandles (module->getProcessName ());
|
||||
if (processes == NULL) {
|
||||
if (module->isWatchdog ()) {
|
||||
Pandora_Wmi::runProgram (module->getStartCommand ());
|
||||
}
|
||||
Sleep (2000);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* There are opened processes */
|
||||
res = Pandora_Wmi::isProcessRunning (module->getProcessName ());
|
||||
str_res = inttostr (res);
|
||||
if (str_res != prev_res) {
|
||||
module->setOutput (str_res);
|
||||
prev_res = str_res;
|
||||
Pandora_Windows_Service::getInstance ()->sendXml (modules);
|
||||
}
|
||||
|
||||
/* Wait for this processes */
|
||||
nprocess = res;
|
||||
result = WaitForMultipleObjects (nprocess, processes, FALSE, 10000);
|
||||
|
||||
if (result > (WAIT_OBJECT_0 + nprocess - 1)) {
|
||||
/* No event happened */
|
||||
for (i = 0; i < nprocess; i++)
|
||||
CloseHandle (processes[i]);
|
||||
pandoraFree (processes);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Some event happened, probably the process was closed */
|
||||
res = Pandora_Wmi::isProcessRunning (module->getProcessName ());
|
||||
str_res = inttostr (res);
|
||||
if (str_res != prev_res) {
|
||||
module->setOutput (str_res);
|
||||
prev_res = str_res;
|
||||
Pandora_Windows_Service::getInstance ()->sendXml (modules);
|
||||
}
|
||||
|
||||
/* Free handles */
|
||||
for (i = 0; i < nprocess; i++)
|
||||
CloseHandle (processes[i]);
|
||||
pandoraFree (processes);
|
||||
}
|
||||
|
||||
delete modules;
|
||||
}
|
||||
|
||||
void
|
||||
Pandora_Module_Proc::run () {
|
||||
|
@ -153,16 +149,16 @@ Pandora_Module_Proc::run () {
|
|||
Pandora_Module::run ();
|
||||
} catch (Interval_Not_Fulfilled e) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
res = Pandora_Wmi::isProcessRunning (this->process_name);
|
||||
this->setOutput (inttostr (res));
|
||||
|
||||
/* Launch thread if it's asynchronous */
|
||||
if (this->async) {
|
||||
this->thread = CreateThread (NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE) async_run,
|
||||
this, 0, NULL);
|
||||
this->async = false;
|
||||
this->setOutput (inttostr (res));
|
||||
|
||||
/* Launch thread if it's asynchronous */
|
||||
if (this->async) {
|
||||
this->thread = CreateThread (NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE) async_run,
|
||||
this, 0, NULL);
|
||||
this->async = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue