System documentation of the GNU Image-Finding Tool

Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

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     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 
00022 */
00023 
00024 
00025 
00026 //configuration files for sessions and algorithms/collections
00027 #ifndef _CCOMMUNICATIONHANDLER
00028 #define _CCOMMUNICATIONHANDLER
00029 #include "libMRML/include/uses-declarations.h"
00030 //the expat xml parser by J.Clark
00031 #include <expat.h>
00032 //a class for using xpat attributes in a nice way
00033 #include "libMRML/include/CAttributeList.h"
00034 
00035 //This is mrml+gift specific
00036 #include "libMRML/include/CSessionManager.h"
00037 #include "libMRML/include/CXMLElement.h"
00038 #include <functional>
00039 #include <iostream>
00040 #include <fstream>
00041 #include "libMRML/include/CMutex.h"
00042 //----------------------------------------
00044 extern void startMRMLElement(void *userData, 
00045                              const char *inElementName, 
00046                              const char **inAttributes);
00047 extern void endMRMLElement(void *userData, const char *name);
00048 
00052 class CCommunicationHandler{
00053 
00058   CSelfDestroyPointer<CXMLElement> mDocumentRoot;
00059   
00062   XML_Parser mParser;  
00063   
00066   CSessionManager& mSessionManager;
00072   CAlgorithm* mAlgorithmTree;
00077   CSelfDestroyPointer<CXMLElement> mCurrentTree;
00078 
00084   string mPeerAddressString;
00085   
00086 public:
00094   CSelfDestroyPointer<CXMLElement> mMultiResponse;
00095 
00096 protected:
00103   int mQueryAtRandomCount;
00104 protected:
00106   int mSocket;
00110   ofstream& mLog;
00111 public:
00112   //----------------------------------------
00114   //----------------------------------------
00116   void setSocket(int inSocket);
00117 
00118   //----------------------------------------
00120   //----------------------------------------
00122   string preamble();
00123 
00124 
00125 
00127   string frame(const string& inSession,
00128                const string& inString);
00129 
00130     
00131   //----------------------------------------
00133   string toAttribute(string inName,
00134                      string inString);
00135 
00136   
00137   string toAttribute(string inName,
00138                      int inInt);
00139 
00140   
00141   string toAttribute(string inName,
00142                      double inFloat);
00143     
00144   //     //----------------------------------------
00145   //     /** turning a relevance level element into a string */
00146   //     /** (obsolete) */
00147   //     string stringOfRelevanceLevelElement(const CRelevanceLevel& inRE,
00148   //                                     double inUserRelevance=0.5);
00149     
00150   //     string stringOfRelevanceLevelList(const CRelevanceLevelList& inRLL);
00151     
00152     
00153   //----------------------------------------
00155   int sendError(const string& inSession,
00156                 const string& inMessage);
00157 
00158   //----------------------------------------
00160   void openSession(const string& inUserName,
00161                    const string& inSessionName);
00163   void renameSession(const string& inSessionID,
00164                      const string& inNewName);
00165 
00167   void deleteSession(const string& inName);
00168 
00169 
00172   void getPropertySheet(const string& inSessionID,
00173                         const string& inAlgorithmID);
00174   //----------------------------------------
00176   int sendHandshake(const string& inUser);
00177     
00179   void getSessions(const string& inUser);
00181   void getCollections();
00183   void getAlgorithms();
00184   //----------------------------------------
00186   int sendResult(const string& inSession,
00187                  const CXMLElement& inRLL);
00188 
00189   
00190   //----------------------------------------
00192   int sendRandomImages(const string& inSession,
00193                        const string& inAlgorithm,
00194                        const string& inCollection,
00195                        const string& inNumberOfImages) ;
00196   ;
00197   
00198   
00199   //----------------------------------------
00201   //----------------------------------------
00202   CXMLElement* gQueryImages;
00203   string mSessionID;
00204   int    mResultSize;
00205   double mCutoff;
00206   string mCollection;
00207   string mAlgorithm;
00208 
00209   //----------------------------------------
00211   void setResultSize(int inResultSize);
00212 
00213 
00214   void setResultCutoff(const string& inCutoff);
00215 
00216   void setResultCutoff(double inCutoff);
00217 
00218 
00219   void setCollectionID(const string& inID);
00220 
00221 
00222   void setAlgorithmID(const string& inID);
00223 
00224   //----------------------------------------
00227   void startTreeBuilding(const char* inElementName,
00228                          const char*const*const inAttributes);
00231   void addToCurrentTree(const char* inElementName,
00232                         const char*const*const inAttributes);
00236   void moveUpCurrentTree();
00240   bool isBuildingTree()const;
00241 
00242   //----------------------------------------
00244   //----------------------------------------
00245   void parseString(const string& inMessage);
00246 
00247 
00248   //----------------------------------------
00258   void clearAlgorithmElement();
00259   //----------------------------------------
00272   //----------------------------------------
00273   void startAlgorithmElement(const char* inName,
00274                              const char* const* const inAttributes);
00275   //----------------------------------------
00279   //----------------------------------------
00280   void endAlgorithmElement();
00281   //----------------------------------------
00285   //----------------------------------------
00286   void initAlgorithmElement();
00287   //----------------------------------------
00290   //----------------------------------------
00291   CAlgorithm* readAlgorithmElement();
00292   //----------------------------------------
00298   void endConfiguration();
00299 
00300   //----------------------------------------
00304   bool mParsingFinished;
00305   void clearParsingFinished();
00306   void setParsingFinished();
00307   bool isParsingFinished()const;
00308 
00309   bool readAndParse();
00310 
00311   
00312 
00313   void makeParser();
00314 
00315 
00329   void startMultiRequest(const string& inSessionID, const string& inLanguageCode="en");
00331   void endMultiRequest();
00335   void addToMultiResponse(CXMLElement* inElement);
00336 
00337 
00338   
00339   //----------------------------------------
00342   //----------------------------------------
00343   CSessionManager& getSessionManager();
00344   
00346   void incrementQueryAtRandomCount();
00348   int getQueryAtRandomCount()const;
00349 
00359   void setPeerAddressString(string);
00361   const string& getPeerAddressString()const;
00362   
00363   //----------------------------------------
00365   //----------------------------------------
00366   CCommunicationHandler(CSessionManager& inSessionManager,
00367                         ofstream& inLogFile);
00368 
00369   ~CCommunicationHandler();
00370 };
00371 
00372 
00373 #endif

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