ICP  1
dae.cpp
Go to the documentation of this file.
1 // dae.cpp : Implementation of Cdae
2 
3 #include "stdafx.h"
4 #include "DAEstatus.h"
5 #include "dae.h"
6 #include "variant_utils.h"
7 #include "isisinstrumentcontrol.h"
8 
9 static Poco::SingletonHolder<InstrumentControlHolder> g_icp_singleton;
10 
12 
13 // Cdae
14 
15 STDMETHODIMP Cdae::InterfaceSupportsErrorInfo(REFIID riid)
16 {
17  static const IID* const arr[] =
18  {
19  &IID_Idae
20  };
21 
22  for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
23  {
24  if (InlineIsEqualGUID(*arr[i],riid))
25  return S_OK;
26  }
27  return S_FALSE;
28 }
29 
30 #if 0
31 // it is not recommended to use AtlReportError() in a catch() hence we have to copy
32 // ex.what() to a string and use this function
33 template <class T>
34 HRESULT reportError(T* obj, const std::string& errmsg)
35 {
36  if (errmsg.empty())
37  {
38  return S_OK;
39  }
40  else
41  {
42  AtlReportError(obj->GetObjectCLSID(), errmsg.c_str());
43  return E_FAIL;
44  }
45 }
46 #endif
47 
48 template <typename T>
49 HRESULT Cdae::callICP(BSTR* messages, T& result, boost::function<T(ISISinstrumentControl*, DAEstatus&)> func)
50 {
51  DAEstatus status;
52  std::string exc_mess;
53  ISISinstrumentControl* the_icp = g_icp_singleton.get();
54  if (the_icp == NULL)
55  {
56  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
57  }
58  else
59  {
61  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
62  try
63  {
65  result = func(the_icp, boost::ref(status));
66  }
67  catch(const std::exception& ex)
68  {
69  exc_mess = ex.what();
70  }
71  catch(...)
72  {
73  exc_mess = "Unknown Win32 exception";
74  }
75  the_icp->unregisterStructuredExceptionHandler(old_se_func);
76  }
77  if (exc_mess.size() > 0)
78  {
79  status.addVa(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "Exception caught in Cdae::callICP() %s", exc_mess.c_str());
80  }
81  return makeResult(status, messages);
82 }
83 
84 template <typename T>
85 HRESULT Cdae::callICP(BSTR* messages, boost::function<T(ISISinstrumentControl*, DAEstatus&)> func)
86 {
87  T icp_result;
88  return callICP<T>(messages, icp_result, func);
89 }
90 
91 static int getXML(const BSTR xml_in, std::string& xml_out)
92 {
93  int l, n, i;
94  l = SysStringLen(xml_in); // l is length without NULL terminator
95  n = WideCharToMultiByte(CP_ACP, 0, xml_in, l, 0, 0, NULL, NULL);
96  char* buffer = new char[n+1];
97  WideCharToMultiByte(CP_ACP, 0, xml_in, l, buffer, n, NULL, NULL);
98  buffer[n] = '\0';
99  for(i=0; i<n; i++)
100  {
101  if (buffer[i] == '\0')
102  {
103  buffer[i] = ' '; // labview can put embedded NULLS into this
104  }
105  }
106  xml_out = buffer;
107  delete[] buffer;
108  return 0;
109 }
110 
111 static void getBSTRValue(const BSTR bstr, std::string& str)
112 {
113  char buffer[1024];
114  int n = sizeof(buffer) - 1;
115  wcstombs(buffer, bstr, n);
116  buffer[n] = '\0';
117  str = buffer;
118 }
119 
120 
121 static int variantToStringTable(VARIANT* v, string_table_t& string_table)
122 {
123  int dims_array[10], ndims, i, j, k;
124  dims_array[0] = dims_array[1] = 0;
125  BSTR* bstr_array = NULL;
126  arrayVariantDimensions(v, dims_array, ndims);
127  accessArrayVariant(v, &bstr_array);
128  k = 0;
129  string_table.resize(dims_array[0]);
130  for(i=0; i<dims_array[0]; i++)
131  {
132  string_table[i].resize(dims_array[1]);
133  }
134  // the string table from labview appears to have the column index as the fastest varying
135  for(j=0; j<dims_array[1]; j++)
136  {
137  for(i=0; i<dims_array[0]; i++)
138  {
139  getBSTRValue(bstr_array[k], string_table[i][j]);
140  k++;
141  }
142  }
144  return 0;
145 }
146 
147 STDMETHODIMP Cdae::updateStatusXML(BSTR* cluster_xml, BSTR* messages)
148 {
149  std::string s;
150  if (cluster_xml == NULL || *cluster_xml == NULL)
151  {
152  return E_FAIL;
153  }
154  getXML(*cluster_xml, s);
155  HRESULT hr = callICP<int>(messages, boost::bind(&ISISinstrumentControl::updateStatusXML, _1, boost::ref(s), _2));
156  if (SUCCEEDED(hr))
157  {
158  reallocBSTR(cluster_xml, s.c_str());
159  }
160  return hr;
161 }
162 
163 BSTR Cdae::makeBSTR(const char* str)
164 {
165  BSTR bstr;
166  size_t l;
167  wchar_t* wbuffer = NULL;
168  l = strlen(str);
169  if (l > 0)
170  {
171  wbuffer = new wchar_t[l + 1];
172  mbstowcs(wbuffer, str, l+1);
173  bstr = SysAllocString(wbuffer);
174  delete[] wbuffer;
175  }
176  else
177  {
178  bstr = SysAllocString(L"");
179  }
180  return bstr;
181 }
182 
183 
184 int Cdae::reallocBSTR(BSTR* bstr, const char* str)
185 {
186  size_t l;
187  wchar_t* wbuffer = NULL;
188  l = strlen(str);
189  if (l > 0)
190  {
191  wbuffer = new wchar_t[l + 1];
192  mbstowcs(wbuffer, str, l+1);
193  SysReAllocString(bstr, wbuffer);
194  delete[] wbuffer;
195  }
196  else
197  {
198  SysReAllocString(bstr, L"");
199  }
200  return 0;
201 }
202 
203 
204 
205 HRESULT Cdae::makeResult(DAEstatus& status, BSTR* messages, bool force_success_result)
206 {
207  std::ostringstream info_stream, all_stream;
208  status.reportAll(all_stream, false, false);
209  std::string all_stream_str(all_stream.str());
210  if (force_success_result)
211  {
212  if (all_stream_str.length() > 0)
213  {
214  g_status.addInfo(FAC_DAE, all_stream_str);
215  }
216  status.reportAll(info_stream);
217  }
218  else
219  {
220  if (all_stream_str.length() > 0)
221  {
222  g_status.add(FAC_DAE, status.severity(), ERRTYPE_OUTOFMEM, all_stream_str);
223  }
224  status.report(info_stream, SEV_WARNING, SEV_LE);
225  }
226  std::string info_string(info_stream.str());
227  if (messages != NULL)
228  {
229  *messages = makeBSTR(info_string.c_str());
230  }
231  if (status.OK())
232  {
233  return S_OK;
234  }
235  else
236  {
237  std::ostringstream error_stream;
238  status.report(error_stream, SEV_ERROR, SEV_GE);
239  std::string error_string(error_stream.str());
240  return AtlReportError(GetObjectCLSID(), error_string.c_str(), __uuidof(Idae));
241  }
242 }
243 
244 STDMETHODIMP Cdae::beginRun(BSTR* messages)
245 {
246  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::beginRun, _1, _2));
247 }
248 
249 STDMETHODIMP Cdae::endRun(BSTR* messages)
250 {
251  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::endRun, _1, _2));
252 }
253 
254 STDMETHODIMP Cdae::pauseRun(BSTR* messages)
255 {
256  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::pauseRun, _1, _2));
257 }
258 
259 STDMETHODIMP Cdae::resumeRun(BSTR* messages)
260 {
261  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::resumeRun, _1, _2));
262 }
263 
264 STDMETHODIMP Cdae::saveRun(BSTR* messages)
265 {
266  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::saveRun, _1, _2));
267 }
268 
269 STDMETHODIMP Cdae::abortRun(BSTR* messages)
270 {
271  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::abortRun, _1, _2));
272 }
273 
274 STDMETHODIMP Cdae::startSEWait(BSTR* messages)
275 {
276  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::startSEWait, _1, _2));
277 }
278 
279 STDMETHODIMP Cdae::endSEWait(BSTR* messages)
280 {
281  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::endSEWait, _1, _2));
282 }
283 
284 STDMETHODIMP Cdae::getSpectrum(LONG spectrum_number, LONG period, VARIANT* time_channels, VARIANT* signal, LONG as_histogram, LONG as_distribution, LONG* sum, BSTR* messages)
285 {
286  // TODO: Add your implementation code here
287  int dims_array[1];
288  DAEstatus status;
289  VariantInit(time_channels);
290  VariantInit(signal);
291  double *time_array = 0, *signal_array = 0, *error_array=0;
292  ISISinstrumentControl* the_icp = g_icp_singleton.get();
293  if (the_icp == NULL)
294  {
295  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
296  return makeResult(status, messages);
297  }
299  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
301  int ntc = the_icp->getNumberOfTimeChannels(spectrum_number, status);
302  dims_array[0] = ntc;
303  allocateArrayVariant(signal, VT_R8, dims_array, 1);
304  if (as_histogram)
305  {
306  dims_array[0] = ntc+1;
307  }
308  allocateArrayVariant(time_channels, VT_R8, dims_array, 1);
309  accessArrayVariant(time_channels, &time_array);
310  accessArrayVariant(signal, &signal_array);
311  if ( (time_array == 0) || (signal_array == 0) )
312  {
313  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
314  the_icp->unregisterStructuredExceptionHandler(old_se_func);
315  return makeResult(status, messages);
316  }
317  error_array = new double[ntc];
318  the_icp->getSpectrum(spectrum_number, period-1, time_array, signal_array, error_array,
319  (as_histogram != 0 ? true : false), (as_distribution != 0 ? true : false), *sum, status);
320  delete[] error_array;
321  unaccessArrayVariant(signal);
322  unaccessArrayVariant(time_channels);
323  the_icp->unregisterStructuredExceptionHandler(old_se_func);
324  return makeResult(status, messages);
325 }
326 
327 STDMETHODIMP Cdae::changeTCB(BSTR tcb_xml, BSTR* messages)
328 {
329  std::string s;
330  getXML(tcb_xml, s);
331  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::updateTCBXML, _1, boost::cref(s), _2));
332 }
333 
334 STDMETHODIMP Cdae::changeDAEsettings(BSTR dae_xml, BSTR* messages)
335 {
336  std::string s;
337  getXML(dae_xml, s);
338  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::updateDAEsettingsXML, _1, boost::cref(s), _2));
339 }
340 
341 STDMETHODIMP Cdae::getSpectrumIntegral(LONG spectrum_number, LONG period, FLOAT time_low, FLOAT time_high, LONG* counts, BSTR* messages)
342 {
343  DAEstatus status;
344  long max_val;
345  ISISinstrumentControl* the_icp = g_icp_singleton.get();
346  if (the_icp == NULL)
347  {
348  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
349  return makeResult(status, messages);
350  }
352  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
354  the_icp->getSpectrumIntegral(spectrum_number, period-1, time_low, time_high, *counts, max_val, status);
355  the_icp->unregisterStructuredExceptionHandler(old_se_func);
356  return makeResult(status, messages);
357 }
358 
359 
360 HRESULT Cdae::getSpectraIntegralHelper(spec_int_func_t func, VARIANT spectrum_numbers, LONG period, VARIANT time_low, VARIANT time_high, VARIANT* counts, BSTR* messages)
361 {
362  DAEstatus status;
363  VariantInit(counts);
364  ISISinstrumentControl* the_icp = g_icp_singleton.get();
365  if (the_icp == NULL)
366  {
367  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
368  return makeResult(status, messages);
369  }
371  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
373  float *tlow, *thigh;
374  long *spec, *cnts;
375  int dims_array[1];
376  dims_array[0] = arrayVariantLength(&spectrum_numbers);
377  long* max_vals = new long[dims_array[0]];
378  allocateArrayVariant(counts, VT_I4, dims_array, 1);
379  accessArrayVariant(counts, &cnts);
380  accessArrayVariant(&time_low, &tlow);
381  accessArrayVariant(&time_high, &thigh);
382  accessArrayVariant(&spectrum_numbers, &spec);
383 
384  (the_icp->*func)(dims_array[0], spec, period-1, tlow, thigh, cnts, max_vals, status);
385  unaccessArrayVariant(counts);
386  unaccessArrayVariant(&time_low);
387  unaccessArrayVariant(&time_high);
388  unaccessArrayVariant(&spectrum_numbers);
389  delete[] max_vals;
390  the_icp->unregisterStructuredExceptionHandler(old_se_func);
391  return makeResult(status, messages);
392 }
393 
394 STDMETHODIMP Cdae::getSpectraIntegral(VARIANT spectrum_numbers, LONG period, VARIANT time_low, VARIANT time_high, VARIANT* counts, BSTR* messages)
395 {
396  return getSpectraIntegralHelper(&ISISinstrumentControl::getSpectrumIntegral, spectrum_numbers, period, time_low, time_high, counts, messages);
397 }
398 
399 STDMETHODIMP Cdae::getSpectraIntegral2(LONG spec_start, LONG nspectra, LONG period, FLOAT time_low, FLOAT time_high, VARIANT* counts, BSTR* messages)
400 {
401  DAEstatus status;
402  ISISinstrumentControl* the_icp = g_icp_singleton.get();
403  if (the_icp == NULL)
404  {
405  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
406  return makeResult(status, messages);
407  }
409  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
410  VariantInit(counts);
411  int dims_array[1];
412  long* cnts = NULL;
413  dims_array[0] = nspectra;
414  allocateArrayVariant(counts, VT_I4, dims_array, 1);
415  accessArrayVariant(counts, &cnts);
417 // this is not ready yet
418 // if (time_low >= time_high)
419 // {
420 // the_icp->getCRPTSpectrumIntegral(spec_start, nspectra, period-1, cnts, status);
421 // }
422 // else
423 // {
424  the_icp->getCRPTSpectrumIntegral(spec_start, nspectra, period-1, time_low, time_high, cnts, NULL, status);
425 // }
426 // HRESULT hr = callICP<int>(messages, boost::bind(&ISISinstrumentControl::getCRPTSpectrumIntegral, _1, spec_start, nspectra, period-1, time_low, time_high, cnts, NULL, _2));
427  unaccessArrayVariant(counts);
428  the_icp->unregisterStructuredExceptionHandler(old_se_func);
429  return makeResult(status, messages);
430 }
431 
432 
433 STDMETHODIMP Cdae::getsect(LONG start, LONG length, VARIANT* values, BSTR* messages)
434 {
435  DAEstatus status;
436  VariantInit(values);
437  ISISinstrumentControl* the_icp = g_icp_singleton.get();
438  if (the_icp == NULL)
439  {
440  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
441  return makeResult(status, messages);
442  }
444  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
446  int dims_array[1];
447  dims_array[0] = length;
448  long* vals = 0;
449  allocateArrayVariant(values, VT_I4, dims_array, 1);
450  accessArrayVariant(values, &vals);
451 // the_icp->getsect(start, length, vals);
452  unaccessArrayVariant(values);
453  the_icp->unregisterStructuredExceptionHandler(old_se_func);
454  return makeResult(status, messages);
455 }
456 
457 STDMETHODIMP Cdae::rio(LONG address, LONG* value, BSTR* messages)
458 {
459  // TODO: Add your implementation code here
460  DAEstatus status;
461  ISISinstrumentControl* the_icp = g_icp_singleton.get();
462  if (the_icp == NULL)
463  {
464  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
465  return makeResult(status, messages);
466  }
467  isisU16_t word;
469  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
471  the_icp->RIO(address, word, status);
472  *value = word;
473  the_icp->unregisterStructuredExceptionHandler(old_se_func);
474  return makeResult(status, messages);
475 }
476 
477 
478 STDMETHODIMP Cdae::getValue(BSTR name, BSTR* messages, VARIANT* result)
479 {
480  int i;
481  char item_name[64];
482  DAEstatus status;
483  VariantInit(result);
484  ISISinstrumentControl* the_icp = g_icp_singleton.get();
485  if (the_icp == NULL)
486  {
487  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
488  return makeResult(status, messages);
489  }
491  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
493  wcstombs(item_name, name, sizeof(item_name));
494  for(i=0; i<strlen(item_name); i++)
495  {
496  item_name[i] = toupper(item_name[i]);
497  }
498  getValueMain(the_icp, item_name, result, status);
499  the_icp->unregisterStructuredExceptionHandler(old_se_func);
500  return makeResult(status, messages);
501 }
502 
503 int Cdae::getArrayValueMain(ISISinstrumentControl* the_icp, const char* item_name, long args[], int nargs, VARIANT* result, DAEstatus& status)
504 {
505 // std::string cvalue;
506  char* item_temp;
507  const char* name_temp;
508  double* darray = 0;
509  long* larray = 0;
510  VARIANT* varray = 0;
511  int i, n, ndims, dims_array[10];
512  if (strchr(item_name,',') != NULL)
513  {
514  dims_array[0] = 1;
515  for(i=0; i<strlen(item_name); i++)
516  {
517  if (item_name[i] == ',')
518  {
519  ++dims_array[0];
520  }
521  }
522  allocateArrayVariant(result, VT_VARIANT, dims_array, 1);
523  accessArrayVariant(result, &varray);
524  item_temp = strdup(item_name);
525  name_temp = strtok(item_temp, ",");
526  n = 0;
527  while(name_temp != NULL)
528  {
529  getArrayValueMain(the_icp, name_temp, args, nargs, varray + n, status);
530  name_temp = strtok(NULL, ",");
531  n++;
532  }
533  free(item_temp);
534  // clean up end of array in case strtok and dims_array[0] disagree
535  // this should only happen if e.g. ",,," is specified as the initial
536  // count will give this a 3 by == but strtok() will only see 1
537  if (n < dims_array[0])
538  {
539  for(i=n; i<dims_array[0]; i++)
540  {
541  VariantInit(varray + i);
542  }
543  }
544  unaccessArrayVariant(result);
545  return 0;
546  }
547  if (the_icp->getIntItem(item_name, result->lVal, status) == DAEstatus::Success)
548  {
549  allocateArrayVariant(result, VT_I4, &nargs, 1);
550  accessArrayVariant(result, &larray);
551  the_icp->getIntItem(item_name, args, nargs, larray, status);
552  unaccessArrayVariant(result);
553  }
554  else if (the_icp->getRealItem(item_name, result->dblVal, status) == DAEstatus::Success)
555  {
556  allocateArrayVariant(result, VT_R8, &nargs, 1);
557  accessArrayVariant(result, &darray);
558  the_icp->getRealItem(item_name, args, nargs, darray, status);
559  unaccessArrayVariant(result);
560  }
561  // use dims_array+1 as C has fastest varying stuff at the end and we need to set
562  // num_spectra as the slowest varying index
563  else if (the_icp->getIntArrayItemSize(item_name, &dims_array[1], ndims, status) == DAEstatus::Success)
564  {
565  dims_array[0] = nargs;
566  ndims++;
567  allocateArrayVariant(result, VT_I4, dims_array, ndims);
568  accessArrayVariant(result, &larray);
569  the_icp->getIntArrayItem(item_name, args, nargs, larray, status);
570  unaccessArrayVariant(result);
571  }
572  // use dims_array+1 as C has fastest varying stuff at the end and we need to set
573  // num_spectra as the slowest varying index
574  else if (the_icp->getRealArrayItemSize(item_name, &dims_array[1], ndims, status) == DAEstatus::Success)
575  {
576  dims_array[0] = nargs;
577  ndims++;
578  allocateArrayVariant(result, VT_R8, dims_array, ndims);
579  accessArrayVariant(result, &darray);
580  the_icp->getRealArrayItem(item_name, args, nargs, darray, status);
581  unaccessArrayVariant(result);
582  }
583  else
584  {
585  status.addVa(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "Item \"%s\" not found", item_name);
586  }
587  return 0;
588 }
589 
590 int Cdae::getValueMain(ISISinstrumentControl* the_icp, const char* item_name, VARIANT* result, DAEstatus& status)
591 {
592  char* item_temp;
593  const char* name_temp;
594  double* darray = 0;
595  long* larray = 0;
596  VARIANT* varray = 0;
597  int i, n, ndims, dims_array[10];
598  if (strchr(item_name,',') != NULL)
599  {
600  dims_array[0] = 1;
601  for(i=0; i<strlen(item_name); i++)
602  {
603  if (item_name[i] == ',')
604  {
605  ++dims_array[0];
606  }
607  }
608  allocateArrayVariant(result, VT_VARIANT, dims_array, 1);
609  accessArrayVariant(result, &varray);
610  item_temp = strdup(item_name);
611  name_temp = strtok(item_temp, ",");
612  n = 0;
613  while(name_temp != NULL)
614  {
615  getValueMain(the_icp, name_temp, varray + n, status);
616  name_temp = strtok(NULL, ",");
617  n++;
618  }
619  free(item_temp);
620  // clean up end of array in case strtok and dims_array[0] disagree
621  // this should only happen if e.g. ",,," is specified as the initial
622  // count will give this a 3 by == but strtok() will only see 1
623  if (n < dims_array[0])
624  {
625  for(i=n; i<dims_array[0]; i++)
626  {
627  VariantInit(varray + i);
628  }
629  }
630  unaccessArrayVariant(result);
631  return 0;
632  }
633  std::string cvalue;
634  if (the_icp->getIntItem(item_name, result->lVal, status) == DAEstatus::Success)
635  {
636  result->vt = VT_I4;
637  }
638  else if (the_icp->getRealItem(item_name, result->dblVal, status) == DAEstatus::Success)
639  {
640  result->vt = VT_R8;
641  }
642  else if (the_icp->getIntArrayItemSize(item_name, dims_array, ndims, status) == DAEstatus::Success)
643  {
644  allocateArrayVariant(result, VT_I4, dims_array, ndims);
645  accessArrayVariant(result, &larray);
646  the_icp->getIntArrayItem(item_name, larray, status);
647  unaccessArrayVariant(result);
648  }
649  else if (the_icp->getRealArrayItemSize(item_name, dims_array, ndims, status) == DAEstatus::Success)
650  {
651  allocateArrayVariant(result, VT_R8, dims_array, ndims);
652  accessArrayVariant(result, &darray);
653  the_icp->getRealArrayItem(item_name, darray, status);
654  unaccessArrayVariant(result);
655  }
656  else if (the_icp->getCharItem(item_name, cvalue, status) == DAEstatus::Success)
657  {
658  CComBSTR b(cvalue.c_str());
659  b.CopyTo(result);
660  }
661  else
662  {
663  status.addVa(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "Item \"%s\" not found", item_name);
664  }
665  return 0;
666 }
667 
668 STDMETHODIMP Cdae::getRawFramesTotal(BSTR* messages, LONG* value)
669 {
670  return callICP<LONG>(messages, *value, boost::bind(&ISISinstrumentControl::getRawFrames, _1, _2));
671 }
672 
673 STDMETHODIMP Cdae::getGoodFramesTotal(BSTR* messages, LONG* value)
674 {
675  return callICP<LONG>(messages, *value, boost::bind(&ISISinstrumentControl::getGoodFrames, _1, _2));
676 }
677 
678 STDMETHODIMP Cdae::getGoodUAmpH(BSTR* messages, DOUBLE* value)
679 {
680  return callICP<DOUBLE>(messages, *value, boost::bind(&ISISinstrumentControl::getGoodUAmpH, _1, _2));
681 }
682 
683 STDMETHODIMP Cdae::getSpectraSum(LONG period, LONG first_spec, LONG num_spec, LONG spec_type, DOUBLE time_low, DOUBLE time_high, VARIANT* sums, VARIANT* max_vals, VARIANT* spec_nums, BSTR* messages)
684 {
685  DAEstatus status;
686  int j;
687  VariantInit(sums);
688  VariantInit(max_vals);
689  VariantInit(spec_nums);
690  ISISinstrumentControl* the_icp = g_icp_singleton.get();
691  if (the_icp == NULL)
692  {
693  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
694  return makeResult(status, messages);
695  }
697  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
699  long *cnts, *maxs, *nums;
700  int nsp = the_icp->getNumberOfSpectra(status);
701  int nspec = num_spec;
702  allocateArrayVariant(sums, VT_I4, &nspec, 1);
703  allocateArrayVariant(max_vals, VT_I4, &nspec, 1);
704  allocateArrayVariant(spec_nums, VT_I4, &nspec, 1);
705  accessArrayVariant(sums, &cnts);
706  accessArrayVariant(max_vals, &maxs);
707  accessArrayVariant(spec_nums, &nums);
708  j = 0;
709  int spec = first_spec;
710  while(j < num_spec)
711  {
712  if (spec > nsp)
713  {
714  cnts[j] = maxs[j] = 0;
715  nums[j] = -1;
716  j++;
717  }
718  else
719  {
720  the_icp->getSpectrumIntegral(spec, period-1, time_low, time_high, cnts[j], maxs[j], status);
721  if ( (spec_type == 0) || // show all spectra
722  ((spec_type == 1) && (cnts[j] == 0)) || // zero counts only
723  ((spec_type == 2) && (cnts[j] > 0)) // non-zero counts only
724  )
725  {
726  nums[j] = spec;
727  j++;
728  }
729  }
730  spec++;
731  }
732  unaccessArrayVariant(sums);
733  unaccessArrayVariant(max_vals);
734  unaccessArrayVariant(spec_nums);
735  the_icp->unregisterStructuredExceptionHandler(old_se_func);
736  return makeResult(status, messages);
737 }
738 
739 STDMETHODIMP Cdae::changeSample(BSTR sample_xml, BSTR* messages)
740 {
741  std::string s;
742  getXML(sample_xml, s);
743  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::updateSampleXML, _1, boost::cref(s), _2));
744 }
745 
746 STDMETHODIMP Cdae::changeUser(BSTR user_xml, BSTR* messages)
747 {
748  std::string s;
749  getXML(user_xml, s);
750  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::updateUserXML, _1, boost::cref(s), _2));
751 }
752 
753 STDMETHODIMP Cdae::changeHardwarePeriods(BSTR periods_xml, BSTR* messages)
754 {
755  std::string s;
756  getXML(periods_xml, s);
757  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::updateHardwarePeriodsXML, _1, boost::cref(s), _2));
758 }
759 
760 STDMETHODIMP Cdae::changePeriod(LONG period_number, BSTR* messages)
761 {
762  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::changePeriod, _1, period_number - 1, _2));
763 }
764 
765 STDMETHODIMP Cdae::dumpDebugInfo(BSTR* messages)
766 {
767  DAEstatus status;
768  ISISinstrumentControl* the_icp = g_icp_singleton.get();
769  if (the_icp == NULL)
770  {
771  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
772  return makeResult(status, messages);
773  }
774  std::ostringstream os;
776  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
777  the_icp->printStatus(os, status);
778  status.addInfo(FAC_DAE, os.str());
779  the_icp->unregisterStructuredExceptionHandler(old_se_func);
780  return makeResult(status, messages, true);
781 }
782 
783 STDMETHODIMP Cdae::VMEWriteValue(ULONG card_id, ULONG card_address, ULONG word_size, ULONG value, ULONG mode, BSTR* messages)
784 {
785  DAEstatus status;
786  ISISinstrumentControl* the_icp = g_icp_singleton.get();
787  if (the_icp == NULL)
788  {
789  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
790  return makeResult(status, messages);
791  }
792  bool sixteen_bit = (word_size == 0);
794  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
796  the_icp->VMEWriteValue(card_id, card_address, sixteen_bit, value, mode, status);
797  the_icp->unregisterStructuredExceptionHandler(old_se_func);
798  return makeResult(status, messages);
799 }
800 
801 STDMETHODIMP Cdae::VMEReadValue(ULONG card_id, ULONG card_address, ULONG word_size, ULONG* value, BSTR* messages)
802 {
803  DAEstatus status;
804  ISISinstrumentControl* the_icp = g_icp_singleton.get();
805  if (the_icp == NULL)
806  {
807  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
808  return makeResult(status, messages);
809  }
810  bool sixteen_bit = (word_size == 0);
812  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
814  the_icp->VMEReadValue(card_id, card_address, sixteen_bit, value, status);
815  the_icp->unregisterStructuredExceptionHandler(old_se_func);
816  return makeResult(status, messages);
817 }
818 
819 STDMETHODIMP Cdae::sumAllSpectra(LONG* counts, LONG* bin0_counts, BSTR* messages)
820 {
821  // TODO: Add your implementation code here
822  DAEstatus status;
823  ISISinstrumentControl* the_icp = g_icp_singleton.get();
824  if (the_icp == NULL)
825  {
826  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
827  return makeResult(status, messages);
828  }
830  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
832  the_icp->sumAllSpectra(*counts, *bin0_counts, status);
833  the_icp->unregisterStructuredExceptionHandler(old_se_func);
834  return makeResult(status, messages);
835 }
836 
837 STDMETHODIMP Cdae::sumAllHistogramMemory(LONG* counts, BSTR* messages)
838 {
839  DAEstatus status;
840  ISISinstrumentControl* the_icp = g_icp_singleton.get();
841  if (the_icp == NULL)
842  {
843  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
844  return makeResult(status, messages);
845  }
847  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
849  the_icp->sumAllHistogramMemory(*counts, status);
850  the_icp->unregisterStructuredExceptionHandler(old_se_func);
851  return makeResult(status, messages);
852 }
853 
854 STDMETHODIMP Cdae::VMEReadArray(ULONG card_id, ULONG card_address, VARIANT* values, ULONG num_values, BSTR* messages)
855 {
856  long* rv;
857  int dims_array[1];
858  DAEstatus status;
859  ISISinstrumentControl* the_icp = g_icp_singleton.get();
860  if (the_icp == NULL)
861  {
862  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
863  return makeResult(status, messages);
864  }
866  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
868  VariantInit(values);
869  dims_array[0] = num_values;
870  allocateArrayVariant(values, VT_I4, dims_array, 1);
871  accessArrayVariant(values, &rv);
872  the_icp->VMEReadArray(card_id, card_address, (isisU32_t*)rv, num_values, status);
873  unaccessArrayVariant(values);
874  the_icp->unregisterStructuredExceptionHandler(old_se_func);
875  return makeResult(status, messages);
876 }
877 
878 STDMETHODIMP Cdae::VMEWriteArray(ULONG card_id, ULONG card_address, VARIANT values, BSTR* messages)
879 {
880  DAEstatus status;
881  int num_values;
882  long* rv;
883  ISISinstrumentControl* the_icp = g_icp_singleton.get();
884  if (the_icp == NULL)
885  {
886  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
887  return makeResult(status, messages);
888  }
890  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
892  accessArrayVariant(&values, &rv);
893  num_values = arrayVariantLength(&values);
894  the_icp->VMEWriteArray(card_id, card_address, (isisU32_t*)rv, num_values, status);
895  the_icp->unregisterStructuredExceptionHandler(old_se_func);
896  return makeResult(status, messages);
897 }
898 
899 STDMETHODIMP Cdae::VMEReadValuesToString(ULONG card_id, ULONG card_address, ULONG word_size, ULONG num_values, BSTR* values, BSTR* messages)
900 {
901  DAEstatus status;
902  std::string str_values;
903  ISISinstrumentControl* the_icp = g_icp_singleton.get();
904  if (the_icp == NULL)
905  {
906  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
907  return makeResult(status, messages);
908  }
909  bool sixteen_bit = (word_size == 0);
911  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
913  the_icp->VMEReadValuesToString(card_id, card_address, sixteen_bit, num_values, str_values, status);
914  *values = makeBSTR(str_values.c_str());
915 // status.addInfo(FAC_DAE, str_values);
916  the_icp->unregisterStructuredExceptionHandler(old_se_func);
917  return makeResult(status, messages);
918 }
919 
920 STDMETHODIMP Cdae::refreshCachedValues(BSTR* messages)
921 {
922  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::refreshCachedValues, _1, _2));
923 }
924 
925 STDMETHODIMP Cdae::setOptions(BSTR options_xml, BSTR* messages)
926 {
927  std::string s;
928  getXML(options_xml, s);
929  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::setOptions, _1, boost::cref(s), _2));
930 }
931 
932 STDMETHODIMP Cdae::getOptions(BSTR* options_xml, BSTR* messages)
933 {
934  if (options_xml == NULL || *options_xml == NULL)
935  {
936  return E_FAIL;
937  }
938  std::string s;
939  getXML(*options_xml, s);
940  HRESULT hr = callICP<int>(messages, boost::bind(&ISISinstrumentControl::getOptions, _1, boost::ref(s), _2));
941  reallocBSTR(options_xml, s.c_str());
942  return hr;
943 }
944 
945 STDMETHODIMP Cdae::getArrayValue(BSTR name, VARIANT arg, BSTR* messages, VARIANT* result)
946 {
947  int i;
948  char item_name[64];
949  DAEstatus status;
950  VariantInit(result);
951  ISISinstrumentControl* the_icp = g_icp_singleton.get();
952  if (the_icp == NULL)
953  {
954  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
955  return makeResult(status, messages);
956  }
958  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
960  wcstombs(item_name, name, sizeof(item_name));
961  for(i=0; i<strlen(item_name); i++)
962  {
963  item_name[i] = toupper(item_name[i]);
964  }
965  long* larray = NULL;
966  int n = arrayVariantLength(&arg);
967  accessArrayVariant(&arg, &larray);
968  if (larray != NULL)
969  {
970  getArrayValueMain(the_icp, item_name, larray, n, result, status);
971  }
972  unaccessArrayVariant(&arg);
973  the_icp->unregisterStructuredExceptionHandler(old_se_func);
974  return makeResult(status, messages);
975 }
976 
977 STDMETHODIMP Cdae::updateCRPT(BSTR* messages)
978 {
979  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::updateCRPTWithDAE, _1, false, _2));
980 }
981 
982 STDMETHODIMP Cdae::storeCRPT(BSTR* messages)
983 {
984  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::storeCRPT, _1, _2));
985 }
986 
987 STDMETHODIMP Cdae::setICPValueLong(BSTR name, LONG value, BSTR* messages)
988 {
989  char item_name[128];
990  DAEstatus status;
991  ISISinstrumentControl* the_icp = g_icp_singleton.get();
992  if (the_icp == NULL)
993  {
994  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
995  }
996  else
997  {
999  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
1001  wcstombs(item_name, name, sizeof(item_name));
1002  if (!stricmp(item_name, "RUN_NUMBER"))
1003  {
1004  the_icp->setRunNumber(value, status);
1005  }
1006  if (!stricmp(item_name, "RUN_STATUS"))
1007  {
1008  the_icp->setRunStatus(value, status);
1009  }
1010  the_icp->unregisterStructuredExceptionHandler(old_se_func);
1011  }
1012  return makeResult(status, messages);
1013 }
1014 
1015 STDMETHODIMP Cdae::notifyICP(LONG event_id, BSTR param, BSTR* messages)
1016 {
1017  char notify_param[256];
1018  wcstombs(notify_param, param, sizeof(notify_param));
1019  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::notifyICP, _1, event_id, notify_param, _2));
1020 }
1021 
1022 STDMETHODIMP Cdae::setBlocksTable(VARIANT table, BSTR* messages)
1023 {
1024  string_table_t string_table;
1025  variantToStringTable(&table, string_table);
1026  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::setBlockTable, _1, boost::cref(string_table), _2));
1027 }
1028 
1029 STDMETHODIMP Cdae::setSampleParameters(VARIANT table, BSTR* messages)
1030 {
1031  string_table_t string_table;
1032  variantToStringTable(&table, string_table);
1033  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::setSampleParameters, _1, boost::cref(string_table), _2));
1034 }
1035 
1036 STDMETHODIMP Cdae::setBeamlineParameters(VARIANT table, BSTR* messages)
1037 {
1038  string_table_t string_table;
1039  variantToStringTable(&table, string_table);
1040  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::setBeamlineParameters, _1, boost::cref(string_table), _2));
1041 }
1042 
1043 STDMETHODIMP Cdae::setUserParameters(LONG rbno, VARIANT table, BSTR* messages)
1044 {
1045  string_table_t string_table;
1046  variantToStringTable(&table, string_table);
1047  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::setUserParameters, _1, rbno, boost::cref(string_table), _2));
1048 }
1049 
1050 STDMETHODIMP Cdae::areYouThere(void)
1051 {
1052  HRESULT ret;
1053  ISISinstrumentControl* the_icp = g_icp_singleton.get();
1054  if (the_icp == NULL)
1055  {
1056  ret = E_FAIL;
1057  }
1058  else
1059  {
1060  ret = S_OK;
1061  }
1062  return ret;
1063 }
1064 
1065 STDMETHODIMP Cdae::changeUpdateSettings(BSTR update_xml, BSTR* messages)
1066 {
1067  std::string s;
1068  getXML(update_xml, s);
1069  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::changeUpdateSettingsXML, _1, boost::cref(s), _2));
1070 }
1071 
1072 STDMETHODIMP Cdae::getNPRatio(FLOAT* current, FLOAT* average, BSTR* messages)
1073 {
1074  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::getNPRatio, _1, current, average, _2));
1075 }
1076 
1077 STDMETHODIMP Cdae::getTotalCounts(BSTR* messages, LONG* counts)
1078 {
1079  int64_t counts64 = 0;
1080  HRESULT hr = callICP<int>(messages, boost::bind(&ISISinstrumentControl::getTotalCounts, _1, boost::ref(counts64), _2));
1081  if ( counts64 < std::numeric_limits<LONG>::max() )
1082  {
1083  *counts = static_cast<LONG>(counts64);
1084  }
1085  else
1086  {
1087  *counts = std::numeric_limits<LONG>::max();
1088  }
1089  return hr;
1090 }
1091 
1092 STDMETHODIMP Cdae::getMEvents(BSTR* messages, DOUBLE* mevents)
1093 {
1094  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::getMEvents, _1, boost::ref(*mevents), _2));
1095 }
1096 
1097 STDMETHODIMP Cdae::getMEventsPeriod(LONG period, BSTR* messages, DOUBLE* mevents)
1098 {
1099  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::getMEventsPeriod, _1, boost::ref(*mevents), period - 1, _2));
1100 }
1101 
1102 STDMETHODIMP Cdae::getCurrentPeriodNumber(LONG* period, LONG* daq_period, BSTR* messages)
1103 {
1104  int p, dp;
1105  HRESULT hr = callICP<int>(messages, boost::bind(&ISISinstrumentControl::getCurrentPeriodNumber, _1, boost::ref(p), boost::ref(dp), _2));
1106  *period = p + 1;
1107  *daq_period = dp + 1;
1108  return hr;
1109 }
1110 
1111 STDMETHODIMP Cdae::snapshotCRPT(BSTR filename, LONG do_update, LONG do_pause, BSTR* messages)
1112 {
1113  char fname[256];
1114  wcstombs(fname, filename, sizeof(fname));
1115  NULL_TERMINATE(fname);
1116  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::snapshotCRPT, _1, fname, (do_update != 0), (do_pause != 0), _2));
1117 }
1118 
1119 STDMETHODIMP Cdae::changePeriodWhileRunning(LONG period, LONG pause_first, BSTR* messages)
1120 {
1121  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::changePeriodWhileRunning, _1, period-1, (pause_first != 0), _2));
1122 }
1123 
1124 HRESULT Cdae::getSettings(BSTR xml_in, BSTR* xml_out, BSTR* messages, xml_get_func_t func)
1125 {
1126  *xml_out = NULL;
1127  std::string xml_s_in, xml_s_out;
1128  getXML(xml_in, xml_s_in);
1129  HRESULT hr = callICP<int>(messages, boost::bind(func, _1, boost::cref(xml_s_in), boost::ref(xml_s_out), _2));
1130 // std::string xml_s_out_unescaped = unescapeXML(xml_s_out.c_str());
1131 // *xml_out = makeBSTR(xml_s_out_unescaped.c_str());
1132  if (SUCCEEDED(hr))
1133  {
1134  *xml_out = makeBSTR(xml_s_out.c_str());
1135  }
1136  return hr;
1137 }
1138 
1139 HRESULT Cdae::updateSettings(BSTR xml_in, BSTR* messages, xml_set_func_t func)
1140 {
1141  std::string xml_s;
1142  getXML(xml_in, xml_s);
1143  return callICP<int>(messages, boost::bind(func, _1, boost::cref(xml_s), _2));
1144 }
1145 
1146 
1147 STDMETHODIMP Cdae::getDAEsettings(BSTR dae_xml_in, BSTR* dae_xml_out, BSTR* messages)
1148 {
1149  return getSettings(dae_xml_in, dae_xml_out, messages, &ISISinstrumentControl::getDAEsettingsXML);
1150 }
1151 
1152 STDMETHODIMP Cdae::getHardwarePeriods(BSTR periods_xml_in, BSTR* periods_xml_out, BSTR* messages)
1153 {
1154  return getSettings(periods_xml_in, periods_xml_out, messages, &ISISinstrumentControl::getHardwarePeriodsXML);
1155 }
1156 
1157 STDMETHODIMP Cdae::getTCB(BSTR tcb_xml_in, BSTR* tcb_xml_out, BSTR* messages)
1158 {
1159  return getSettings(tcb_xml_in, tcb_xml_out, messages, &ISISinstrumentControl::getTCBXML);
1160 }
1161 
1162 STDMETHODIMP Cdae::getUpdateSettings(BSTR update_xml_in, BSTR* update_xml_out, BSTR* messages)
1163 {
1164  return getSettings(update_xml_in, update_xml_out, messages, &ISISinstrumentControl::getUpdateSettingsXML);
1165 }
1166 
1167 STDMETHODIMP Cdae::changeNumberOfSoftwarePeriods(LONG nperiod, BSTR* messages)
1168 {
1169  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::changeNumberOfSoftwarePeriods, _1, nperiod, _2));
1170 }
1171 
1172 STDMETHODIMP Cdae::getRunState(BSTR* messages, LONG* state)
1173 {
1174  DAEstatus status;
1175  ISISinstrumentControl* the_icp = g_icp_singleton.get();
1176  if (the_icp == NULL)
1177  {
1178  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
1179  return makeResult(status, messages);
1180  }
1181  ICPCritical cs(m_critical);
1182  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
1184  *state = the_icp->getRunState();
1185  the_icp->unregisterStructuredExceptionHandler(old_se_func);
1186  return makeResult(status, messages);
1187 }
1188 
1189 STDMETHODIMP Cdae::beginRunEx(LONG options, LONG period, BSTR* messages)
1190 {
1191  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::beginRunEx, _1, ((options & 0x1) != 0), ((options & 0x2) != 0), period - 1, _2));
1192 }
1193 
1194 STDMETHODIMP Cdae::fillWithTestPattern(ULONG pattern, BSTR* messages)
1195 {
1196  DAEstatus status;
1197  ISISinstrumentControl* the_icp = g_icp_singleton.get();
1198  if (the_icp == NULL)
1199  {
1200  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
1201  }
1202  else
1203  {
1204  ICPCritical cs(m_critical);
1205  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
1207  the_icp->fillWithTestPattern(pattern, status);
1208  the_icp->unregisterStructuredExceptionHandler(old_se_func);
1209  }
1210  return makeResult(status, messages);
1211 }
1212 
1213 STDMETHODIMP Cdae::getVetoStatus(BSTR* veto_status, BSTR* messages)
1214 {
1215  DAEstatus status;
1216  time_t timer;
1217  std::string veto_text1, veto_text2;
1218  char time_stamp[128];
1219  *veto_status = NULL;
1220  HRESULT hr = callICP<int>(messages, boost::bind(&ISISinstrumentControl::getVetoStatus, _1, boost::ref(veto_text1), _2));
1221  if (SUCCEEDED(hr))
1222  {
1223  hr = callICP<int>(messages, boost::bind(&ISISinstrumentControl::whichVeto, _1, boost::ref(veto_text2), _2));
1224  }
1225  time(&timer);
1226  strftime(time_stamp, sizeof(time_stamp), "Last Updated: %H:%M:%S", localtime(&timer));
1227  *veto_status = makeBSTR((veto_text1 + "\n" + veto_text2 + "\n" + time_stamp).c_str());
1228  return hr;
1229 }
1230 
1231 STDMETHODIMP Cdae::loadDAEWithData(BSTR file_name, LONG options, BSTR* messages)
1232 {
1233  std::string fname;
1234  getBSTRValue(file_name, fname);
1235  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::loadDAEWithData, _1, boost::cref(fname), options, _2));
1236 }
1237 
1238 STDMETHODIMP Cdae::setVeto(BSTR name, LONG enable, BSTR* messages)
1239 {
1240  std::string veto_name;
1241  getBSTRValue(name, veto_name);
1242  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::setVeto, _1, boost::cref(veto_name), enable, _2));
1243 }
1244 
1245 STDMETHODIMP Cdae::checkTestPattern(ULONG pattern, BSTR* messages)
1246 {
1247  DAEstatus status;
1248  ISISinstrumentControl* the_icp = g_icp_singleton.get();
1249  if (the_icp == NULL)
1250  {
1251  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
1252  }
1253  else
1254  {
1255  ICPCritical cs(m_critical);
1256  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
1258  the_icp->checkTestPattern(pattern, status);
1259  the_icp->unregisterStructuredExceptionHandler(old_se_func);
1260  }
1261  return makeResult(status, messages);
1262 }
1263 
1264 STDMETHODIMP Cdae::getRunNumber(BSTR* messages, LONG* run_number)
1265 {
1266  DAEstatus status;
1267  ISISinstrumentControl* the_icp = g_icp_singleton.get();
1268  if (the_icp == NULL)
1269  {
1270  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
1271  return makeResult(status, messages);
1272  }
1273  ICPCritical cs(m_critical);
1274  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
1276  *run_number = the_icp->getRunNumber();
1277  the_icp->unregisterStructuredExceptionHandler(old_se_func);
1278  return makeResult(status, messages);
1279 }
1280 
1281 STDMETHODIMP Cdae::changeMonitoringSettings(BSTR monitor_xml, BSTR* messages)
1282 {
1283  return updateSettings(monitor_xml, messages, &ISISinstrumentControl::updateMonitoringXML);
1284 }
1285 
1286 STDMETHODIMP Cdae::getMonitoringSettings(BSTR monitor_xml_in, BSTR* monitor_xml_out, BSTR* messages)
1287 {
1288  return getSettings(monitor_xml_in, monitor_xml_out, messages, &ISISinstrumentControl::getMonitoringXML);
1289 }
1290 
1291 
1293 {
1294  int i;
1295  int n;
1297  report_struct() : i(0), n(0), messages_bstr(NULL) {}
1298  report_struct(BSTR* messages, int _n) : i(0), n(_n), messages_bstr(messages) {}
1299 };
1300 
1301 static int status_reporter(const DAEstatus_message& mess, void* arg)
1302 {
1303  report_struct* rs = (report_struct*)arg;
1304  if (rs->i < rs->n)
1305  {
1306  rs->messages_bstr[rs->i] = Cdae::makeBSTR(mess.str().c_str());
1307  ++(rs->i);
1308  }
1309  return 0;
1310 }
1311 
1312 STDMETHODIMP Cdae::getStatusMessages(LONG stream, VARIANT* messages)
1313 {
1314  VariantInit(messages);
1315  ISISinstrumentControl* the_icp = g_icp_singleton.get();
1316  if (the_icp == NULL)
1317  {
1318  return S_OK;
1319  }
1320  int dims_array[1] = { 0 };
1321  if (g_status.size() == 0)
1322  {
1323  allocateArrayVariant(messages, VT_BSTR, dims_array, 1);
1324  return S_OK;
1325  }
1326  ICPCritical cs(m_critical);
1327  dims_array[0] = g_status.size(); // need to get this after ICPcritical created to be sure of correct value
1328  allocateArrayVariant(messages, VT_BSTR, dims_array, 1);
1329  BSTR* messages_bstr = NULL;
1330  accessArrayVariant(messages, &messages_bstr);
1331  report_struct rs(messages_bstr, dims_array[0]);
1332  bool stat_ok = g_status.OK(); // make note as reportAll() will clear this
1333  g_status.reportAll(status_reporter, &rs);
1334  unaccessArrayVariant(messages);
1335  if (stat_ok)
1336  {
1337  return S_OK;
1338  }
1339  else
1340  {
1341 // status.report(error_stream, SEV_ERROR, SEV_GE);
1342 // error_string = error_stream.str();
1343 // return AtlReportError(GetObjectCLSID(), error_string.c_str(), __uuidof(Idae));
1344  return S_OK;
1345  }
1346 }
1347 
1348 
1349 STDMETHODIMP Cdae::getGoodFramesPeriod(BSTR* messages, LONG* value)
1350 {
1351  return callICP<LONG>(messages, *value, boost::bind(&ISISinstrumentControl::getCurrentPeriodGoodFrames, _1, _2));
1352 }
1353 
1354 STDMETHODIMP Cdae::getGoodUAmpHPeriod(BSTR* messages, DOUBLE* value)
1355 {
1356  return callICP<DOUBLE>(messages, *value, boost::bind(&ISISinstrumentControl::getCurrentPeriodGoodUAmpH, _1, _2));
1357 }
1358 
1359 STDMETHODIMP Cdae::getFramesAllPeriods(VARIANT* good_frames, VARIANT* raw_frames, BSTR* messages)
1360 {
1361  int nper = 1;
1362  HRESULT hr = callICP<int>(messages, nper, boost::bind(&ISISinstrumentControl::getNumberOfPeriods, _1, _2));
1363  if (FAILED(hr))
1364  {
1365  return hr;
1366  }
1367  int dims_array[1] = { nper };
1368  allocateArrayVariant(good_frames, VT_I4, dims_array, 1);
1369  allocateArrayVariant(raw_frames, VT_I4, dims_array, 1);
1370  long* good = NULL;
1371  long* raw = NULL;
1372  accessArrayVariant(good_frames, &good);
1373  accessArrayVariant(raw_frames, &raw);
1374  hr = callICP<int>(messages, boost::bind(&ISISinstrumentControl::getFramesAllPeriods, _1, good, raw, nper, _2));
1375  unaccessArrayVariant(good_frames);
1376  unaccessArrayVariant(raw_frames);
1377  return hr;
1378 }
1379 
1380 STDMETHODIMP Cdae::getUAmpHAllPeriods(VARIANT* good_uamph, VARIANT* raw_uamph, BSTR* messages)
1381 {
1382  int nper = 1;
1383  HRESULT hr = callICP<int>(messages, nper, boost::bind(&ISISinstrumentControl::getNumberOfPeriods, _1, _2));
1384  if (FAILED(hr))
1385  {
1386  return hr;
1387  }
1388  int dims_array[1] = { nper };
1389  allocateArrayVariant(good_uamph, VT_R4, dims_array, 1);
1390  allocateArrayVariant(raw_uamph, VT_R4, dims_array, 1);
1391  float* good = NULL;
1392  float* raw = NULL;
1393  accessArrayVariant(good_uamph, &good);
1394  accessArrayVariant(raw_uamph, &raw);
1395  hr = callICP<int>(messages, boost::bind(&ISISinstrumentControl::getUAmpHAllPeriods, _1, good, raw, nper, _2));
1396  unaccessArrayVariant(good_uamph);
1397  unaccessArrayVariant(raw_uamph);
1398  return hr;
1399 }
1400 
1402 {
1403  // ISISinstrumentControl* the_icp = g_icp_singleton.get(); // not sure we want to do this from FinalConstruct() - may delay DCOM registration?
1404  // m_connection.push_back(the_icp->registerOnRunStateChange(boost::bind(&Cdae::Fire_OnRunStateChange, this, _1)));
1405 }
1406 
1408 {
1409 // BOOST_FOREACH(boost::signals2::connection conn, m_connection)
1410 // {
1411 // conn.disconnect();
1412 // }
1413 // m_connection.clear();
1414 }
1415 
1416 CRITICAL_SECTION* Cdae::m_critical = NULL;
1417 
1418 
1419 
1420 STDMETHODIMP Cdae::updateCRPTSpectra(LONG period, LONG spec_start, LONG nspec, BSTR* messages)
1421 {
1422  return callICP<int>(messages, boost::bind(static_cast<int(ISISinstrumentControl::*)(int,long,int,DAEstatus&)>(&ISISinstrumentControl::updateCRPTSpectra), _1, period - 1, spec_start, nspec, _2));
1423 }
1424 
1425 STDMETHODIMP Cdae::getCRPTSpectraIntegral(VARIANT spectrum_numbers, LONG period, VARIANT time_low, VARIANT time_high, VARIANT* counts, BSTR* messages)
1426 {
1427  return getSpectraIntegralHelper(&ISISinstrumentControl::getCRPTSpectrumIntegral, spectrum_numbers, period, time_low, time_high, counts, messages);
1428 }
1429 
1430 
1431 STDMETHODIMP Cdae::quit(BSTR* messages)
1432 {
1433  DAEstatus status;
1434  ISISinstrumentControl* the_icp = g_icp_singleton.get();
1435  if (the_icp == NULL)
1436  {
1437  status.add(FAC_DAE, SEV_ERROR, ERRTYPE_OUTOFMEM, "ICP is NULL");
1438  return makeResult(status, messages);
1439  }
1440  ICPCritical cs(m_critical);
1441  _se_translator_function old_se_func = the_icp->registerStructuredExceptionHandler();
1443  the_icp->exitProgram("", false);
1444  the_icp->unregisterStructuredExceptionHandler(old_se_func);
1445  return makeResult(status, messages);
1446 }
1447 
1448 
1450 {
1451  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::requestEndRunAfterNextSequenceCompletes, _1, _2));
1452 }
1453 
1454 
1455 STDMETHODIMP Cdae::isFinalSequenceComplete(BSTR* messages, LONG* complete)
1456 {
1457  bool is_complete = false;
1458  HRESULT hr = callICP<bool>(messages, is_complete, boost::bind(&ISISinstrumentControl::isFinalSequenceComplete, _1, _2));
1459  *complete = (is_complete ? 1 : 0);
1460  return hr;
1461 }
1462 
1463 
1464 STDMETHODIMP Cdae::getSpectrumNumbersForTR(LONG time_regime, LONG* spec_min, LONG* spec_max, BSTR* messages)
1465 {
1466  return callICP<int>(messages, boost::bind(&ISISinstrumentControl::getSpectrumNumbersForTimeRegime, _1, time_regime, boost::ref(*spec_min), boost::ref(*spec_max), _2));
1467 }
1468 
1469 
1470 STDMETHODIMP Cdae::getNumberOfPeriods(BSTR* messages, LONG* nperiod)
1471 {
1472  return callICP<LONG>(messages, *nperiod, boost::bind(&ISISinstrumentControl::getNumberOfPeriods, _1, _2));
1473 }
1474 
1475 
1476 STDMETHODIMP Cdae::updateStatusXML2(BSTR status_xml_in, BSTR* status_xml_out, BSTR* messages)
1477 {
1478  *status_xml_out = CComBSTR(status_xml_in).Detach();
1479  return updateStatusXML(status_xml_out, messages);
1480 }
HRESULT storeCRPT(BSTR *messages)
Definition: dae.cpp:982
int VMEReadValue(unsigned long card_id, unsigned long card_address, bool sixteen_bit, unsigned long *value, DAEstatus &status)
#define NULL_TERMINATE(__array)
null terminate a char[n] static array
Definition: isiscrpt.h:74
int setSampleParameters(const string_table_t &table, DAEstatus &status)
HRESULT changePeriodWhileRunning(LONG period, LONG pause_first, BSTR *messages)
Definition: dae.cpp:1119
HRESULT sumAllSpectra(LONG *counts, LONG *bin0_counts, BSTR *messages)
Definition: dae.cpp:819
HRESULT changePeriod(LONG period_number, BSTR *messages)
Definition: dae.cpp:760
HRESULT getGoodUAmpHPeriod(BSTR *messages, DOUBLE *value)
Definition: dae.cpp:1354
HRESULT changeMonitoringSettings(BSTR monitor_xml, BSTR *messages)
Definition: dae.cpp:1281
int refreshCachedValues(DAEstatus &status)
#define FAC_DAE
int allocateArrayVariant(VARIANT *v, VARTYPE v_type, int *dims_array, int ndims)
report_struct(BSTR *messages, int _n)
Definition: dae.cpp:1298
#define ERRTYPE_OUTOFMEM
HRESULT checkTestPattern(ULONG pattern, BSTR *messages)
Definition: dae.cpp:1245
int getMEvents(double &mevents, DAEstatus &status)
int getNumberOfSpectra(DAEstatus &status)
HRESULT getGoodFramesPeriod(BSTR *messages, LONG *value)
Definition: dae.cpp:1349
int getHardwarePeriodsXML(const std::string &periods_xml_in, std::string &periods_xml_out, DAEstatus &status)
HRESULT startSEWait(BSTR *messages)
Definition: dae.cpp:274
float getGoodUAmpH(DAEstatus &status)
int getIntArrayItemSize(const char *item_name, int *dims_array, int &ndims, DAEstatus &status)
int getRealItem(const char *item_name, double &dblVal, DAEstatus &status)
int getValueMain(ISISinstrumentControl *the_icp, const char *item_name, VARIANT *result, DAEstatus &status)
Definition: dae.cpp:590
HRESULT getTotalCounts(BSTR *messages, LONG *counts)
Definition: dae.cpp:1077
int addVa(int facility, int severity, int errtype, const char *format,...)
Definition: DAEstatus.cpp:54
static DAEstatus g_status
Definition: dae.cpp:11
#define SEV_WARNING
int RIO(isis32_t bus_addr, isisU16_t &word, DAEstatus &status)
int getNumberOfPeriods(DAEstatus &status)
static Poco::SingletonHolder< InstrumentControlHolder > g_icp_singleton
Definition: dae.cpp:9
HRESULT changeUpdateSettings(BSTR update_xml, BSTR *messages)
Definition: dae.cpp:1065
void registerICPCallbacks()
Definition: dae.cpp:1401
HRESULT setOptions(BSTR options_xml, BSTR *messages)
Definition: dae.cpp:925
std::ostream & printStatus(std::ostream &os, DAEstatus &dstatus)
HRESULT endRun(BSTR *messages)
Definition: dae.cpp:249
HRESULT setBeamlineParameters(VARIANT table, BSTR *messages)
Definition: dae.cpp:1036
HRESULT getMEventsPeriod(LONG period, BSTR *messages, DOUBLE *mevents)
Definition: dae.cpp:1097
int report(int severity, int direction, bool reset_overall_severity=true, bool remove_messages=true)
Definition: DAEstatus.cpp:224
HRESULT VMEWriteArray(ULONG card_id, ULONG card_address, VARIANT values, BSTR *messages)
Definition: dae.cpp:878
int getRealArrayItem(const char *item_name, double *darray, DAEstatus &status)
int storeCRPT(DAEstatus &status)
int updateUserXML(const std::string &user_xml, DAEstatus &status)
HRESULT getArrayValue(BSTR name, VARIANT arg, BSTR *messages, VARIANT *result)
Definition: dae.cpp:945
HRESULT isFinalSequenceComplete(BSTR *messages, LONG *complete)
Definition: dae.cpp:1455
int endSEWait(DAEstatus &dstatus)
int beginRunEx(bool start_paused, bool delayed_start, long period, DAEstatus &status)
#define SEV_LE
int setRunStatus(long number, DAEstatus &status)
int updateMonitoringXML(const std::string &monitor_xml, DAEstatus &status)
HRESULT getCRPTSpectraIntegral(VARIANT spectrum_numbers, LONG period, VARIANT time_low, VARIANT time_high, VARIANT *counts, BSTR *messages)
Definition: dae.cpp:1425
HRESULT getValue(BSTR name, BSTR *messages, VARIANT *result)
Definition: dae.cpp:478
HRESULT getGoodUAmpH(BSTR *messages, DOUBLE *value)
Definition: dae.cpp:678
int getCurrentPeriodGoodFrames(DAEstatus &status)
int whichVeto(std::string &veto_text, DAEstatus &status)
unsigned long isisU32_t
Definition: isisvme_types.h:8
HRESULT getSpectraSum(LONG period, LONG first_spec, LONG num_spec, LONG spec_type, DOUBLE time_low, DOUBLE time_high, VARIANT *sums, VARIANT *max_vals, VARIANT *spec_nums, BSTR *messages)
Definition: dae.cpp:683
HRESULT getNumberOfPeriods(BSTR *messages, LONG *nperiod)
Definition: dae.cpp:1470
int sumAllSpectra(long &counts, long &bin0_counts, DAEstatus &status)
HRESULT dumpDebugInfo(BSTR *messages)
Definition: dae.cpp:765
int add(DAEstatus &dstatus, bool clear)
Definition: DAEstatus.cpp:131
int getCurrentPeriodNumber(int &period, int &daq_period, DAEstatus &status)
int changePeriod(int period, DAEstatus &status)
int setBeamlineParameters(const string_table_t &table, DAEstatus &status)
int fillWithTestPattern(unsigned long pattern, DAEstatus &status)
std::vector< std::vector< std::string > > string_table_t
HRESULT abortRun(BSTR *messages)
Definition: dae.cpp:269
int getOptions(std::string &options_xml, DAEstatus &status)
int getDAEsettingsXML(const std::string &dae_xml_in, std::string &dae_xml_out, DAEstatus &status)
HRESULT changeHardwarePeriods(BSTR periods_xml, BSTR *messages)
Definition: dae.cpp:753
static const int Success
Definition: DAEstatus.h:140
int getGoodFrames(DAEstatus &status)
bool isFinalSequenceComplete(DAEstatus &status)
HRESULT requestEndRunAfterNextSequenceCompletes(BSTR *messages)
Definition: dae.cpp:1449
HRESULT quit(BSTR *messages)
Definition: dae.cpp:1431
HRESULT getVetoStatus(BSTR *veto_status, BSTR *messages)
Definition: dae.cpp:1213
HRESULT makeResult(DAEstatus &status, BSTR *messages, bool force_success_result=false)
Definition: dae.cpp:205
HRESULT getMonitoringSettings(BSTR monitor_xml_in, BSTR *monitor_xml_out, BSTR *messages)
Definition: dae.cpp:1286
int setRunNumber(long number, DAEstatus &status)
int notifyICP(long event_id, const char *param, DAEstatus &status)
HRESULT VMEWriteValue(ULONG card_id, ULONG card_address, ULONG word_size, ULONG value, ULONG mode, BSTR *messages)
Definition: dae.cpp:783
std::string str() const
Definition: DAEstatus.h:82
int getSpectrumIntegral(long spec_no, long period, float t_low, float t_high, long &integral, long &max_val, DAEstatus &status)
HRESULT VMEReadArray(ULONG card_id, ULONG card_address, VARIANT *values, ULONG num_values, BSTR *messages)
Definition: dae.cpp:854
HRESULT VMEReadValuesToString(ULONG card_id, ULONG card_address, ULONG word_size, ULONG num_values, BSTR *values, BSTR *messages)
Definition: dae.cpp:899
HRESULT getSpectrum(LONG spectrum_number, LONG period, VARIANT *time_channels, VARIANT *signal, LONG as_histogram, LONG as_distribution, LONG *sum, BSTR *messages)
Definition: dae.cpp:284
int reallocBSTR(BSTR *bstr, const char *str)
Definition: dae.cpp:184
int getFramesAllPeriods(long *good_frames, long *raw_frames, int n, DAEstatus &status)
int updateCRPTSpectra(int period, long spec_start, int nspectra, DAEstatus &status)
int VMEReadValuesToString(unsigned long card_id, unsigned long card_address, bool sixteen_bit, unsigned long num_values, std::string &values, DAEstatus &status)
HRESULT setVeto(BSTR name, LONG enable, BSTR *messages)
Definition: dae.cpp:1238
int setReportCopyFunction(DAEreport_func_t *report_func, void *arg)
Definition: DAEstatus.h:185
int VMEWriteValue(unsigned long card_id, unsigned long card_address, bool sixteen_bit, unsigned long value, unsigned long mode, DAEstatus &status)
HRESULT setSampleParameters(VARIANT table, BSTR *messages)
Definition: dae.cpp:1029
int getCRPTSpectrumIntegral(long spec_no, long period, float t_low, float t_high, long &integral, long &max_val, DAEstatus &status)
void unregisterStructuredExceptionHandler(_se_translator_function old_func)
int exitProgram(const std::string &message, bool prompt)
HRESULT updateStatusXML2(BSTR status_xml_in, BSTR *status_xml_out, BSTR *messages)
Definition: dae.cpp:1476
int saveRun(DAEstatus &status)
int VMEReadArray(unsigned long card_id, unsigned long card_address, isisU32_t *values, unsigned long num_values, DAEstatus &status)
int beginRun(DAEstatus &status)
int reportAll(bool reset_overall_severity=true, bool remove_messages=true)
Definition: DAEstatus.h:169
_se_translator_function registerStructuredExceptionHandler()
this needs to be called per thread
HRESULT notifyICP(LONG event_id, BSTR param, BSTR *messages)
Definition: dae.cpp:1015
#define SEV_ERROR
int updateCRPTWithDAE(CRPTProxy &crpt, bool pause_collection, DAEstatus &status)
int getSpectrumNumbersForTimeRegime(long tr, long &spec_min, long &spec_max, DAEstatus &status)
static int getXML(const BSTR xml_in, std::string &xml_out)
Definition: dae.cpp:91
HRESULT areYouThere(void)
Definition: dae.cpp:1050
bool OK()
Definition: DAEstatus.h:143
int getNumberOfTimeChannels(int spectrum, DAEstatus &status)
static int allReportFunc(const DAEstatus_message &mess, void *arg)
int getVetoStatus(std::string &veto_text, DAEstatus &status)
static CRITICAL_SECTION * m_critical
Definition: dae.h:74
int pauseRun(DAEstatus &status)
HRESULT getSpectraIntegral2(LONG spec_start, LONG nspectra, LONG period, FLOAT time_low, FLOAT time_high, VARIANT *counts, BSTR *messages)
Definition: dae.cpp:399
HRESULT getStatusMessages(LONG stream, VARIANT *messages)
Definition: dae.cpp:1312
HRESULT getGoodFramesTotal(BSTR *messages, LONG *value)
Definition: dae.cpp:673
HRESULT getTCB(BSTR tcb_xml_in, BSTR *tcb_xml_out, BSTR *messages)
Definition: dae.cpp:1157
int getTCBXML(const std::string &tcb_xml_in, std::string &tcb_xml_out, DAEstatus &status)
HRESULT updateStatusXML(BSTR *cluster_xml, BSTR *messages)
Definition: dae.cpp:147
HRESULT refreshCachedValues(BSTR *messages)
Definition: dae.cpp:920
HRESULT getNPRatio(FLOAT *current, FLOAT *average, BSTR *messages)
Definition: dae.cpp:1072
HRESULT getRunNumber(BSTR *messages, LONG *run_number)
Definition: dae.cpp:1264
HRESULT VMEReadValue(ULONG card_id, ULONG card_address, ULONG word_size, ULONG *value, BSTR *messages)
Definition: dae.cpp:801
unsigned short isisU16_t
Definition: isisvme_types.h:7
int getRawFrames(DAEstatus &status)
int loadDAEWithData(const std::string &file_name, long options, DAEstatus &status)
HRESULT getSpectraIntegral(VARIANT spectrum_numbers, LONG period, VARIANT time_low, VARIANT time_high, VARIANT *counts, BSTR *messages)
Definition: dae.cpp:394
HRESULT updateCRPT(BSTR *messages)
Definition: dae.cpp:977
int updateDAEsettingsXML(const std::string &status_xml, DAEstatus &status)
HRESULT changeSample(BSTR sample_xml, BSTR *messages)
Definition: dae.cpp:739
int updateSampleXML(const std::string &sample_xml, DAEstatus &status)
HRESULT endSEWait(BSTR *messages)
Definition: dae.cpp:279
int startSEWait(DAEstatus &dstatus)
int getIntItem(const char *item_name, long &lVal, DAEstatus &status)
HRESULT changeDAEsettings(BSTR dae_xml, BSTR *messages)
Definition: dae.cpp:334
HRESULT getUAmpHAllPeriods(VARIANT *good_uamph, VARIANT *raw_uamph, BSTR *messages)
Definition: dae.cpp:1380
HRESULT setUserParameters(LONG rbno, VARIANT table, BSTR *messages)
Definition: dae.cpp:1043
int changeNumberOfSoftwarePeriods(long nperiod, DAEstatus &status)
HRESULT callICP(BSTR *messages, T &result, boost::function< T(ISISinstrumentControl *, DAEstatus &)> func)
Definition: dae.cpp:49
int requestEndRunAfterNextSequenceCompletes(DAEstatus &status)
HRESULT getUpdateSettings(BSTR update_xml_in, BSTR *update_xml_out, BSTR *messages)
Definition: dae.cpp:1162
void unregisterICPCallbacks()
Definition: dae.cpp:1407
int snapshotCRPT(const char *filename, bool do_update, bool do_pause, DAEstatus &status)
static int variantToStringTable(VARIANT *v, string_table_t &string_table)
Definition: dae.cpp:121
HRESULT sumAllHistogramMemory(LONG *counts, BSTR *messages)
Definition: dae.cpp:837
HRESULT updateCRPTSpectra(LONG period, LONG spec_start, LONG nspec, BSTR *messages)
Definition: dae.cpp:1420
HRESULT getSpectrumIntegral(LONG spectrum_number, LONG period, FLOAT time_low, FLOAT time_high, LONG *counts, BSTR *messages)
Definition: dae.cpp:341
HRESULT fillWithTestPattern(ULONG pattern, BSTR *messages)
Definition: dae.cpp:1194
HRESULT loadDAEWithData(BSTR file_name, LONG options, BSTR *messages)
Definition: dae.cpp:1231
static void getBSTRValue(const BSTR bstr, std::string &str)
Definition: dae.cpp:111
int endRun(DAEstatus &status)
int getUAmpHAllPeriods(float *good_uamph, float *raw_uamph, int n, DAEstatus &status)
HRESULT getDAEsettings(BSTR dae_xml_in, BSTR *dae_xml_out, BSTR *messages)
Definition: dae.cpp:1147
HRESULT getSpectraIntegralHelper(spec_int_func_t func, VARIANT spectrum_numbers, LONG period, VARIANT time_low, VARIANT time_high, VARIANT *counts, BSTR *messages)
Definition: dae.cpp:360
HRESULT updateSettings(BSTR xml_in, BSTR *messages, xml_set_func_t func)
Definition: dae.cpp:1139
HRESULT InterfaceSupportsErrorInfo(REFIID riid)
Definition: dae.cpp:15
int severity()
Definition: DAEstatus.h:142
float getCurrentPeriodGoodUAmpH(DAEstatus &status)
static int accessArrayVariant(VARIANT *v, void **values, VARTYPE vt)
HRESULT rio(LONG address, LONG *value, BSTR *messages)
Definition: dae.cpp:457
HRESULT setICPValueLong(BSTR name, LONG value, BSTR *messages)
Definition: dae.cpp:987
BSTR * messages_bstr
Definition: dae.cpp:1296
int getMEventsPeriod(double &mevents, int period, DAEstatus &status)
int VMEWriteArray(unsigned long card_id, unsigned long card_address, isisU32_t *values, unsigned long num_values, DAEstatus &status)
report_struct()
Definition: dae.cpp:1297
HRESULT getHardwarePeriods(BSTR periods_xml_in, BSTR *periods_xml_out, BSTR *messages)
Definition: dae.cpp:1152
HRESULT getOptions(BSTR *options_xml, BSTR *messages)
Definition: dae.cpp:932
HRESULT resumeRun(BSTR *messages)
Definition: dae.cpp:259
static int status_reporter(const DAEstatus_message &mess, void *arg)
Definition: dae.cpp:1301
HRESULT saveRun(BSTR *messages)
Definition: dae.cpp:264
HRESULT getMEvents(BSTR *messages, DOUBLE *mevents)
Definition: dae.cpp:1092
int changePeriodWhileRunning(int period, bool pause_first, DAEstatus &status)
int updateHardwarePeriodsXML(const std::string &periods_xml, DAEstatus &status)
HRESULT getRawFramesTotal(BSTR *messages, LONG *value)
Definition: dae.cpp:668
HRESULT changeNumberOfSoftwarePeriods(LONG nperiod, BSTR *messages)
Definition: dae.cpp:1167
int changeUpdateSettingsXML(const std::string &update_xml, DAEstatus &status)
HRESULT getSettings(BSTR xml_in, BSTR *xml_out, BSTR *messages, xml_get_func_t func)
Definition: dae.cpp:1124
HRESULT getsect(LONG start, LONG length, VARIANT *values, BSTR *messages)
Definition: dae.cpp:433
int getNPRatio(float *current, float *average, DAEstatus &status)
int arrayVariantLength(VARIANT *v)
int addInfo(int facility, const std::string &text)
Definition: DAEstatus.cpp:86
int abortRun(DAEstatus &status)
static BSTR makeBSTR(const char *str)
Definition: dae.cpp:163
HRESULT getFramesAllPeriods(VARIANT *good_frames, VARIANT *raw_frames, BSTR *messages)
Definition: dae.cpp:1359
HRESULT setBlocksTable(VARIANT table, BSTR *messages)
Definition: dae.cpp:1022
int setOptions(const std::string &options_xml, DAEstatus &status)
HRESULT beginRun(BSTR *messages)
Definition: dae.cpp:244
int setBlockTable(const string_table_t &table, DAEstatus &status)
#define SEV_GE
int getRealArrayItemSize(const char *item_name, int *dims_array, int &ndims, DAEstatus &status)
HRESULT pauseRun(BSTR *messages)
Definition: dae.cpp:254
int setUserParameters(long rbno, const string_table_t &table, DAEstatus &status)
int checkTestPattern(unsigned long pattern, DAEstatus &status)
HRESULT snapshotCRPT(BSTR filename, LONG do_update, LONG do_pause, BSTR *messages)
Definition: dae.cpp:1111
int arrayVariantDimensions(VARIANT *v, int dims_array[], int &ndims)
HRESULT beginRunEx(LONG options, LONG period, BSTR *messages)
Definition: dae.cpp:1189
HRESULT changeUser(BSTR user_xml, BSTR *messages)
Definition: dae.cpp:746
int sumAllHistogramMemory(long &counts, DAEstatus &status)
int updateTCBXML(const std::string &status_xml, DAEstatus &status)
int getSpectrum(long spectrum_number, long period, double *time_array, double *signal_array, double *error_array, bool as_histogram, bool as_distribution, long &sum, DAEstatus &status)
HRESULT getSpectrumNumbersForTR(LONG time_regime, LONG *spec_min, LONG *spec_max, BSTR *messages)
Definition: dae.cpp:1464
int getUpdateSettingsXML(const std::string &update_xml_in, std::string &update_xml_out, DAEstatus &status)
int getArrayValueMain(ISISinstrumentControl *the_icp, const char *item_name, long args[], int nargs, VARIANT *result, DAEstatus &status)
Definition: dae.cpp:503
int setVeto(const std::string &name, long enable, DAEstatus &status)
int unaccessArrayVariant(VARIANT *v)
int getCharItem(const char *item_name, std::string &cvalue, DAEstatus &status)
HRESULT reportError(T *obj, const std::string &errmsg)
Definition: instapi_utils.h:9
HRESULT changeTCB(BSTR tcb_xml, BSTR *messages)
Definition: dae.cpp:327
HRESULT getRunState(BSTR *messages, LONG *state)
Definition: dae.cpp:1172
HRESULT getCurrentPeriodNumber(LONG *period, LONG *daq_period, BSTR *messages)
Definition: dae.cpp:1102
int getMonitoringXML(const std::string &monitor_xml_in, std::string &monitor_xml_out, DAEstatus &status)
int updateStatusXML(std::string &status_xml, DAEstatus &status)
int getTotalCounts(int64_t &counts, DAEstatus &status)
int getIntArrayItem(const char *item_name, long *larray, DAEstatus &status)
int size()
Definition: DAEstatus.h:145
int resumeRun(DAEstatus &status)