/*
*
* ProLinga-Run
*
* Copyright (C) 2002-2009 Xobas Software.
* All rights reserved.
*
* This file is part of ProLinga-Run.
*
* ProLinga-Run 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 3 of the License, or
* (at your option) any later version.
*
* ProLinga-Run 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 ProLinga-Run. If not, see .
*
* More information is available at the following addresses:
*
* Website : http://www.prolinga.org
*
* Email : prolinga-list@prolinga.org
*
*
*/
#include "RunCommon.h"
#include
#include "RunCommand.hpp"
#include "RunConfig.hpp"
#include "BuiltIn.hpp"
//#include "InitRunEnvironment.hpp"
#include
#if BUILD_DATA
#include
#endif
#if BUILD_REPOSITORY
#include
#endif
#if BUILD_VALIDATE
#include
#endif
/* Make sure global handles keep their value */
static GtkWidget *activeStaticScreen;
static BiWebParameterPtr biWebStaticPtr;
static ConfigRunPtr confRunStaticPtr;
static int _argcStatic;
static char **_argvStatic;
/* Global handles */
GtkWidget *activeScreen = activeStaticScreen;
BiWebParameterPtr biWebPtr = biWebStaticPtr;
ConfigRunPtr confRunPtr = confRunStaticPtr;
int _argc = _argcStatic;
char **_argv = _argvStatic;
#if BUILD_DATA
static PlDataPtr datRunStaticPtr;
PlDataPtr datRunPtr = datRunStaticPtr;
#else
static char *dataStaticEndPoint;
char *dataEndPoint = dataStaticEndPoint;
static int dataStaticCompressionLevel;
int dataCompressionLevel = dataStaticCompressionLevel;
#endif
#if BUILD_REPOSITORY
static PlRepositoryPtr repRunStaticPtr;
PlRepositoryPtr repRunPtr = repRunStaticPtr;
#else
static char *repositoryStaticEndPoint;
char *repositoryEndPoint = repositoryStaticEndPoint;
static int repositoryStaticCompressionLevel;
int repositoryCompressionLevel = repositoryStaticCompressionLevel;
#endif
#if BUILD_VALIDATE
static PlValidatePtr valRunStaticPtr;
PlValidatePtr valRunPtr = valRunStaticPtr;
#else
static char *validateStaticEndPoint;
char *validateEndPoint = validateStaticEndPoint;
static int validateStaticCompressionLevel;
int validateCompressionLevel = validateStaticCompressionLevel;
#endif
xmlDocPtr ProcessError(const char *errorString)
{
xmlDocPtr docRunResponse;
char *runResponse;
/* Generate generic error */
runResponse = new char[1024];
strcpy(runResponse, "\n\t\n\t\t\n\t\t\t\n\t\t\t\tError\n\t\t\t\tCan not process Run Command\n\t\t\t\t");
strcat(runResponse, errorString);
strcat(runResponse, "\n\t\t\t\n\t\t\n\t\n");
/* Load response into xml doc */
docRunResponse = xmlParseMemory(runResponse, strlen(runResponse));
/* Clean up */
delete runResponse;
/* Return */
return docRunResponse;
}
PlRun::PlRun()
{
/* Init */
isRunOpen = false;
}
PlRun::~PlRun()
{
/* free */
}
void PlRun::runOpen(const char *configFileName, int argc, char **argv)
{
const char *confName;
#if !defined(BUILD_DATA) || !defined(BUILD_REPOSITORY) || !defined(BUILD_VALIDATE)
char tmpEndPoint[255], *host;
int port;
#endif
ConfigRunPtr confRunPtr;
/* Return if already open */
if (isRunOpen == true)
return;
/* Set global handles */
activeStaticScreen = NULL;
biWebStaticPtr = NULL;
activeScreen = NULL;
biWebPtr = NULL;
/* Get Config */
if (configFileName == NULL)
confName = DEF_CONFIG_FILE;
else
confName = configFileName;
/* Get Config */
confRunPtr = new ConfigRun(confName);
confRunStaticPtr = confRunPtr;
#ifdef BUILD_DATA
datRunPtr = new PlData;
if (argc == -1)
datRunPtr->dataOpen(NULL, _argc, _argv);
else
{
datRunPtr->dataOpen(NULL, argc, argv);
/* Set global arguments */
_argc = argc;
_argcStatic = argc;
_argv = argv;
_argvStatic = argv;
}
datRunStaticPtr = datRunPtr;
#else
/* Set Data EndPoint */
host = confRunPtr->getStringValue("DataHost", DEF_DATA_HOST);
port = confRunPtr->getNumberValue("DataPort", DEF_DATA_PORT);
sprintf(tmpEndPoint, "%s:%d", host, port);
dataEndPoint = new char[strlen(tmpEndPoint)+1];
strcpy(dataEndPoint, tmpEndPoint);
dataStaticEndPoint = dataEndPoint;
/* Set Data CompressionLevel */
dataCompressionLevel = confRunPtr->getNumberValue("DataCompressionLevel", DEF_DATA_COMP_LEVEL);
dataStaticCompressionLevel = dataCompressionLevel;
#endif
#ifdef BUILD_REPOSITORY
/* Open Repository */
repRunPtr = new PlRepository;
repRunPtr->repositoryOpen(NULL);
repRunStaticPtr = repRunPtr;
#else
/* Set Repository EndPoint */
host = confRunPtr->getStringValue("RepositoryHost", DEF_REPOSITORY_HOST);
port = confRunPtr->getNumberValue("RepositoryPort", DEF_REPOSITORY_PORT);
sprintf(tmpEndPoint, "%s:%d", host, port);
repositoryEndPoint = new char[strlen(tmpEndPoint)+1];
strcpy(repositoryEndPoint, tmpEndPoint);
repositoryStaticEndPoint = repositoryEndPoint;
/* Set Repository CompressionLevel */
repositoryCompressionLevel = confRunPtr->getNumberValue("RepositoryCompressionLevel", DEF_REPOSITORY_COMP_LEVEL);
repositoryStaticCompressionLevel = repositoryCompressionLevel;
#endif
#ifdef BUILD_VALIDATE
/* Open Validate */
valRunPtr = new PlValidate;
valRunPtr->validateOpen(NULL);
valRunStaticPtr = valRunPtr;
#else
/* Set Validate EndPoint */
host = confRunPtr->getStringValue("ValidateHost", DEF_VALIDATE_HOST);
port = confRunPtr->getNumberValue("ValidatePort", DEF_VALIDATE_PORT);
sprintf(tmpEndPoint, "%s:%d", host, port);
validateEndPoint = new char[strlen(tmpEndPoint)+1];
strcpy(validateEndPoint, tmpEndPoint);
validateStaticEndPoint = validateEndPoint;
/* Set Validate CompressionLevel */
validateCompressionLevel = confRunPtr->getNumberValue("ValidateCompressionLevel", DEF_VALIDATE_COMP_LEVEL);
validateStaticCompressionLevel = validateCompressionLevel;
#endif
/* Set status */
isRunOpen = true;
/* Free */
delete confRunPtr;
}
void PlRun::runClose(void)
{
/* Return if already closed */
if (isRunOpen == false)
return;
#if BUILD_DATA
datRunPtr->dataClose();
#endif
#if BUILD_VALIDATE
valRunPtr->validateClose();
#endif
#if defined(BUILD_REPOSITORY) && !defined(BUILD_VALIDATE)
repRunPtr->repositoryClose();
#endif
/* Clean up */
delete confRunPtr;
/* Set status */
isRunOpen = false;
}
xmlDocPtr PlRun::executeCommand(const xmlDocPtr runRequest)
{
xmlDocPtr runResponse;
/* Return if run not open or process command */
if (isRunOpen == false)
runResponse = ProcessError("Run not opened.");
else
runResponse = RunCommand(runRequest);
/* Retain values global variables */
activeStaticScreen = activeScreen;
biWebStaticPtr = biWebPtr;
/* Return */
return runResponse;
}