rasdaman complete source
servercomm.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
33 #ifndef _SERVERCOMM_
34 #define _SERVERCOMM_
35 
36 // Put it in front of any typedef bool ... because o2 is using bool as a variable.
37 // #include "o2template_CC.hxx"
38 
39 #include <list>
40 
41 #include <rpc/rpc.h>
42 #include "raslib/error.hh"
43 #include "raslib/oid.hh"
44 #include "raslib/minterval.hh"
45 #include "raslib/rmdebug.hh"
46 
47 #include "reladminif/adminif.hh"
48 #include "reladminif/databaseif.hh"
49 #include "reladminif/transactionif.hh"
50 #include "relcatalogif/basetype.hh"
51 
52 #include "servercomm/callbackmgr.hh"
53 
54 #ifndef _RPCIF_
55 #define _RPCIF_
56 #include "clientcomm/rpcif.h"
57 #endif
58 
59 #ifdef DECALPHA
60 #include <rpc/svc.h>
61 #endif
62 
63 // forward declarations
64 class QtData;
65 class MDDObj;
66 class MDDCollIter;
67 class MDDColl;
68 class r_Parse_Params;
69 
70 //@ManMemo: Module: {\bf servercomm}
71 
72 /*@Doc:
73  The class servercomm describes the one and only server communication object
74  that can exist in a RasDaMan RPC server. It manages listening for client and
75  maps incoming calls to the respective remote procedures (which reside in the
76  file manager.cc). These remote procedures are global functions
77  which mainly concern with RPC call processing and finally call the methods
78  of this servercomm class to forward client requests.
79 */
80 
81 class ServerComm
82 {
83 public:
84 
86  class ClientTblElt
87  {
88  public:
90  ClientTblElt( const char* clientIdText, unsigned long clientId );
97  ~ClientTblElt();
99 
101  void release();
107  void endRequest();
108 
110  void releaseTransferStructures();
117  unsigned long clientId;
119 
121  unsigned int currentUsers;
122 
124  char* clientIdText;
125 
127  char* userName;
128 
130  char* baseName;
131 
133  unsigned long creationTime;
134 
136  unsigned long lastActionTime;
137 
139  r_Data_Format transferFormat;
140  char* transferFormatParams;
142  int exactFormat;
144  r_Data_Format storageFormat;
145  char* storageFormatParams;
146 
148  void* encodedData;
149  unsigned long encodedSize;
151  unsigned long totalRawSize;
152  unsigned long totalTransferedSize;
153 
155  MDDColl* transferColl;
160  MDDCollIter* transferCollIter;
162 
164  std::vector<QtData*>* transferData;
169  std::vector<QtData*>::iterator* transferDataIter;
171 
173  MDDObj* assembleMDD;
174 
176  MDDObj* transferMDD;
177 
179  std::vector< Tile* >* transTiles;
180 
182  std::vector< Tile* >::iterator* tileIter;
183 
185  std::vector< Tile* >* deletableTiles;
191  unsigned long bytesToTransfer;
193 
195  std::vector< MDDColl* >* persMDDCollections;
196 
198  DatabaseIf database;
199 
201  TransactionIf transaction;
202 
204  RMTimer* taTimer;
205 
207  RMTimer* transferTimer;
208 
210  RMTimer* evaluationTimer;
211 
213  r_Parse_Params *clientParams;
214 
215  private:
217  ClientTblElt( const ClientTblElt& ) {};
218  };
219 
221  ServerComm();
222 
224  ServerComm( unsigned long timeOut, unsigned long managementInterval , unsigned long listenPort, char* rasmgrHost, unsigned int rasmgrPort, char* serverName);
225 
227  virtual ~ServerComm();
228 
230  virtual void startRpcServer() throw( r_Error );
231 
233  virtual void stopRpcServer();
234 
235  // informs RasMGR:
236  void informRasMGR(int);
237 #define SERVER_DOWN 0
238 #define SERVER_AVAILABLE 1
239  // 2 is server crushed, but it's generated by rasmgr!
240  // regularly signal the rasmgr that we are available
241 #define SERVER_REGULARSIG 3
242 
244  void addClientTblEntry( ClientTblElt *context ) throw ( r_Error );
250  unsigned short deleteClientTblEntry( unsigned long ClientId );
257  // quick hack function used when stopping server to abort transaction and close db
258  void abortEveryThingNow();
259 
261  virtual void printServerStatus( ostream& s=cout );
262 
264  virtual void getServerStatus( ServerStatRes &returnStruct );
265 
267  static std::list<ClientTblElt*> clientTbl;
268 
270  static unsigned long clientCount;
271 
273  const unsigned long clientTimeout;
274 
276  const unsigned long garbageCollectionInterval;
277 
279  unsigned long transactionActive;
280 
282  long memUsed;
283 
285  static ServerComm* actual_servercomm;
286 
291  CallBackManager callback_mgr;
292 
293  //@Man: Communication methods
295 
298  virtual unsigned short aliveSignal( unsigned long client );
309  virtual unsigned short openDB( unsigned long callingClientId, const char* dbName, const char* userName );
323  virtual unsigned short closeDB( unsigned long callingClientId );
333  virtual unsigned short createDB( char* name );
335 
337  virtual unsigned short destroyDB( char* name );
338 
341  virtual unsigned short beginTA( unsigned long callingClientId, unsigned short readOnly=0 );
352  virtual unsigned short commitTA( unsigned long callingClientId );
363  virtual unsigned short abortTA( unsigned long callingClientId );
373 
382  virtual bool isTAOpen( unsigned long callingClientId );
383 
386  virtual unsigned short executeQuery( unsigned long callingClientId, const char* query, ExecuteQueryRes &returnStructure );
422  virtual unsigned short getNextMDD( unsigned long callingClientId,
425  r_Minterval &mddDomain,
426  char* &typeName,
427  char* &typeStructure,
428  r_OId &oid,
429  unsigned short &currentFormat );
445  virtual unsigned short getNextElement( unsigned long callingClientId,
447  char* &buffer,
448  unsigned int &bufferSize );
463  virtual unsigned short getMDDByOId( unsigned long callingClientId,
465  r_OId &oid,
466  r_Minterval &mddDomain,
467  char* &typeName,
468  char* &typeStructure,
469  unsigned short &currentFormat );
494  virtual unsigned short getNextTile( unsigned long callingClientId,
496  RPCMarray** rpcMarray );
543  virtual unsigned short endTransfer( unsigned long client );
555  virtual unsigned short initExecuteUpdate( unsigned long callingClientId );
580  virtual unsigned short executeUpdate( unsigned long callingClientId, const char* query, ExecuteUpdateRes &returnStructure );
597  virtual unsigned short startInsertTransMDD( unsigned long callingClientId,
600  r_Minterval &domain,
601  unsigned long typeLength,
602  const char* typeName );
621  virtual unsigned short startInsertPersMDD( unsigned long callingClientId,
623  const char* collName,
624  r_Minterval& domain,
625  unsigned long typeLength,
626  const char* typeName,
627  r_OId& oid );
662  virtual unsigned short insertTile( unsigned long callingClientId,
664  int isPersistent,
665  RPCMarray* rpcMarray );
686  // inserts a tile into a persistent MDD object splitting it up according to
687  // parameter tileSize
688  virtual unsigned short insertTileSplitted( unsigned long callingClientId,
689  int isPersistent,
690  RPCMarray* rpcMarray,
691  r_Minterval* tileSize );
711  virtual unsigned short endInsertMDD( unsigned long callingClientId,
713  int isPersistent );
722  virtual unsigned short insertMDD( unsigned long callingClientId,
725  const char* collName,
726  RPCMarray *rpcMarray,
727  const char* typeName, r_OId& oid );
752  virtual unsigned short getCollByName( unsigned long callingClientId,
755  const char* collName,
756  char* &typeName,
757  char* &typeStructure,
758  r_OId &oid );
787  virtual unsigned short getCollByOId( unsigned long callingClientId,
789  r_OId &oid,
790  char* &typeName,
791  char* &typeStructure,
792  char* &collName );
817  virtual unsigned short getCollOIdsByName( unsigned long callingClientId,
819  const char* collName,
820  char* &typeName,
821  char* &typeStructure,
822  r_OId &oid,
823  RPCOIdEntry* &oidTable,
824  unsigned int &oidTableSize );
848  virtual unsigned short getCollOIdsByOId( unsigned long callingClientId,
850  r_OId &oid,
851  char* &typeName,
852  char* &typeStructure,
853  RPCOIdEntry* &oidTable,
854  unsigned int &oidTableSize,
855  char* &collName );
879  virtual unsigned short insertColl( unsigned long callingClientId,
882  const char* collName,
883  const char* typeName,
884  r_OId& oid );
905  virtual unsigned short deleteCollByName( unsigned long callingClientId,
908  const char* collName );
922  virtual unsigned short deleteObjByOId( unsigned long callingClientId, r_OId& oid );
937  virtual unsigned short removeObjFromColl( unsigned long callingClientId,
940  const char* collName, r_OId& oid );
954  virtual unsigned short getNewOId( unsigned long callingClientId,
957  unsigned short objType, r_OId& oid );
971  virtual unsigned short getObjectType( unsigned long callingClientId,
973  r_OId& oid, unsigned short &objType );
986  virtual unsigned short getTypeStructure( unsigned long callingClientId,
988  const char* typeName,
989  unsigned short typeType,
990  char* &typeStructure);
1004  virtual unsigned short setTransferMode( unsigned long callingClientId,
1006  unsigned short format, const char* formatParams );
1019  virtual unsigned short setStorageMode( unsigned long callingClientId,
1021  unsigned short format, const char *formatParams );
1025 
1027 
1029  virtual ClientTblElt* getClientContext( unsigned long ClientId );
1039  // get, set and clear extended error info.
1040  const char *getExtendedErrorInfo();
1041 
1042  void setExtendedErrorInfo(const char*);
1043 
1044  void clearExtendedErrorInfo();
1045 
1046  void clientEndRequest();
1047 
1048  // constant for clientID
1049  static const char* HTTPCLIENT;
1050 
1051 private:
1053  ServerComm( const ServerComm& );//and then why this? : clientTimeout(3600), garbageCollectionInterval(600){;};
1054 
1055 protected:
1057  static int ensureTileFormat( r_Data_Format &hasFmt, r_Data_Format needFmt,
1058  const r_Minterval &dom, const BaseType *type,
1059  char *&data, unsigned long &size, int repack,
1060  int owner, const char *params = NULL);
1062  static const int ENSURE_TILE_FORMAT_OK;
1063  static const int ENSURE_TILE_FORMAT_BAD;
1064 
1066  AdminIf* admin;
1067 
1068  char *errorText;
1069 
1070  unsigned long listenPort;
1071  char* rasmgrHost;
1072  unsigned int rasmgrPort;
1073  char* serverName;
1074 
1075  bool isHttpServer;
1076  //this trick didn't work and we are out of time
1077  // ClientTblElt *uniqueClientContext;
1078 };
1079 
1080 
1082 void rpcif_1_caller(struct svc_req *rqstp,SVCXPRT *transp);
1083 
1084 
1085 /******************************************************************************************
1086 *** This class shouldn't be here, later it will be put in its own file
1087 ******************************************************************************************/
1088 
1089 
1090 class AccessControl
1091 {
1092 public:
1093  AccessControl();
1094  ~AccessControl();
1095  void initSyncro(const char *);
1096  void setServerName(const char *serverName);
1097 
1098  void resetForNewClient();
1099  int crunchCapability(const char*);
1100  /* 0 - ok
1101  804 - capability refused
1102  */
1103 
1104  void wantToRead(); // both throw
1105  void wantToWrite();
1106  bool isClient();
1107 private:
1108  int messageDigest(const char *input,char *output,const char *mdName);
1109  double initDeltaT;
1110  char serverName[100];
1111 
1112  bool okToRead;
1113  bool okToWrite;
1114  bool weHaveClient;
1115 };
1116 extern AccessControl accessControl;
1117 
1118 #include "servercomm.icc"
1119 
1120 #endif
Definition: databaseif.hh:66
Definition: adminif.hh:81
Definition: rpcif.h:22
Definition: transactionif.hh:52
Definition: rpcif.h:79
Definition: relcatalogif/basetype.hh:66
Definition: rpcif.h:223
Module: { raslib}.
Definition: rmdebug.hh:298
Definition: rpcif.h:90
Definition: rpcif.h:48