rasdaman complete source
rnpclientcomm.hh
Go to the documentation of this file.
1 #ifndef RNPCLIENTCOMM_HH
2 #define RNPCLIENTCOMM_HH
3 /*
4 * This file is part of rasdaman community.
5 *
6 * Rasdaman community is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Rasdaman community is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
20 rasdaman GmbH.
21 *
22 * For more information please see <http://www.rasdaman.org>
23 * or contact Peter Baumann via <baumann@rasdaman.com>.
24 */
25 /*************************************************************
26  *
27  *
28  * COMMENTS:
29  *
30  ************************************************************/
31 
32 #include "clientcomm/clientcomm.hh"
35 #include "clientcomm/rpcif.h"
36 
37 using namespace rnp;
38 
48 {
49 public:
51  RnpClientComm( const char* rasmgrHost, int rasmgrPort = RASMGRPORT ) throw( r_Error );
52 
53  ~RnpClientComm() throw ();
54 
55  bool effectivTypeIsRNP() throw();
56 
57  //@Man: Database methods
59 
62  int openDB( const char* database );
64  int closeDB();
66  int createDB( const char* name ) throw(r_Error);
68  int destroyDB( const char* name ) throw(r_Error);
69 
71 
72 
73  //@Man: Transaction methods
75 
78  int openTA( unsigned short readOnly = 0 ) throw(r_Error);
80  int commitTA() throw(r_Error);
82  int abortTA();
83 
85 
86 
87  //@Man: MDD methods
89 
92  void insertMDD( const char* collName, r_GMarray* mar ) throw( r_Error );
94  r_Ref_Any getMDDByOId( const r_OId& oid ) throw( r_Error );
95 
97 
98 
99  //@Man: Collection methods
101 
104  void insertColl( const char* collName, const char* typeName, const r_OId& oid ) throw( r_Error );
106  void deleteCollByName( const char* collName ) throw( r_Error );
108  void deleteObjByOId( const r_OId& oid ) throw( r_Error );
110  void removeObjFromColl( const char* name, const r_OId& oid ) throw ( r_Error );
112  r_Ref_Any getCollByName( const char* name ) throw( r_Error );
114  r_Ref_Any getCollByOId ( const r_OId& oid ) throw( r_Error );
116  r_Ref_Any getCollOIdsByName( const char* name ) throw( r_Error );
118  r_Ref_Any getCollOIdsByOId ( const r_OId& oid ) throw( r_Error );
119 
121 
122 
123  //@Man: Query methods
125 
128  void executeQuery( const r_OQL_Query& query, r_Set< r_Ref_Any >& result ) throw( r_Error );
129  /*@Doc:
130  Executes a retrieval query of type \Ref{r_OQL_Query} and returns the result. Every
131  MDD object of the MDD collection is fetched from the server and inserted
132  in the resulting \Ref{r_Set}.
133  */
134 
136  void executeQuery( const r_OQL_Query& query ) throw( r_Error );
137  /*@Doc:
138  Executes an update query of type \Ref{r_OQL_Query}.
139  */
140 
142 
143 
144 
145  //@Man: System methods
147 
150  r_OId getNewOId( unsigned short objType ) throw(r_Error);
151 
153  unsigned short getObjectType( const r_OId& oid ) throw(r_Error);
154 
157  char* getTypeStructure( const char* typeName, r_Type_Type typeType ) throw(r_Error);
158 
160 
161 
163  unsigned long getClientID() const;
164 
166  int setTransferFormat( r_Data_Format format, const char* formatParams=NULL );
167 
169  int setStorageFormat( r_Data_Format format, const char *formatParams=NULL );
170 
171 
173  const char* getServerName();
174 
176  void setUserIdentification(const char *userName, const char *plainTextPassword);
177 
179  void setMaxRetry(unsigned int newMaxRetry);
180 
182  unsigned int getMaxRetry();
183 
184  void setTurbo(bool turbo);
185 
187 
188 
189  // obsolete, but kept because of virtual functions in base class
190  void triggerAliveSignal();
191  void sendAliveSignal();
192  const char *getExtendedErrorInfo() throw(r_Error);
193 
194  void setTimeoutInterval(int seconds);
195  int getTimeoutInterval();
196 
197 //#### secret, unofficial functions ###########
198 
199  r_OId createCollection(const char *collName, const char *collTypeName) throw(r_Error);
200 
201  r_OId createMDD(const char* collName, const char* mddTypeName, const char* definitionDomain, const char *tileDomain, bool rcindex = false) throw(r_Error);
202 
203  void extendMDD(r_OId mddOId, const char *stripeDomain, const char* tileDomain) throw(r_Error);
204 
205  vector<r_OId> getOIdsFromCollection( const char* name ) throw( r_Error );
206 
207  vector<r_OId> getOIdsFromCollection( const r_OId& oid ) throw( r_Error );
208 
209  vector<r_Minterval> getTileDomains(r_OId mddOId, const char *stripeDomain) throw( r_Error );
210 
211 
212  void preloadTiles(r_OId mddOId, const char *tileDomain) throw(r_Error);
213 
214  int getTileData(r_OId mddOId, const char *tileDomain, char *&data, bool preallocated = false) throw(r_Error);
215 
216  void replaceTileData(r_OId mddOId, const char *tileDomain, const char *newData, int dataLength, const char *alfaData, int alfaLength) throw(r_Error);
217 
218 //#############################################
219 private:
221  int clientID;
222 
224  char *rasmgrHost;
225 
227  int rasmgrPort;
228 
230  char serverHost[100]; //can't be just a pointer, it's never stored elsewhere
231 
232  int serverPort;
233 
234  // the name of the opened database, needed because it will be opened again and again, in a hidden operation
235  char databaseName[100];
236 
237  // the capability
238  char capability[100];
239 
241  char identificationString[100];
242 
244  int getFreeServer(bool readwrite, bool openDB);
245 
247  int executeGetFreeServer(bool readwrite, bool openDB);
248 
249  int readWholeMessage(int socket,char *destBuffer,int buffSize);
250 
251  int writeWholeMessage(int socket,char *destBuffer,int buffSize);
252 
253  // MD5 of password
254  int messageDigest(const char *input,char *output,const char *mdName);
255 
257  void getElementCollection( r_Set< r_Ref_Any >& result ) throw(r_Error);
258 
260  void getMDDCollection( r_Set< r_Ref_Any >& result, unsigned int isQuery ) throw(r_Error);
261 
263  unsigned short getMDDCore( r_Ref<r_GMarray> &mdd, GetMDDRes *thisResult, unsigned int isQuery ) throw( r_Error );
264 
266  int concatArrayData( const char *source, unsigned long srcSize, char *&dest,
267  unsigned long &destSize, unsigned long &destLevel );
268 
270  void getMarRpcRepresentation( const r_GMarray* mar, RPCMarray*& rpcMarray,
271  r_Data_Format initStorageFormat = r_Array,
272  const r_Base_Type *bt = NULL);
273 
275  void freeMarRpcRepresentation( const r_GMarray* mar, RPCMarray* rpcMarray );
276 
278  int endianServer;
279  int endianClient;
280 
282  r_Data_Format transferFormat;
284  r_Data_Format storageFormat;
286  char* transferFormatParams;
288  char *storageFormatParams;
290  r_Parse_Params *clientParams;
291 
293  int serverCompresses;
295  int exactFormat;
296 
297  // functions which really do the connection stuff
298  void executeConnect();
299  void executeDisconnect();
300  void executeOpenDB(const char*);
301  void executeCloseDB();
302  void executeBeginTA(bool rw);
303  void executeCommitTA();
304  void executeAbortTA();
305  int executeExecuteQuery( const char* query, r_Set< r_Ref_Any >& result ) throw( r_Error );
306  GetElementRes* executeGetNextElement();
307  int executeEndTransfer();
308  GetMDDRes* executeGetNextMDD();
309  GetTileRes* executeGetNextTile();
310  void executeExecuteUpdateQuery(const char *query) throw(r_Error);
311  int executeStartInsertTransMDD(r_GMarray* mdd);
312  int executeInsertTile(bool persistent, RPCMarray* tile);
313  void executeEndInsertMDD(bool persistent);
314  int executeInitUpdate();
315  int executeStartInsertPersMDD( const char* collName, r_GMarray* mar );
316  int executeInsertMDD(const char* collName, r_GMarray* mar, RPCMarray *rpcMarray);
317  int executeInsertCollection( const char* collName, const char* typeName, const r_OId& oid );
318  r_Ref_Any executeGetCollByNameOrOId ( const char* collName, const r_OId& oid ) throw( r_Error );
319  r_Ref_Any executeGetCollOIdsByNameOrOId ( const char* collName, const r_OId& oid ) throw( r_Error );
320  int executeSetFormat( bool transferFormat, r_Data_Format format, const char* formatParams);
321  r_OId executeGetNewOId( unsigned short objType ) throw(r_Error);
322  unsigned short executeGetObjectType( const r_OId& oid ) throw(r_Error);
323  char* executeGetTypeStructure( const char* typeName, r_Type_Type typeType ) throw(r_Error);
324 
325  vector<r_OId> executeGetOIdsFromCollection ( const char* collName, const r_OId& oid ) throw( r_Error );
326 
327  void turboOpenDB(const char*);
328  void turboBeginTA(bool rw);
329  void turboCommitTA();
330  void turboAbortTA();
331 
332  bool useTurbo;
333 
334  // returns only if transaction is open and rw, otherwise throws
335  void checkForRwTransaction() throw (r_Error);
336 
337  // varianta locala
338  void sendRequestGetAnswer() throw (r_Error);
339 
340  int sendAndReturnStatus() throw (r_Error);
341 
342  bool detectErrors();
343  // doesn't return if there is an error
344  void reassemble_r_Error() throw (r_Error);
345 
346  // a very internal helper for some functions
347  void helper012d(const char* caller) throw (r_Error);
348 };
349 
350 #endif
r_Type_Type
Definition: clientcomm.hh:196
Definition: raslib/basetype.hh:47
Definition: rpcif.h:263
Definition: rpcif.h:158
Definition: error.hh:88
Definition: clientcomm.hh:46
Definition: rpcif.h:22
Definition: rnpcommunication.hh:44
Definition: clientcomm.hh:67
r_Data_Format
Definition: mddtypes.hh:133
Definition: gmarray.hh:66
Definition: rpcif.h:148
Definition: ref.hh:65
Definition: mddtypes.hh:135
Definition: parseparams.hh:44
Definition: oqlquery.hh:81
Definition: rnpclientcomm.hh:47
int writeWholeMessage(int socket, char *destBuffer, int buffSize)
int messageDigest(const char *input, char *output, const char *mdName)
const int RASMGRPORT
Definition: rminit.hh:59
Definition: rnpcommunication.hh:117
int readWholeMessage(int socket, char *destBuffer, int buffSize)
Definition: oid.hh:47