summaryrefslogtreecommitdiffstats
path: root/clientcomm/clientcomm.hh
blob: 4d255d57825fa4863f6d5474cbea8d60951b8812 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
/
/**
 * INCLUDE: clientcomm.hh
 *
 * MODULE:  clientcomm
 * CLASS:   ClientComm
 *
 * COMMENTS:
 * 		ClientComm is now an abstract class, with two subclasses: RpcClintComm and RnpClientComm
 * 		This will change again when RPC will be dropped forever
 *
*/

#ifndef _CLIENTCOMM_
#define _CLIENTCOMM_

#include "raslib/rminit.hh"
#include "raslib/error.hh"
#include "rasodmg/oqlquery.hh"
#include "rasodmg/marray.hh"

#include "raslib/primitivetype.hh"


template <class T> class r_Set;
class r_Ref_Any;
class r_Base_Type;
class r_Parse_Params;


//@ManMemo: Module: {\bf clientcomm}

/*@Doc:

The class ClientComm represents {\bf one} connection between
{\bf one} client entity (e.g. an object of class \Ref{r_Database}) and
the server. Therefore, the host name has to be provided at
the constructor.
*/

class ClientComm
{
  public:
    
    /// destructor (closes the connection and releases resources)
    virtual ~ClientComm() throw();

    // the class is not necessary singleton, but the type of the actual object depends on the environment
    static ClientComm* createObject(const char* rasmgrName, int rasmgrPort);
    
    /** Methods for setting the protocol. Default will be RNP, but until release 5.2 it is RPC, 
        unless you compile with -DDEFAULTRNP
        Also, if the environment variable RMANPROTOCOL is set, it's value is used to set the protocol
	and the 'in-code' setting is ignored
	RMANPROTOCOL can be:
		- RNP 		-> RNP is used
		- COMPAT 	-> raslib uses RPC, rasj uses HTTP
		- RPC		-> raslib uses RPC, rasj uses RNP
		- HTTP		-> raslib uses RNP, rasj uses HTTP
		every other value is ignored and the 'in-code' setting is used 
		
	NOTE: This methods will be removed in the next version
      */
      
    static  void useRNP() throw();
    static  void useRPC() throw();
    static  bool internalSettingIsRNP() throw();
    
    virtual bool effectivTypeIsRNP() throw() = 0;
        
    //@Man: Database methods
    //@{
    ///
       //RNP: all made pure
       
      /// open database
      virtual int openDB( const char* database ) = 0;
      /// close current database
      virtual int closeDB() = 0;
      /// create a database
      virtual int createDB( const char* name ) throw(r_Error) = 0;
      /// destroy a database
      virtual int destroyDB( const char* name ) throw(r_Error) = 0;

    ///
    //@}
    
    //@Man: Transaction methods
    //@{
    ///

      /// begin transaction
      virtual int openTA( unsigned short readOnly = 0 ) throw(r_Error) =0;
      /// commit current transaction
      virtual int commitTA() throw(r_Error) =0;
      /// abort current transaction
      virtual int abortTA() =0;

    ///
    //@}
    
    //@Man: MDD methods
    //@{
    ///

      /// inserts a MDD object in an existing MDD collection on the server
      virtual void insertMDD( const char* collName, r_GMarray* mar ) throw( r_Error ) =0;
      /// gets MDD object by oid
      virtual r_Ref_Any getMDDByOId( const r_OId& oid ) throw( r_Error ) =0;

    ///
    //@}
    
    //@Man: Collection methods
    //@{
    ///

