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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
|
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef __cplusplus
}
#endif
#include "aceclient.h"
#include "RPC.h"
#define CHUNKSIZE 10
static int
not_here(s)
char *s;
{
croak("%s not implemented on this architecture", s);
return -1;
}
static double
constant(name, arg)
char *name;
int arg;
{
errno = 0;
switch (*name) {
case 'A':
if (strEQ(name, "ACE_INVALID"))
#ifdef ACE_INVALID
return ACE_INVALID;
#else
goto not_there;
#endif
if (strEQ(name, "ACE_OUTOFCONTEXT"))
#ifdef ACE_OUTOFCONTEXT
return ACE_OUTOFCONTEXT;
#else
goto not_there;
#endif
if (strEQ(name, "ACE_SYNTAXERROR"))
#ifdef ACE_SYNTAXERROR
return ACE_SYNTAXERROR;
#else
goto not_there;
#endif
if (strEQ(name, "ACE_UNRECOGNIZED"))
#ifdef ACE_UNRECOGNIZED
return ACE_UNRECOGNIZED;
#else
goto not_there;
#endif
if (strEQ(name, "ACE_PARSE"))
#ifdef ACE_PARSE
return ACE_PARSE;
#else
goto not_there;
#endif
break;
case 'B':
break;
case 'C':
break;
case 'D':
if (strEQ(name, "DEFAULT_PORT"))
#ifdef DEFAULT_PORT
return DEFAULT_PORT;
#else
goto not_there;
#endif
if (strEQ(name, "DROP_ENCORE"))
#ifdef DROP_ENCORE
return DROP_ENCORE;
#else
goto not_there;
#endif
break;
case 'E':
break;
case 'F':
break;
case 'G':
break;
case 'H':
if (strEQ(name, "HAVE_ENCORE"))
#ifdef HAVE_ENCORE
return HAVE_ENCORE;
#else
goto not_there;
#endif
break;
case 'I':
break;
case 'J':
break;
case 'K':
break;
case 'L':
break;
case 'M':
break;
case 'N':
break;
case 'O':
break;
case 'P':
break;
case 'Q':
break;
case 'R':
break;
case 'S':
if (strEQ(name, "STATUS_WAITING"))
#ifdef STATUS_WAITING
return STATUS_WAITING;
#else
goto not_there;
#endif
if (strEQ(name, "STATUS_PENDING"))
#ifdef STATUS_PENDING
return STATUS_PENDING;
#else
goto not_there;
#endif
if (strEQ(name, "STATUS_ERROR"))
#ifdef STATUS_ERROR
return STATUS_ERROR;
#else
goto not_there;
#endif
break;
case 'T':
break;
case 'U':
break;
case 'V':
break;
case 'W':
if (strEQ(name, "WANT_ENCORE"))
#ifdef WANT_ENCORE
return WANT_ENCORE;
#else
goto not_there;
#endif
break;
case 'X':
break;
case 'Y':
break;
case 'Z':
break;
case '_':
if (strEQ(name, "_ACECLIENT_"))
#ifdef _ACECLIENT_
return _ACECLIENT_;
#else
goto not_there;
#endif
break;
}
errno = EINVAL;
return 0;
not_there:
errno = ENOENT;
return 0;
}
MODULE = Ace::RPC PACKAGE = Ace::RPC
double
constant(name,arg)
char * name
int arg
AceDB*
connect(CLASS, host, rpc_port, timeOut=120, ...)
char* CLASS
char* host
unsigned long rpc_port
int timeOut
PREINIT:
ace_handle* ace;
CODE:
RETVAL = (AceDB*) safemalloc(sizeof(AceDB));
if (RETVAL == NULL) XSRETURN_UNDEF;
RETVAL->encoring = FALSE;
RETVAL->status = STATUS_WAITING;
RETVAL->answer = NULL;
RETVAL->errcode = 0;
ace = openServer(host,rpc_port,timeOut);
if (ace == NULL) {
safefree(RETVAL);
XSRETURN_UNDEF;
} else {
RETVAL->database = ace;
}
OUTPUT:
RETVAL
void
DESTROY(self)
AceDB* self
CODE:
if (self->answer != NULL)
free((void*) self->answer);
if (self->database != NULL)
closeServer(self->database);
safefree((char*)self);
ace_handle*
handle(self)
AceDB* self
CODE:
RETVAL = self->database;
OUTPUT:
RETVAL
int
encore(self)
AceDB* self
CODE:
RETVAL = self->encoring;
OUTPUT:
RETVAL
int
error(self)
AceDB* self
CODE:
RETVAL = self->errcode;
OUTPUT:
RETVAL
int
status(self)
AceDB* self
CODE:
RETVAL = self->status;
OUTPUT:
RETVAL
int
query(self,request, type=0)
AceDB* self
char* request
int type
PREINIT:
unsigned char* answer = NULL;
int retval,length,isWrite=0,isEncore=0;
CODE:
if (type == ACE_PARSE)
isWrite = 1;
else if (type > 0)
isEncore = 1;
retval = askServerBinary(self->database,request,
&answer,&length,&isEncore,CHUNKSIZE);
if (self->answer) {
free((void*) self->answer);
self->answer = NULL;
}
self->errcode = retval;
self->status = STATUS_WAITING;
if ((retval > 0) || (answer == NULL) ) {
self->status = STATUS_ERROR;
RETVAL = 0;
} else {
self->answer = answer;
self->length = length;
self->status = STATUS_PENDING;
self->encoring = isEncore && !isWrite;
RETVAL = 1;
}
OUTPUT:
RETVAL
SV*
read(self)
AceDB* self
PREINIT:
unsigned char* answer = NULL;
int retval,length,encore=0;
CODE:
if (self->status != STATUS_PENDING)
XSRETURN_UNDEF;
if (self->answer == NULL && self->encoring) {
retval = askServerBinary(self->database,"encore",&answer,
&length,&encore,CHUNKSIZE);
self->errcode = retval;
self->encoring = encore;
if ((retval > 0) || (answer == NULL) ) {
self->status = STATUS_ERROR;
XSRETURN_UNDEF;
}
self->answer = answer;
self->length = length;
}
if (!self->encoring)
self->status = STATUS_WAITING;
RETVAL = newSVpv((char*)self->answer,self->length);
OUTPUT:
RETVAL
CLEANUP:
if (self->answer != NULL) {
free((void*) self->answer);
self->length = 0;
self->answer = NULL;
}
|