RequestAbstract.h 2.28 KB
#ifndef REQUESTABSTRACT_H
#define REQUESTABSTRACT_H

#include <string>

#include "../Application/Application.h"
#include "../WorkingDirManager/WorkingDirManager.h"
#include "RequestLoader.h"
#include "ResultWriter.h"

using namespace TREPS::Application;
using namespace TREPS::WorkingDirManager;

namespace TREPS
{
	namespace RequestManager
	{
		//enumerate that define the request output type
		typedef enum {
			//no output file. Just return OK if the request execution is a success
			OUTPUT_NONE,
			//send a path to a existing xml file
			OUTPUT_XMLFILE,
			//send a path to a generated result file (in a workind dir)
			OUTPUT_RESULTFILE,
			//send a single string
			OUTPUT_STRING
			} t_RequestOutputType;
		
		//Base class to use for all requests!
		class RequestAbstractClass
		{
			public:
				RequestAbstractClass(void);
				
				virtual ~RequestAbstractClass(void) = 0;

				//get request id
				virtual string getRequestId(void) = 0;

				//load request
				virtual bool load(RequestLoaderClass *loader) = 0;
				
				//execute the request process
				virtual bool run(void) = 0;
				
				//write the content of the request result file
				virtual void writeResult(ResultWriterClass *writer) = 0;

				//get the working dir of the current operation
				string getWorkingDir(void);

				//init the oeration id
				bool initOpId(RequestLoaderClass *loader, bool lockWorkingDir);

				//get request output type
				t_RequestOutputType getOutputType(void);

				//To know if this request use the cache - By default set to false
				bool useCacheResult(void);

				//specific suffix used to name result file - only used when the request type is OUTPUT_RESULTFILE
				virtual string getResultFileSuffix(void) = 0;

				//xml file path used as result - only used when the request type is OUTPUT_XMLFILE
				virtual string getXMLFilePath(void) = 0;

				//string as result - only used when the request type is OUTPUT_STRING
				virtual string getStringResult(void) = 0;

				//set request status in opêration list file
				void setStatus(const char *status);

			protected:
				ApplicationClass *app;

				WorkingDirManagerClass *dirMgr;
				
				string opId;

				bool useCache;

				t_RequestOutputType outputType;
		};
	}
}

#endif