      /// creates an empty MDD collection on the server
      virtual void insertColl( const char* collName, const char* typeName, const r_OId& oid ) throw( r_Error ) =0;
      /// deletes an MDD collection by name
      virtual void deleteCollByName( const char* collName ) throw( r_Error ) =0;
      /// deletes an object by oid (right now, objects are collection only)
      virtual void deleteObjByOId( const r_OId& oid ) throw( r_Error ) =0;
      /// removes an object from a collection
      virtual void removeObjFromColl( const char* name, const r_OId& oid ) throw ( r_Error ) =0;
      /// gets collection by name
      virtual r_Ref_Any getCollByName( const char* name ) throw( r_Error ) =0;
      /// gets collection by oid
      virtual r_Ref_Any getCollByOId ( const r_OId& oid ) throw( r_Error ) =0;
      /// gets collection references by name
      virtual r_Ref_Any getCollOIdsByName( const char* name ) throw( r_Error ) =0;
      /// gets collection references by oid
      virtual r_Ref_Any getCollOIdsByOId ( const r_OId& oid ) throw( r_Error ) =0;

    ///
    //@}

    //@Man: Query methods
    //@{
    ///

      /// query execution
      virtual void executeQuery( const r_OQL_Query& query, r_Set< r_Ref_Any >& result ) throw( r_Error ) =0;
      /*@Doc:
        Executes a retrieval query of type \Ref{r_OQL_Query} and returns the result. Every
        MDD object of the MDD collection is fetched from the server and inserted
        in the resulting \Ref{r_Set}.
      */
    
      /// update execution
      virtual void executeQuery( const r_OQL_Query& query ) throw( r_Error ) =0;
      /*@Doc:
        Executes an update query of type \Ref{r_OQL_Query}. 
      */

    ///
    //@}


    //@Man: System methods
    //@{
    ///

      /// get new oid    
      virtual r_OId getNewOId( unsigned short objType ) throw(r_Error) = 0;

      /// get oid type
      virtual unsigned short getObjectType( const r_OId& oid ) throw(r_Error) = 0;

	enum r_Type_Type
		{
		r_SetType_Type = 1,
		r_MDDType_Type = 2
		};

      /// get type structure
      /// deallocate using delete []
      virtual char* getTypeStructure( const char* typeName, r_Type_Type typeType ) throw(r_Error) =0;

    ///
    //@}

    /// changes endianness of MDD data
    static int changeEndianness( r_GMarray* mdd, const r_Base_Type* bt=NULL );
    /// changes the endianness of MDD data and keeps the original untouched
    static int changeEndianness( const r_GMarray* mdd, void *newData, const r_Base_Type* bt=NULL );

    /// provides read access to my clientID
    virtual unsigned long getClientID() const  = 0;
			

    //@Man: Methods for asynchronious alive signal concept
    //@{
    
    /// triggers an alive signal
    virtual void triggerAliveSignal() = 0;
    /** 
      First, it sets the switch {\tt aliveSignalRemaining} saying that an alive signal
      should be send to the server. Then it calls {\tt sendAliveSignal()} to send it
      immediately if possible.
    */
    
    /// send an alive signal if necessary and possible
    virtual void sendAliveSignal() = 0;
    /** 
      Sends an alive signal to the server if the switch {\tt aliveSignalRemaining} is 
      set and no other RPC is active. If a signal can be sent, {\tt aliveSignalRemaining}
      is set to 0 again.
    */

    /// set the preferred transfer format
    virtual int setTransferFormat( r_Data_Format format, const char* formatParams=NULL ) =0;

    /// set the preferred storage format
    virtual int setStorageFormat( r_Data_Format format, const char *formatParams=NULL ) =0;
    
    /// get extended error information
    virtual const char *getExtendedErrorInfo() throw(r_Error)  =0;
    
    /// get real server name (the dinamic one, assigned by the RasMGR)
    const char* getServerName();
    
    /// user identification for RasMGR
    virtual void setUserIdentification(const char *userName, const char *plainTextPassword) =0;    

    /// set maximum retry to get a server
    virtual void setMaxRetry(unsigned int newMaxRetry) = 0;
    
    /// get maximum retry to get a server
    virtual unsigned int  getMaxRetry() = 0;
    
    /// set and get communication timeout interval. Only RNP really uses it
    virtual void setTimeoutInterval(int seconds) = 0;
    virtual int  getTimeoutInterval() = 0;

    ///
    //@}
   
  protected:  
    /// constructor getting nothing
    ClientComm() throw( r_Error );
        
  private:
    
    static bool currentProtocolIsRNP;
   };

#endif