Mercurial > hg > audiodb
comparison audioDB.cpp @ 77:c4389e8f4461
Slightly more bullet-proof server. In audioDB::error(), We check to see
if we're running as a server (which also includes new audioDB instances
created by the server...); if so, we throw() rather than exit().
author | mas01cr |
---|---|
date | Mon, 01 Oct 2007 14:30:58 +0000 |
parents | f6cc39635877 |
children | beff1e23e95a |
comparison
equal
deleted
inserted
replaced
76:f6cc39635877 | 77:c4389e8f4461 |
---|---|
1 #include "audioDB.h" | 1 #include "audioDB.h" |
2 | 2 |
3 #define O2_DEBUG | 3 #define O2_DEBUG |
4 | 4 |
5 void audioDB::error(const char* a, const char* b, const char *sysFunc) { | 5 void audioDB::error(const char* a, const char* b, const char *sysFunc) { |
6 cerr << a << ": " << b << endl; | 6 if(isServer) { |
7 if (sysFunc) { | 7 char *err = new char[256]; /* FIXME: overflows */ |
8 perror(sysFunc); | 8 snprintf(err, 255, "%s: %s\n%s", a, b, sysFunc ? strerror(errno) : ""); |
9 } | 9 /* FIXME: actually we could usefully do with a properly structured |
10 exit(1); | 10 type, so that we can throw separate faultstring and details. |
11 -- CSR, 2007-10-01 */ | |
12 throw(err); | |
13 } else { | |
14 cerr << a << ": " << b << endl; | |
15 if (sysFunc) { | |
16 perror(sysFunc); | |
17 } | |
18 exit(1); | |
19 } | |
11 } | 20 } |
12 | 21 |
13 #define O2_AUDIODB_INITIALIZERS \ | 22 #define O2_AUDIODB_INITIALIZERS \ |
14 dim(0), \ | 23 dim(0), \ |
15 dbName(0), \ | 24 dbName(0), \ |
57 printf("%s\n", gengetopt_args_info_help[1]); | 66 printf("%s\n", gengetopt_args_info_help[1]); |
58 printf("%s\n", gengetopt_args_info_help[2]); | 67 printf("%s\n", gengetopt_args_info_help[2]); |
59 printf("%s\n", gengetopt_args_info_help[0]); | 68 printf("%s\n", gengetopt_args_info_help[0]); |
60 exit(1); | 69 exit(1); |
61 } | 70 } |
62 | 71 |
63 if(O2_ACTION(COM_SERVER)) | 72 if(O2_ACTION(COM_SERVER)) |
64 startServer(); | 73 startServer(); |
65 | 74 |
66 else if(O2_ACTION(COM_CREATE)) | 75 else if(O2_ACTION(COM_CREATE)) |
67 create(dbName); | 76 create(dbName); |
95 } | 104 } |
96 | 105 |
97 audioDB::audioDB(const unsigned argc, char* const argv[], adb__queryResult *adbQueryResult): O2_AUDIODB_INITIALIZERS | 106 audioDB::audioDB(const unsigned argc, char* const argv[], adb__queryResult *adbQueryResult): O2_AUDIODB_INITIALIZERS |
98 { | 107 { |
99 processArgs(argc, argv); | 108 processArgs(argc, argv); |
109 isServer = 1; // FIXME: Hack | |
100 assert(O2_ACTION(COM_QUERY)); | 110 assert(O2_ACTION(COM_QUERY)); |
101 query(dbName, inFile, adbQueryResult); | 111 query(dbName, inFile, adbQueryResult); |
102 } | 112 } |
103 | 113 |
104 audioDB::audioDB(const unsigned argc, char* const argv[], adb__statusResult *adbStatusResult): O2_AUDIODB_INITIALIZERS | 114 audioDB::audioDB(const unsigned argc, char* const argv[], adb__statusResult *adbStatusResult): O2_AUDIODB_INITIALIZERS |
105 { | 115 { |
106 processArgs(argc, argv); | 116 processArgs(argc, argv); |
117 isServer = 1; // FIXME: Hack | |
107 assert(O2_ACTION(COM_STATUS)); | 118 assert(O2_ACTION(COM_STATUS)); |
108 status(dbName, adbStatusResult); | 119 status(dbName, adbStatusResult); |
109 } | 120 } |
110 | 121 |
111 audioDB::~audioDB(){ | 122 audioDB::~audioDB(){ |
152 } | 163 } |
153 | 164 |
154 if(args_info.radius_given){ | 165 if(args_info.radius_given){ |
155 radius=args_info.radius_arg; | 166 radius=args_info.radius_arg; |
156 if(radius<=0 || radius>1000000000){ | 167 if(radius<=0 || radius>1000000000){ |
157 cerr << "Warning: radius out of range" << endl; | 168 error("radius out of range"); |
158 exit(1); | |
159 } | 169 } |
160 else | 170 else |
161 if(verbosity>3) { | 171 if(verbosity>3) { |
162 cerr << "Setting radius to " << radius << endl; | 172 cerr << "Setting radius to " << radius << endl; |
163 } | 173 } |
2488 | 2498 |
2489 // SERVER SIDE | 2499 // SERVER SIDE |
2490 int adb__status(struct soap* soap, xsd__string dbName, adb__statusResult &adbStatusResult){ | 2500 int adb__status(struct soap* soap, xsd__string dbName, adb__statusResult &adbStatusResult){ |
2491 char* const argv[]={"audioDB",COM_STATUS,"-d",dbName}; | 2501 char* const argv[]={"audioDB",COM_STATUS,"-d",dbName}; |
2492 const unsigned argc = 4; | 2502 const unsigned argc = 4; |
2493 audioDB(argc, argv, &adbStatusResult); | 2503 try { |
2494 return SOAP_OK; | 2504 audioDB(argc, argv, &adbStatusResult); |
2505 return SOAP_OK; | |
2506 } catch(char *err) { | |
2507 soap_receiver_fault(soap, err, ""); | |
2508 return SOAP_FAULT; | |
2509 } | |
2495 } | 2510 } |
2496 | 2511 |
2497 // Literal translation of command line to web service | 2512 // Literal translation of command line to web service |
2498 | 2513 |
2499 int adb__query(struct soap* soap, xsd__string dbName, xsd__string qKey, xsd__string keyList, xsd__string timesFileName, xsd__int qType, xsd__int qPos, xsd__int pointNN, xsd__int trackNN, xsd__int seqLen, adb__queryResult &adbQueryResult){ | 2514 int adb__query(struct soap* soap, xsd__string dbName, xsd__string qKey, xsd__string keyList, xsd__string timesFileName, xsd__int qType, xsd__int qPos, xsd__int pointNN, xsd__int trackNN, xsd__int seqLen, adb__queryResult &adbQueryResult){ |