/*
*
* ProLinga-Data
*
* Copyright (C) 2002-2008 Xobas Software.
* All rights reserved.
*
* This file is part of ProLinga-Data.
*
* ProLinga-Data 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-Data 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-Data. If not, see .
*
* More information is available at the following addresses:
*
* Website : http://www.prolinga.org
*
* Email : prolinga-list@prolinga.org
*
*
*/
#include "DatCommon.h"
#include
#include "DCDataCommand.hpp"
#include "DatConfig.hpp"
#include "DCSession.hpp"
#include "DatMain.hpp"
/* Make sure global handles keep their value */
static DCSessionPtr sesStaticPtr;
static int _argcStatic;
static char **_argvStatic;
/* Global handles */
DCSessionPtr sesPtr = sesStaticPtr;
int _argc = _argcStatic;
char **_argv = _argvStatic;
xmlDocPtr DCProcessError(char *errorString)
{
xmlDocPtr docDataResponse;
char *dataResponse;
/* Generate generic error */
dataResponse = new char[1024];
strcpy(dataResponse, "\n\t\n\t\t\n\t\t\t\n\t\t\t\tError\n\t\t\t\tCan not process Data Command\n\t\t\t\t");
strcat(dataResponse, errorString);
strcat(dataResponse, "\n\t\t\t\n\t\t\n\t\n");
/* Load response into xml doc */
docDataResponse = xmlParseMemory(dataResponse, strlen(dataResponse));
/* Clean up */
delete dataResponse;
/* Return */
return docDataResponse;
}
PlData::PlData()
{
/* Init */
isDataOpen = false;
}
PlData::~PlData()
{
/* free */
}
void PlData::dataOpen(const char *configFileName, int argc, char **argv)
{
char *confName;
/* Return if already open */
if (isDataOpen == true)
return;
/* Init libgda */
if (argc == -1)
gda_init("prolinga-data", "1.0", _argc, _argv);
else
{
gda_init("prolinga-data", "1.0", argc, argv);
/* Set global arguments */
_argc = argc;
_argcStatic = argc;
_argv = argv;
_argvStatic = argv;
}
/* Set global database handles */
sesPtr = new DCSession;
sesStaticPtr = sesPtr;
/* Get Config */
if (configFileName == NULL)
confName = DEF_CONFIG_FILE;
else
confName = (char *)configFileName;
/* Set status */
isDataOpen = true;
}
void PlData::dataClose(void)
{
/* Return if already closed */
if (isDataOpen == false)
return;
/* Set status */
isDataOpen = false;
/* Close GDA */
//gda_main_quit();
/* Free */
delete sesPtr;
sesStaticPtr = NULL;
sesPtr = NULL;
}
xmlDocPtr PlData::executeCommand(const xmlDocPtr dataRequest)
{
xmlDocPtr dataResponse;
/* Return if repository not open or process command */
if (isDataOpen == false)
dataResponse = DCProcessError("Data not opened.");
else
dataResponse = DCDataCommand(dataRequest);
/* Return */
return dataResponse;
}