System documentation of the GNU Image-Finding Tool

CCommunicationHandler.h
1 /* -*- mode: c++ -*-
2 */
3 /*
4 
5  GIFT, a flexible content based image retrieval system.
6  Copyright (C) 1998, 1999, 2000, 2001, 2002, CUI University of Geneva
7 
8  Copyright (C) 2003, 2004 Bayreuth University
9  2005 Bamberg University
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 
24 */
25 
26 
27 
28 //configuration files for sessions and algorithms/collections
29 #ifndef _CCOMMUNICATIONHANDLER
30 #define _CCOMMUNICATIONHANDLER
31 #include "libMRML/include/uses-declarations.h"
32 //the expat xml parser by J.Clark
33 #include <expat.h>
34 //a class for using xpat attributes in a nice way
35 #include "libMRML/include/CAttributeList.h"
36 
37 //This is mrml+gift specific
38 #include "libMRML/include/CSessionManager.h"
39 #include "libMRML/include/CXMLElement.h"
40 #include <functional>
41 #include <iostream>
42 #include <fstream>
43 #include "libMRML/include/CMutex.h"
44 //----------------------------------------
46 extern void startMRMLElement(void *userData,
47  const char *inElementName,
48  const char **inAttributes);
49 extern void endMRMLElement(void *userData, const char *name);
50 
55 
61 
64  XML_Parser mParser;
65 
68  CSessionManager& mSessionManager;
74  CAlgorithm* mAlgorithmTree;
80 
86  string mPeerAddressString;
87 
88 public:
97 
98 protected:
106 protected:
108  int mSocket;
112  ofstream& mLog;
113 public:
114  //----------------------------------------
116  //----------------------------------------
118  void setSocket(int inSocket);
119 
120  //----------------------------------------
122  //----------------------------------------
124  string preamble();
125 
126 
127 
129  string frame(const string& inSession,
130  const string& inString);
131 
132 
133  //----------------------------------------
135  string toAttribute(string inName,
136  string inString);
137 
138 
139  string toAttribute(string inName,
140  int inInt);
141 
142 
143  string toAttribute(string inName,
144  double inFloat);
145 
146  // //----------------------------------------
147  // /** turning a relevance level element into a string */
148  // /** (obsolete) */
149  // string stringOfRelevanceLevelElement(const CRelevanceLevel& inRE,
150  // double inUserRelevance=0.5);
151 
152  // string stringOfRelevanceLevelList(const CRelevanceLevelList& inRLL);
153 
154 
155  //----------------------------------------
157  int sendError(const string& inSession,
158  const string& inMessage);
159 
160  //----------------------------------------
162  void openSession(const string& inUserName,
163  const string& inSessionName);
165  void renameSession(const string& inSessionID,
166  const string& inNewName);
167 
169  void deleteSession(const string& inName);
170 
171 
174  void getPropertySheet(const string& inSessionID,
175  const string& inAlgorithmID);
176  //----------------------------------------
178  int sendHandshake(const string& inUser);
179 
181  void getSessions(const string& inUser);
183  void getCollections();
185  void getAlgorithms();
186  //----------------------------------------
188  int sendResult(const string& inSession,
189  const CXMLElement& inRLL);
190 
191 
192  //----------------------------------------
194  int sendRandomImages(const string& inSession,
195  const string& inAlgorithm,
196  const string& inCollection,
197  const string& inNumberOfImages) ;
198  ;
199 
200 
201  //----------------------------------------
203  //----------------------------------------
205  string mSessionID;
206  int mResultSize;
207  double mCutoff;
208  string mCollection;
209  string mAlgorithm;
210 
211  //----------------------------------------
213  void setResultSize(int inResultSize);
214 
215 
216  void setResultCutoff(const string& inCutoff);
217 
218  void setResultCutoff(double inCutoff);
219 
220 
221  void setCollectionID(const string& inID);
222 
223 
224  void setAlgorithmID(const string& inID);
225 
226  //----------------------------------------
229  void startTreeBuilding(const char* inElementName,
230  const char*const*const inAttributes);
233  void addToCurrentTree(const char* inElementName,
234  const char*const*const inAttributes);
238  void moveUpCurrentTree();
242  bool isBuildingTree()const;
243 
244  //----------------------------------------
246  //----------------------------------------
247  void parseString(const string& inMessage);
248 
249 
250  //----------------------------------------
260  void clearAlgorithmElement();
261  //----------------------------------------
274  //----------------------------------------
275  void startAlgorithmElement(const char* inName,
276  const char* const* const inAttributes);
277  //----------------------------------------
281  //----------------------------------------
282  void endAlgorithmElement();
283  //----------------------------------------
287  //----------------------------------------
288  void initAlgorithmElement();
289  //----------------------------------------
292  //----------------------------------------
294  //----------------------------------------
300  void endConfiguration();
301 
302  //----------------------------------------
307  void clearParsingFinished();
308  void setParsingFinished();
309  bool isParsingFinished()const;
310 
311  bool readAndParse();
312 
313 
314 
315  void makeParser();
316 
317 
331  void startMultiRequest(const string& inSessionID, const string& inLanguageCode="en");
333  void endMultiRequest();
337  void addToMultiResponse(CXMLElement* inElement);
339  const string getCurrentSessionID();
340 
341 
342  //----------------------------------------
345  //----------------------------------------
347 
351  int getQueryAtRandomCount()const;
352 
362  void setPeerAddressString(string);
364  const string& getPeerAddressString()const;
365 
366  //----------------------------------------
368  //----------------------------------------
369  CCommunicationHandler(CSessionManager& inSessionManager,
370  ofstream& inLogFile);
371 
373 };
374 
375 
376 #endif
void getPropertySheet(const string &inSessionID, const string &inAlgorithmID)
Gets the property sheet contained in the algorithm with inAlgorithmID.
void getSessions(const string &inUser)
getting the sessions for one user (new MRML)
bool isBuildingTree() const
is this building a tree at present?
CAlgorithm * readAlgorithmElement()
read the pointer to the algorithm tree
string frame(const string &inSession, const string &inString)
Frame: this is for all messages the same.
int mSocket
The socket, which is used for this communication.
Definition: CCommunicationHandler.h:108
void endAlgorithmElement()
end of an element in the tree of configured algorithms
int sendRandomImages(const string &inSession, const string &inAlgorithm, const string &inCollection, const string &inNumberOfImages)
random images
This class captures the structure of an XML element.
Definition: CXMLElement.h:51
void renameSession(const string &inSessionID, const string &inNewName)
renaming the current session
void openSession(const string &inUserName, const string &inSessionName)
Opening a session.
void moveUpCurrentTree()
move up in the tree
CSessionManager & getSessionManager()
Using the session manager which is a member.
void setSocket(int inSocket)
communications:
ofstream & mLog
The logfile which logs all communication.
Definition: CCommunicationHandler.h:112
int getQueryAtRandomCount() const
reading this flag
void getCollections()
getting collections available on a system
int mQueryAtRandomCount
We have said, that the user can tell, if he wants a query in the normal sense or rather a collection ...
Definition: CCommunicationHandler.h:105
int sendHandshake(const string &inUser)
the handshake message (old MRML)
void startAlgorithmElement(const char *inName, const char *const *const inAttributes)
start of an element in the tree of configured algorithms.
An algorithm is a CXMLElement which is linked to a CSessionManager together they are able to build CQ...
Definition: CAlgorithm.h:43
void clearAlgorithmElement()
Clear the algorithm tree element.
string preamble()
helpers for creating mrml messages
a helper class for use with expat, which also handles the socket stuff.
Definition: CCommunicationHandler.h:54
string toAttribute(string inName, string inString)
making attributes out of name/value pairs
void setPeerAddressString(string)
set the name of the peer, this is just an informative string, destined for the log.
bool mParsingFinished
parsing from a stream: read each character parse it
Definition: CCommunicationHandler.h:306
This structure handles the sessions; by this, it encapsulates the current state of the server...
Definition: CSessionManager.h:209
void incrementQueryAtRandomCount()
incrementing the QueryAtRandomCount flag
CXMLElement * gQueryImages
processing a query
Definition: CCommunicationHandler.h:198
const string & getPeerAddressString() const
get the Peer adress string
void endMultiRequest()
sends the message which has been built
void initAlgorithmElement()
clear the pointer to the algorithm tree
void deleteSession(const string &inName)
renaming the current session
void startTreeBuilding(const char *inElementName, const char *const *const inAttributes)
Start building a tree by successive adding of XML elements.
void parseString(const string &inMessage)
parse XML using expat
void setResultSize(int inResultSize)
setting properties of the query
void addToCurrentTree(const char *inElementName, const char *const *const inAttributes)
Start building a tree by successive adding of XML elements.
void addToMultiResponse(CXMLElement *inElement)
adds an XMLElement to the multi-response which is built
CSelfDestroyPointer< CXMLElement > mMultiResponse
A DOM-alike tree which will be built from all the answers given to the requests.
Definition: CCommunicationHandler.h:96
void startMultiRequest(const string &inSessionID, const string &inLanguageCode="en")
If we process multiple queries which are part of one message, we have to first collect the answers fr...
int sendResult(const string &inSession, const CXMLElement &inRLL)
the result of a query
void endConfiguration()
End the configuration i.e.
const string getCurrentSessionID()
returns the currently valid SessionID
int sendError(const string &inSession, const string &inMessage)
turning a relevance level element into a string
CCommunicationHandler(CSessionManager &inSessionManager, ofstream &inLogFile)
constructor/destructor
void getAlgorithms()
getting algorithms available on a system

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