cadbc.h
Go to the documentation of this file.00001 #ifndef CADBC_H
00002 #define CADBC_H
00003
00004
00005 #include <sys/types.h>
00006 #include <sys/socket.h>
00007 #include <netinet/in.h>
00008 #include <netdb.h>
00009
00010
00011
00012 #include <string>
00013 #include <cstdio>
00014
00015 #include <iostream>
00016 #include <cstdlib>
00017 #include <string>
00018 #include "Aceobj.h"
00019
00020
00021
00022
00023
00024
00025
00026 using namespace std;
00027
00028 class AceException {
00029 public:
00030 AceException() : err() { }
00031 AceException(const string &er) : err(er) { }
00032 AceException(const char er[]) : err(er) { }
00033 friend ostream& operator<<(ostream &ous, const AceException &ae) {
00034 ous << "AceException:\n" << ae.err; return ous; }
00035 const string& getMessage() const { return err; }
00036
00037 private:
00038 string err;
00039 };
00040 class AQLException : public AceException {
00041 public:
00042 AQLException() : AceException() {}
00043 AQLException(const string &er) : AceException(er) {}
00044 friend ostream& operator<<(ostream &ous, const AQLException &e) {
00045 ous << "AQLException:\n" << e.getMessage(); return ous; }
00046 };
00047 class DNANotFound : public AceException {
00048 public:
00049 DNANotFound() : AceException() {}
00050 DNANotFound(const string &er) : AceException(er) {}
00051
00052 };
00053 class pepNotFound : public AceException {
00054 public:
00055 pepNotFound() : AceException() {}
00056 pepNotFound(const string &er) : AceException(er) {}
00057 pepNotFound(const char er[]) : AceException(er) {}
00058 };
00059
00060 class cadbc
00061 {
00062 public:
00063 friend class Result;
00068
00069
00070
00071
00072
00073
00074
00075
00087 cadbc(const string &host, int port, int rcvbfsz=100000);
00088 ~cadbc() { delete[] msg; shutdown(sock,2); }
00089
00090 void login(const char user[], const char passwd[]);
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00118 const char* getPeptideFasta(const string &pepName) throw(pepNotFound);
00119
00120 const char* getPeptideString(const string &pepName) throw(pepNotFound);
00121
00122
00123
00124
00125
00126
00127
00128
00134
00135
00144 const char* getDNAFasta(const string& seqname) throw(DNANotFound);
00145 const char* getDNAString(const string& seqname) throw(DNANotFound);
00146
00152 const char* fas2str();
00153 Aceobj* fetch(const string &objType, const string &objName) throw(AceException);
00161 void aql(const string &query) throw(AQLException);
00162 int fields() const { return columns.size(); }
00163 string fieldName(int i) const { return columns[i]; }
00164
00165 string fieldType(int i) const { return columns[i]; }
00166
00177 bool next();
00181 string getvalue(int i) { return currRow[i]; }
00182
00183
00184
00185
00186
00187 char* query(const string q) { return query(q.c_str()); }
00188 char* query(const char q[]) { send_msg("ACESERV_MSGREQ",q); receive(); return getBody(); }
00189
00190
00191
00192
00193
00194
00195
00196
00197 char *getBody() const { return msg+HEADER_LEN; }
00198 int getBodyLength() const { return msglen-HEADER_LEN; }
00199
00200
00201
00202
00203 char *getNext() { send_msg("ACESERV_MSGENCORE", "encore"); receive(); return getBody(); }
00204
00205
00206
00207 int send_msg(const char msgType[], const char body[], int body_len);
00208 int send_msg(const char msgType[], const char body[]) {
00209 return send_msg(msgType,body,strlen(body)+1); }
00210 int send_msg(const char msgType[], const string &body) {
00211 return send_msg(msgType,body.c_str(),body.length()+1); }
00212
00216 int receive();
00217
00218
00219
00220
00221
00222 int getMaxBytes() const { return *((int*)(msg+16)); }
00223 int getMsgLen() const { return *((int*)(msg+4)); }
00224 void setMsgLen(int l) { *((int*)(msg+4))=l; }
00225 const char* getMsgType() const { return msg+20; }
00226 void setMsgType(const char mt[]) {
00227 if (strlen(mt)>29) { cerr << "msg type longer than 29\n"; exit(1); }
00228 strcpy(msg+20, mt); }
00229 int getSockbufSize();
00230 void setSockbufSize(int sz);
00231
00232 void show();
00233
00234 static const int HEADER_LEN=50;
00235
00236 static const char *OK, *REQ, *FAIL, *DATA, *ENCORE, *KILL;
00237
00238
00239 private:
00248 string& completeQuery(const string &query);
00249
00250 void showHeader();
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 char *msg;
00262
00271 int msglen;
00272 int msgMaxlen;
00279 int maxBytes;
00280
00281 int sock;
00282 sockaddr_in svaddr;
00283
00288 string result;
00289 static const int faswidth = 50;
00290
00291
00295 Aceobj obj;
00296
00302 vector<string> columns;
00303 char *aqlResult;
00304 char *nextRow;
00309 vector<string> currRow;
00310 };
00311
00390 #endif