00001 #include "eventQuery.h"
00002 #include "rmClientTypes.h"
00003
00004 int
00005 eventQuery::removeElement(unsigned long aID)
00006 {
00007 int ret;
00008
00009 EventQuery * query = getElement(aID);
00010 if(!query)
00011 return RMCLIENT_ERROR_QUERY;
00012
00013 if(query->refCnt > 0)
00014 return RMCLIENT_ERROR_CC_REFCNT;
00015
00016 if(query->status == ACTIVE) {
00017 ret = posix_log_query_destroy(&(query->query));
00018 if(ret)
00019 return RMCLIENT_ERROR_QUERY_DESTROY;
00020 }
00021
00022 return rmRefArray<EventQuery>::removeElement(aID);
00023 }
00024
00025 bool
00026 eventQuery::elementIsReady(const EventQuery & aQuery) const
00027 {
00028 if(aQuery.purpose > PURPOSE_GENERAL || aQuery.purpose < PURPOSE_NOTIFY)
00029 return false;
00030
00031 if(aQuery.qstr.size() == 0)
00032 return false;
00033
00034 return true;
00035 }
00036
00037 int
00038 eventQuery::getInteger32(RMAttribute aName, unsigned long aID, long & aValue)
00039 {
00040 aValue = -1;
00041 const EventQuery * query = getConstElement(aID);
00042 if(!query)
00043 return RMCLIENT_ERROR_QUERY;
00044
00045 switch(aName) {
00046 case EVENTQUERY_PURPOSE:
00047 aValue = query->purpose;
00048 break;
00049
00050 case EVENTQUERY_REFCOUNT:
00051 aValue = query->refCnt;
00052 break;
00053
00054 case EVENTQUERY_STATUS:
00055 aValue = query->status;
00056 break;
00057
00058 default:
00059 return RMCLIENT_ERROR_NOSUCHNAME;
00060 }
00061
00062 return RMCLIENT_SUCCESS;
00063 }
00064
00065 int
00066 eventQuery::setInteger32(RMAttribute aName, unsigned long aID, long aValue)
00067 {
00068 int ret, purpose;
00069
00070 EventQuery * query = getElement(aID);
00071 if(!query)
00072 return RMCLIENT_ERROR_QUERY;
00073
00074 if(query->refCnt > 0)
00075 return RMCLIENT_ERROR_CC_REFCNT;
00076
00077 switch(aName) {
00078
00079 case EVENTQUERY_PURPOSE:
00080
00081 if(query->status == ACTIVE)
00082 return RMCLIENT_ERROR_STATE;
00083
00084
00085 if(aValue < PURPOSE_NOTIFY || aValue > PURPOSE_GENERAL)
00086 return RMCLIENT_ERROR_NOSUCHVALUE;
00087
00088 query->purpose = aValue;
00089 updateStatus(*query);
00090
00091 break;
00092
00093 case EVENTQUERY_STATUS:
00094 if(aValue < NOTEXIST || aValue > DESTROY || aValue == NOTREADY)
00095 return RMCLIENT_ERROR_NOSUCHVALUE;
00096
00097 if(aValue == ACTIVE) {
00098
00099 if(query->status == NOTINSERVICE) {
00100
00101 if(query->purpose == PURPOSE_NOTIFY)
00102 purpose = POSIX_LOG_PRPS_NOTIFY;
00103 else if(query->purpose == PURPOSE_SEEK)
00104 purpose = POSIX_LOG_PRPS_SEEK;
00105 else
00106 purpose = POSIX_LOG_PRPS_GENERAL;
00107
00108 ret = posix_log_query_create(query->qstr.c_str(), purpose, &(query->query), 0, 0);
00109 if(ret)
00110 return RMCLIENT_ERROR_QUERY_CREATE;
00111 }
00112 else if(query->status == ACTIVE)
00113 return RMCLIENT_SUCCESS;
00114
00115
00116 else {
00117 return RMCLIENT_ERROR_STATE;
00118 }
00119
00120 }
00121 else if(aValue == NOTINSERVICE) {
00122
00123 if(query->status == ACTIVE) {
00124
00125 ret = posix_log_query_destroy(&(query->query));
00126 if(ret)
00127 return RMCLIENT_ERROR_QUERY_DESTROY;
00128
00129 memset(&(query->query), 0, sizeof(posix_log_query_t));
00130 }
00131 else if(query->status == NOTINSERVICE)
00132 return RMCLIENT_SUCCESS;
00133
00134
00135 else
00136 return RMCLIENT_ERROR_STATE;
00137 }
00138
00139 query->status = aValue;
00140 break;
00141
00142 default:
00143 return RMCLIENT_ERROR_NOSUCHNAME;
00144 }
00145
00146 return RMCLIENT_SUCCESS;
00147 }
00148
00149 int
00150 eventQuery::getString(RMAttribute aName, unsigned long aID, char * & aBuf)
00151 {
00152 aBuf = NULL;
00153
00154 int purpose;
00155 size_t len, qstrlen;
00156 char * qstrbuf(NULL);
00157
00158 const EventQuery * query = getConstElement(aID);
00159 if(!query)
00160 return RMCLIENT_ERROR_QUERY;
00161
00162 switch(aName) {
00163
00164 case EVENTQUERY_STRING:
00165
00166 if(query->status == ACTIVE) {
00167 posix_log_query_get(&(query->query), &purpose, 0, 0, &len);
00168 if(len && purpose) {
00169
00170 qstrlen = len;
00171 qstrbuf = (char *) malloc(sizeof(char)*qstrlen);
00172 if(!qstrbuf)
00173 return RMCLIENT_ERROR_MEMORY;
00174
00175 posix_log_query_get(&query->query, &purpose, qstrbuf, qstrlen, &len);
00176 }
00177 else return RMCLIENT_ERROR_QUERY_STRING;
00178 } else {
00179
00180 qstrlen = query->qstr.size() + 1;
00181
00182 if(qstrlen > 1) {
00183 qstrbuf = (char *) malloc(sizeof(char)*qstrlen);
00184 if(!qstrbuf)
00185 return RMCLIENT_ERROR_MEMORY;
00186
00187 strncpy(qstrbuf, query->qstr.c_str(), qstrlen);
00188 }
00189 }
00190
00191 aBuf = qstrbuf;
00192 break;
00193
00194 default:
00195 return RMCLIENT_ERROR_NOSUCHNAME;
00196 }
00197 return RMCLIENT_SUCCESS;
00198 }
00199
00200 int
00201 eventQuery::setString(RMAttribute aName, unsigned long aID, char * aBuf)
00202 {
00203 EventQuery * query = getElement(aID);
00204 if(!query)
00205 return RMCLIENT_ERROR_QUERY;
00206
00207 if(query->refCnt > 0)
00208 return RMCLIENT_ERROR_CC_REFCNT;
00209
00210 switch(aName) {
00211
00212 case EVENTQUERY_STRING:
00213
00214
00215 if(query->status == ACTIVE)
00216 return RMCLIENT_ERROR_STATE;
00217
00218 query->qstr = aBuf;
00219 break;
00220
00221 default:
00222 return RMCLIENT_ERROR_NOSUCHNAME;
00223 }
00224
00225 updateStatus(*query);
00226 return RMCLIENT_SUCCESS;
00227 }
00228
00229 int
00230 eventQuery::addDefaultElement(unsigned long aID)
00231 {
00232 EventQuery query;
00233
00234
00235
00236 query.purpose = 0;
00237 query.refCnt = 0;
00238 query.status = NOTREADY;
00239
00240 return addElement(query, aID);
00241 }
00242
00243