9 #include "..\newicp\isiscrpt.h"
10 #include "..\newicp\isisraw.h"
37 if (WSAStartup(MAKEWORD(2, 2), &WsaDat) != 0)
41 SOCKET s = socket(PF_INET, SOCK_STREAM, 0);
47 hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
54 hr =
m_dae.CoCreateInstance(isisicpLib::CLSID_dae, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER|CLSCTX_LOCAL_SERVER);
64 struct sockaddr_in sin, sad_from;
65 memset(&sin, 0,
sizeof(sin));
66 struct in_addr the_addr;
67 the_addr.S_un.S_addr = INADDR_ANY;
68 sin.sin_family = PF_INET;
69 sin.sin_addr = the_addr;
71 if (bind(s, (
struct sockaddr*)&sin,
sizeof(sin)) == -1)
77 if (listen(s, 5) == -1)
88 std::list<ISISDSRequest*>::iterator iter;
93 if ( !((*iter)->isRunning()) )
103 struct timeval select_timeout = { 5, 0 };
104 n = select(FD_SETSIZE, &readfds, NULL, NULL, &select_timeout);
114 hr =
m_dae->areYouThere();
126 if (FD_ISSET(s, &readfds))
128 len_sadfrom =
sizeof(sad_from);
129 sd = accept(s, (
struct sockaddr*)&sad_from, &len_sadfrom);
132 Poco::Thread::sleep(2000);
135 setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, (
char*)&setkeepalive,
sizeof(setkeepalive));
136 address = inet_ntoa(sad_from.sin_addr);
147 int dims_array_out[10], ndims_out;
150 hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
155 char *command_in, *comm_data_in, *comm_data_out;
157 int comm_data_len_out, istat;
165 hr =
m_dae.CoCreateInstance(isisicpLib::CLSID_dae, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER|CLSCTX_LOCAL_SERVER);
175 int ndims_in, data_dims_in[10];
184 comm_data_out, type_out, dims_array_out, ndims_out, free_out))
193 if (comm_data_in != NULL)
213 char*& comm_data_out,
ISISDSDataType& type_out,
int* dims_array_out,
int& ndims_out,
bool& free_out)
218 double dvalue, *darray;
226 comm_data_out = NULL;
229 dims_array_out[0] = 0;
231 if ( !strcmp(command_in,
"GETPARC08") &&
234 comm_data_out = strdup(cvalue.c_str());
235 dims_array_out[0] = strlen(comm_data_out);
238 LOGSTR_DEBUG(
"Processing command \"" << command_in <<
"\" for item \"" << comm_data_in <<
"\" returning \"" << comm_data_out <<
"\"");
241 else if ( !strcmp(command_in,
"GETPARI32") &&
244 dims_array_out[0] = 1;
245 comm_data_out = (
char*)malloc(
sizeof(
int));
246 *((
int*)comm_data_out) = lvalue;
249 LOGSTR_DEBUG(
"Processing command \"" << command_in <<
"\" for item \"" << comm_data_in <<
"\" returning " << lvalue);
252 else if (!strcmp(command_in,
"GETPARR32") &&
255 dims_array_out[0] = 1;
256 comm_data_out = (
char*)malloc(
sizeof(
float));
257 *((
float*)comm_data_out) = dvalue;
260 LOGSTR_DEBUG(
"Processing command \"" << command_in <<
"\" for item \"" << comm_data_in <<
"\" returning " << dvalue);
263 else if (!strcmp(command_in,
"GETPARR64") &&
266 dims_array_out[0] = 1;
267 comm_data_out = (
char*)malloc(
sizeof(
double));
268 *((
double*)comm_data_out) = dvalue;
271 LOGSTR_DEBUG(
"Processing command \"" << command_in <<
"\" for item \"" << comm_data_in <<
"\" returning " << dvalue);
274 else if (!strcmp(command_in,
"GETPARR64") &&
278 for(i=0; i<ndims_out; i++)
280 total_size *= dims_array_out[i];
282 darray = (
double*)malloc(total_size *
sizeof(
double));
284 comm_data_out = (
char*)darray;
287 LOGSTR_DEBUG(
"Processing command \"" << command_in <<
"\" for item \"" << comm_data_in <<
"\" returning array length " << total_size);
290 else if (!strcmp(command_in,
"GETPARR32") &&
294 for(i=0; i<ndims_out; i++)
296 total_size *= dims_array_out[i];
298 farray = (
float*)malloc(total_size *
sizeof(
float));
300 comm_data_out = (
char*)farray;
303 LOGSTR_DEBUG(
"Processing command \"" << command_in <<
"\" for item \"" << comm_data_in <<
"\" returning array length " << total_size);
306 else if ( !strcmp(command_in,
"GETPARI32") &&
310 for(i=0; i<ndims_out; i++)
312 total_size *= dims_array_out[i];
314 larray = (
long*)malloc(total_size *
sizeof(
long));
316 comm_data_out = (
char*)larray;
319 LOGSTR_DEBUG(
"Processing command \"" << command_in <<
"\" for item \"" << comm_data_in <<
"\" returning array length " << total_size);
322 else if ( !strcmp(command_in,
"GETDAT") )
324 int dims_temp[5], ndims_temp;
325 int ifsn = ((
int*)comm_data_in)[0];
326 int nos = ((
int*)comm_data_in)[1];
327 long* spec_array =
new long[nos];
330 spec_array[i] = ifsn + i;
332 BSTR messages = NULL;
335 hr =
m_dae->updateCRPTSpectra(0, ifsn, nos, &messages);
348 total_size = dims_temp[0] * nos;
353 dims_array_out[0] = total_size;
354 larray = (
long*)malloc(total_size *
sizeof(
long));
356 comm_data_out = (
char*)larray;
360 LOGSTR_DEBUG(
"Processing command \"" << command_in <<
"\" ifsn " << ifsn <<
" nos " << nos <<
" returning array length " << total_size);
int getRealArrayItem(const char *item_name, const long *spec_array, int nspec, double *darray, DAEstatus &status) const
CComPtr< isisicpLib::Idae > m_dae
int getCharItem(const char *item_name, std::string &cvalue, DAEstatus &status) const
int getIntArrayItem(const char *item_name, const long *spec_array, int nspec, long *larray, DAEstatus &status) const
#define LOGSTR_DEBUG(__arg)
CComPtr< isisicpLib::Idae > m_dae
int isisds_send_command(SOCKET s, const char *command, const void *data, ISISDSDataType type, const int dims_array[], int ndims)
std::list< ISISDSRequest * > m_requests
int getRealItem(const char *item_name, double &dblVal, DAEstatus &status) const
#define LOGSTR_ERROR(__arg)
int getRealArrayItemSize(const char *item_name, int *dims_array, int &ndims, DAEstatus &status) const
int mapCRPT(const std::string &crpt_name, const std::string &crpt_data_name, bool read_only, bool existing)
int isisds_recv_open(SOCKET s, ISISDSAccessMode *access_type)
void setLoggerName(const std::string &logger_name)
bool processCommand(ISISDSAccessMode access_type, const char *command_in, const char *comm_data_in, int comm_data_len_in, char *&comm_data_out, ISISDSDataType &type_out, int *dims_array_out, int &ndims_out, bool &free_out)
int addInfo(int facility, const std::string &text)
int getIntItem(const char *item_name, long &lVal, DAEstatus &status) const
int getIntArrayItemSize(const char *item_name, int *dims_array, int &ndims, DAEstatus &status) const
int isisds_recv_command_alloc(SOCKET s, char **command, void **data, ISISDSDataType *type, int dims_array[], int *ndims)