00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _CCOMMUNICATIONHANDLER
00030 #define _CCOMMUNICATIONHANDLER
00031 #include "libMRML/include/uses-declarations.h"
00032
00033 #include <expat.h>
00034
00035 #include "libMRML/include/CAttributeList.h"
00036
00037
00038 #include "libMRML/include/CSessionManager.h"
00039 #include "libMRML/include/CXMLElement.h"
00040 #include <functional>
00041 #include <iostream>
00042 #include <fstream>
00043 #include "libMRML/include/CMutex.h"
00044
00046 extern void startMRMLElement(void *userData,
00047 const char *inElementName,
00048 const char **inAttributes);
00049 extern void endMRMLElement(void *userData, const char *name);
00050
00054 class CCommunicationHandler{
00055
00060 CSelfDestroyPointer<CXMLElement> mDocumentRoot;
00061
00064 XML_Parser mParser;
00065
00068 CSessionManager& mSessionManager;
00074 CAlgorithm* mAlgorithmTree;
00079 CSelfDestroyPointer<CXMLElement> mCurrentTree;
00080
00086 string mPeerAddressString;
00087
00088 public:
00096 CSelfDestroyPointer<CXMLElement> mMultiResponse;
00097
00098 protected:
00105 int mQueryAtRandomCount;
00106 protected:
00108 int mSocket;
00112 ofstream& mLog;
00113 public:
00114
00116
00118 void setSocket(int inSocket);
00119
00120
00122
00124 string preamble();
00125
00126
00127
00129 string frame(const string& inSession,
00130 const string& inString);
00131
00132
00133
00135 string toAttribute(string inName,
00136 string inString);
00137
00138
00139 string toAttribute(string inName,
00140 int inInt);
00141
00142
00143 string toAttribute(string inName,
00144 double inFloat);
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00157 int sendError(const string& inSession,
00158 const string& inMessage);
00159
00160
00162 void openSession(const string& inUserName,
00163 const string& inSessionName);
00165 void renameSession(const string& inSessionID,
00166 const string& inNewName);
00167
00169 void deleteSession(const string& inName);
00170
00171
00174 void getPropertySheet(const string& inSessionID,
00175 const string& inAlgorithmID);
00176
00178 int sendHandshake(const string& inUser);
00179
00181 void getSessions(const string& inUser);
00183 void getCollections();
00185 void getAlgorithms();
00186
00188 int sendResult(const string& inSession,
00189 const CXMLElement& inRLL);
00190
00191
00192
00194 int sendRandomImages(const string& inSession,
00195 const string& inAlgorithm,
00196 const string& inCollection,
00197 const string& inNumberOfImages) ;
00198 ;
00199
00200
00201
00203
00204 CXMLElement* gQueryImages;
00205 string mSessionID;
00206 int mResultSize;
00207 double mCutoff;
00208 string mCollection;
00209 string mAlgorithm;
00210
00211
00213 void setResultSize(int inResultSize);
00214
00215
00216 void setResultCutoff(const string& inCutoff);
00217
00218 void setResultCutoff(double inCutoff);
00219
00220
00221 void setCollectionID(const string& inID);
00222
00223
00224 void setAlgorithmID(const string& inID);
00225
00226
00229 void startTreeBuilding(const char* inElementName,
00230 const char*const*const inAttributes);
00233 void addToCurrentTree(const char* inElementName,
00234 const char*const*const inAttributes);
00238 void moveUpCurrentTree();
00242 bool isBuildingTree()const;
00243
00244
00246
00247 void parseString(const string& inMessage);
00248
00249
00250
00260 void clearAlgorithmElement();
00261
00274
00275 void startAlgorithmElement(const char* inName,
00276 const char* const* const inAttributes);
00277
00281
00282 void endAlgorithmElement();
00283
00287
00288 void initAlgorithmElement();
00289
00292
00293 CAlgorithm* readAlgorithmElement();
00294
00300 void endConfiguration();
00301
00302
00306 bool mParsingFinished;
00307 void clearParsingFinished();
00308 void setParsingFinished();
00309 bool isParsingFinished()const;
00310
00311 bool readAndParse();
00312
00313
00314
00315 void makeParser();
00316
00317
00331 void startMultiRequest(const string& inSessionID, const string& inLanguageCode="en");
00333 void endMultiRequest();
00337 void addToMultiResponse(CXMLElement* inElement);
00339 const string getCurrentSessionID();
00340
00341
00342
00345
00346 CSessionManager& getSessionManager();
00347
00349 void incrementQueryAtRandomCount();
00351 int getQueryAtRandomCount()const;
00352
00362 void setPeerAddressString(string);
00364 const string& getPeerAddressString()const;
00365
00366
00368
00369 CCommunicationHandler(CSessionManager& inSessionManager,
00370 ofstream& inLogFile);
00371
00372 ~CCommunicationHandler();
00373 };
00374
00375
00376 #endif