System documentation of the GNU Image-Finding Tool

CCommunicationHandler.h
00001 /* -*- mode: c++ -*- 
00002 */
00003 /* 
00004 
00005     GIFT, a flexible content based image retrieval system.
00006     Copyright (C) 1998, 1999, 2000, 2001, 2002, CUI University of Geneva
00007 
00008      Copyright (C) 2003, 2004 Bayreuth University
00009       2005 Bamberg University
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU General Public License for more details.
00019 
00020     You should have received a copy of the GNU General Public License
00021     along with this program; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 
00024 */
00025 
00026 
00027 
00028 //configuration files for sessions and algorithms/collections
00029 #ifndef _CCOMMUNICATIONHANDLER
00030 #define _CCOMMUNICATIONHANDLER
00031 #include "libMRML/include/uses-declarations.h"
00032 //the expat xml parser by J.Clark
00033 #include <expat.h>
00034 //a class for using xpat attributes in a nice way
00035 #include "libMRML/include/CAttributeList.h"
00036 
00037 //This is mrml+gift specific
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   //     /** turning a relevance level element into a string */
00148   //     /** (obsolete) */
00149   //     string stringOfRelevanceLevelElement(const CRelevanceLevel& inRE,
00150   //                                     double inUserRelevance=0.5);
00151     
00152   //     string stringOfRelevanceLevelList(const CRelevanceLevelList& inRLL);
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

Need for discussion? Want to contribute? Contact
help-gift@gnu.org Generated using Doxygen