ICP  1
selog.cpp
Go to the documentation of this file.
1 // selog.cpp : Implementation of Cselog
2 
3 #include "stdafx.h"
4 #include "selog.h"
5 #include "..\selogger\selogger.h"
6 
7 
8 // Cselog
9 
10 STDMETHODIMP Cselog::InterfaceSupportsErrorInfo(REFIID riid)
11 {
12  static const IID* arr[] =
13  {
14  &IID_Iselog
15  };
16 
17  for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
18  {
19  if (InlineIsEqualGUID(*arr[i],riid))
20  return S_OK;
21  }
22  return S_FALSE;
23 }
24 
25 STDMETHODIMP Cselog::SELogValue(LONG run_number, BSTR source, BSTR iso_time, BSTR block_name, BSTR block_value)
26 {
27  AFX_MANAGE_STATE(AfxGetStaticModuleState());
28  COLE2CT c_source(source), c_iso_time(iso_time), c_block_name(block_name), c_block_value(block_value);
29  if (se_log_value(run_number, c_source, c_iso_time, c_block_name, c_block_value) == 0)
30  {
31  return S_OK;
32  }
33  else
34  {
35  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
36  }
37 }
38 
39 STDMETHODIMP Cselog::SEClose(void)
40 {
41  AFX_MANAGE_STATE(AfxGetStaticModuleState());
42  if (se_close() == 0)
43  {
44  return S_OK;
45  }
46  else
47  {
48  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
49  }
50 }
51 
52 STDMETHODIMP Cselog::SENewSECIConfig(BSTR config_name)
53 {
54  AFX_MANAGE_STATE(AfxGetStaticModuleState());
55  COLE2CT config_name_c(config_name);
56  if (se_new_seci_config(config_name_c) == 0)
57  {
58  return S_OK;
59  }
60  else
61  {
62  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
63  }
64 }
65 
66 STDMETHODIMP Cselog::SESetBlockValue(BSTR block_name, BSTR block_value)
67 {
68  AFX_MANAGE_STATE(AfxGetStaticModuleState());
69  COLE2CT block_name_c(block_name), block_value_c(block_value);
70  if (se_set_block_value(block_name_c, block_value_c) == 0)
71  {
72  return S_OK;
73  }
74  else
75  {
76  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
77  }
78 }
79 
80 STDMETHODIMP Cselog::SESetBlockDetails(BSTR block_name, BSTR setpoint_value, BSTR vi_name,
81  BSTR read_control_label, BSTR set_control_label,
82  BSTR button_control_label, LONG options, BSTR nexus_name,
83  FLOAT low_limit, FLOAT high_limit, BSTR units, BSTR current_value)
84 {
85  AFX_MANAGE_STATE(AfxGetStaticModuleState());
86  if (se_set_block_details(COLE2CT(block_name), COLE2CT(setpoint_value),
87  COLE2CT(vi_name), COLE2CT(read_control_label), COLE2CT(set_control_label),
88  COLE2CT(button_control_label), (BlockOptions)options, COLE2CT(nexus_name),
89  low_limit, high_limit, COLE2CT(units), COLE2CT(current_value)) == 0)
90  {
91  return S_OK;
92  }
93  else
94  {
95  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
96  }
97 }
98 
99 STDMETHODIMP Cselog::SENewMeasurement(BSTR label, BSTR* id)
100 {
101  AFX_MANAGE_STATE(AfxGetStaticModuleState());
102  std::string id_s;
103  *id = NULL;
104  if (se_new_measurement(COLE2CT(label), id_s) == 0)
105  {
106  CComBSTR bstr_wrapper(id_s.c_str());
107  *id = bstr_wrapper.Detach();
108  return S_OK;
109  }
110  else
111  {
112  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
113  }
114 }
115 
116 STDMETHODIMP Cselog::SEGetMeasurementLabel(BSTR id, BSTR* label)
117 {
118  AFX_MANAGE_STATE(AfxGetStaticModuleState());
119  std::string label_s;
120  *label = NULL;
121  if (se_get_measurement_label(COLE2CT(id), label_s) == 0)
122  {
123  CComBSTR bstr_wrapper(label_s.c_str());
124  *label = bstr_wrapper.Detach();
125  return S_OK;
126  }
127  else
128  {
129  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
130  }
131 }
132 
133 #include "variant_utils.h"
134 
135 static int build_string_vector(VARIANT& v, std::vector<std::string>& sv)
136 {
137  BSTR* bstr_values = NULL;
138  VARIANT* variant_values = NULL;
139  int n = arrayVariantLength(&v);
140 // we could get an array of BSTR or an array of variants
141  if (accessArrayVariant(&v, &bstr_values) != 0)
142  {
143  accessArrayVariant(&v, &variant_values);
144  }
145  // use resize() rather than reserve() so we get n blank items and [i] reference is valid
146  sv.resize(n);
147  for(int i=0; i<n; i++)
148  {
149  if (bstr_values != NULL)
150  {
151  sv[i] = COLE2CT(bstr_values[i]);
152  }
153  else if (variant_values != NULL)
154  {
155  sv[i] = COLE2CT(variant_values[i].bstrVal);
156  }
157  }
159  return 0;
160 }
161 
162 STDMETHODIMP Cselog::SESetBlockValues(VARIANT block_names, VARIANT block_values)
163 {
164  AFX_MANAGE_STATE(AfxGetStaticModuleState());
165  std::vector<std::string> names_list;
166  std::vector<std::string> values_list;
167  build_string_vector(block_names, names_list);
168  build_string_vector(block_values, values_list);
169  if (se_set_block_values(names_list, values_list) == 0)
170  {
171  return S_OK;
172  }
173  else
174  {
175  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
176  }
177 }
178 
179 STDMETHODIMP Cselog::SELogValues(LONG run_number, BSTR source, VARIANT iso_times, VARIANT block_names, VARIANT block_values)
180 {
181  AFX_MANAGE_STATE(AfxGetStaticModuleState());
182  std::vector<std::string> names_list;
183  std::vector<std::string> values_list;
184  std::vector<std::string> times_list;
185  build_string_vector(block_names, names_list);
186  build_string_vector(block_values, values_list);
187  build_string_vector(iso_times, times_list);
188  if (se_log_values(run_number, COLE2CT(source), times_list, names_list, values_list) == 0)
189  {
190  return S_OK;
191  }
192  else
193  {
194  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
195  }
196 }
197 
198 STDMETHODIMP Cselog::SEGetMeasurementID(BSTR label, BSTR* measurement_id)
199 {
200  AFX_MANAGE_STATE(AfxGetStaticModuleState());
201  std::string id_s;
202  *measurement_id = NULL;
203  if (se_get_measurement_id(COLE2CT(label), id_s) == 0)
204  {
205  CComBSTR bstr_wrapper(id_s.c_str());
206  *measurement_id = bstr_wrapper.Detach();
207  return S_OK;
208  }
209  else
210  {
211  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
212  }
213 }
214 
215 STDMETHODIMP Cselog::SESetMeasurementLabel(BSTR measurement_id, BSTR label)
216 {
217  AFX_MANAGE_STATE(AfxGetStaticModuleState());
218  if (se_set_measurement_label(COLE2CT(measurement_id), COLE2CT(label)) == 0)
219  {
220  return S_OK;
221  }
222  else
223  {
224  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
225  }
226  return S_OK;
227 }
228 
229 STDMETHODIMP Cselog::SESetBlockSetpoint(BSTR block_name, BSTR block_setpoint)
230 {
231  AFX_MANAGE_STATE(AfxGetStaticModuleState());
232  COLE2CT block_name_c(block_name), block_setpoint_c(block_setpoint);
233  if (se_set_block_setpoint(block_name_c, block_setpoint_c) == 0)
234  {
235  return S_OK;
236  }
237  else
238  {
239  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
240  }
241  return S_OK;
242 }
243 
244 
245 STDMETHODIMP Cselog::SESetBlockSetpoints(VARIANT block_names, VARIANT block_setpoints)
246 {
247  AFX_MANAGE_STATE(AfxGetStaticModuleState());
248  std::vector<std::string> names_list;
249  std::vector<std::string> setpoints_list;
250  build_string_vector(block_names, names_list);
251  build_string_vector(block_setpoints, setpoints_list);
252  if (se_set_block_setpoints(names_list, setpoints_list) == 0)
253  {
254  return S_OK;
255  }
256  else
257  {
258  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
259  }
260 }
261 
262 STDMETHODIMP Cselog::SEGetSECIConfig(BSTR* seci_config)
263 {
264  AFX_MANAGE_STATE(AfxGetStaticModuleState());
265  std::string seci_config_s;
266  *seci_config = NULL;
267  if (se_get_seci_config(seci_config_s) == 0)
268  {
269  CComBSTR bstr_wrapper(seci_config_s.c_str());
270  *seci_config = bstr_wrapper.Detach();
271  return S_OK;
272  }
273  else
274  {
275  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
276  }
277 }
278 
279 
280 STDMETHODIMP Cselog::SELogValuesAsync(LONG run_number, BSTR source, VARIANT iso_times, VARIANT block_names, VARIANT block_values)
281 {
282  AFX_MANAGE_STATE(AfxGetStaticModuleState());
283  std::vector<std::string> names_list;
284  std::vector<std::string> values_list;
285  std::vector<std::string> times_list;
286  build_string_vector(block_names, names_list);
287  build_string_vector(block_values, values_list);
288  build_string_vector(iso_times, times_list);
289  if (se_log_values_async(run_number, COLE2CT(source), times_list, names_list, values_list) == 0)
290  {
291  return S_OK;
292  }
293  else
294  {
295  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
296  }
297 }
298 
299 
300 STDMETHODIMP Cselog::SEGetValues(LONG run_number, BSTR source, BSTR block_name, VARIANT* iso_times, VARIANT* block_values)
301 {
302  AFX_MANAGE_STATE(AfxGetStaticModuleState());
303  std::vector<std::string> block_values_v;
304  std::vector<std::string> iso_times_v;
305  if (se_get_values(run_number, COLE2CT(source), COLE2CT(block_name), iso_times_v, block_values_v) != 0)
306  {
307  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
308  }
309  makeVariantFromArray(iso_times, iso_times_v);
310  makeVariantFromArray(block_values, block_values_v);
311  return S_OK;
312 }
313 
314 
315 STDMETHODIMP Cselog::SEClearLoggedValues(LONG run_number)
316 {
317  AFX_MANAGE_STATE(AfxGetStaticModuleState());
318  if (se_clear_values(run_number, run_number) != 0)
319  {
320  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
321  }
322  return S_OK;
323 }
324 
325 
326 STDMETHODIMP Cselog::SEExecSQL(BSTR sql, BSTR* result)
327 {
328  std::string result_s;
329  AFX_MANAGE_STATE(AfxGetStaticModuleState());
330  *result = NULL;
331  if (se_exec_sql(COLE2CT(sql), result_s) == 0)
332  {
333  CComBSTR bstr_wrapper(result_s.c_str());
334  *result = bstr_wrapper.Detach();
335  return S_OK;
336  }
337  else
338  {
339  return AtlReportError(GetObjectCLSID(), se_get_errmsg());
340  }
341 }
HRESULT SELogValues(LONG run_number, BSTR source, VARIANT iso_times, VARIANT block_names, VARIANT block_values)
Definition: selog.cpp:179
SELOGGER_API int __stdcall se_new_seci_config(const char *config_name)
Definition: selogger.cpp:764
HRESULT SESetBlockDetails(BSTR block_name, BSTR setpoint_value, BSTR vi_name, BSTR read_control_label, BSTR set_control_label, BSTR button_control_label, LONG options, BSTR nexus_name, FLOAT low_limit, FLOAT high_limit, BSTR units, BSTR current_value)
Definition: selog.cpp:80
SELOGGER_API int __stdcall se_new_measurement(const char *label, std::string &res)
Definition: selogger.cpp:872
SELOGGER_API int __stdcall se_get_measurement_id(const char *label, std::string &measurement_id)
Definition: selogger.cpp:947
HRESULT SEExecSQL(BSTR sql, BSTR *result)
Definition: selog.cpp:326
HRESULT SENewMeasurement(BSTR label, BSTR *id)
Definition: selog.cpp:99
static int build_string_vector(VARIANT &v, std::vector< std::string > &sv)
Definition: selog.cpp:135
HRESULT SELogValue(LONG run_number, BSTR source, BSTR iso_time, BSTR block_name, BSTR block_value)
Definition: selog.cpp:25
HRESULT SEGetSECIConfig(BSTR *seci_config)
Definition: selog.cpp:262
SELOGGER_API int __stdcall se_log_values(long run_number, const char *source, const std::vector< std::string > &iso_times, const std::vector< std::string > &block_names, const std::vector< std::string > &block_values)
Definition: selogger.cpp:589
HRESULT SESetBlockSetpoint(BSTR block_name, BSTR block_setpoint)
Definition: selog.cpp:229
SELOGGER_API const char *__stdcall se_get_errmsg()
Definition: selogger.cpp:696
HRESULT SESetMeasurementLabel(BSTR measurement_id, BSTR label)
Definition: selog.cpp:215
SELOGGER_API int __stdcall se_log_value(long run_number, const char *source, const char *iso_time, const char *block_name, const char *block_value)
Definition: selogger.cpp:525
SELOGGER_API int __stdcall se_get_measurement_label(const char *measurement_id, std::string &res)
Definition: selogger.cpp:905
HRESULT SEGetMeasurementID(BSTR label, BSTR *measurement_id)
Definition: selog.cpp:198
SELOGGER_API int __stdcall se_set_block_setpoints(const std::vector< std::string > &block_names, const std::vector< std::string > &block_setpoints)
Definition: selogger.cpp:1413
HRESULT SELogValuesAsync(LONG run_number, BSTR source, VARIANT iso_times, VARIANT block_names, VARIANT block_values)
Definition: selog.cpp:280
HRESULT SEGetMeasurementLabel(BSTR id, BSTR *label)
Definition: selog.cpp:116
BlockOptions
Definition: selogger.h:19
HRESULT InterfaceSupportsErrorInfo(REFIID riid)
Definition: selog.cpp:10
HRESULT SEClose(void)
Definition: selog.cpp:39
SELOGGER_API int __stdcall se_close()
Definition: selogger.cpp:691
SELOGGER_API int __stdcall se_get_values(long run_number, const char *source, const char *block_name, std::vector< std::string > &iso_times, std::vector< std::string > &block_values)
Definition: selogger.cpp:1446
SELOGGER_API int __stdcall se_get_seci_config(std::string &seci_config)
Definition: selogger.cpp:739
HRESULT SEGetValues(LONG run_number, BSTR source, BSTR block_name, VARIANT *iso_times, VARIANT *block_values)
Definition: selog.cpp:300
HRESULT SESetBlockValues(VARIANT block_names, VARIANT block_values)
Definition: selog.cpp:162
SELOGGER_API int __stdcall se_exec_sql(const char *sql, std::string &result)
Definition: selogger.cpp:1503
static int accessArrayVariant(VARIANT *v, void **values, VARTYPE vt)
SELOGGER_API int __stdcall se_set_block_setpoint(const char *block_name, const char *block_setpoint)
Definition: selogger.cpp:1404
SELOGGER_API int __stdcall se_clear_values(int run_start, int run_finish)
Definition: selogger.cpp:1040
HRESULT SESetBlockSetpoints(VARIANT block_names, VARIANT block_setpoints)
Definition: selog.cpp:245
SELOGGER_API int __stdcall se_set_block_value(const char *block_name, const char *block_value)
Definition: selogger.cpp:475
HRESULT SEClearLoggedValues(LONG run_number)
Definition: selog.cpp:315
SELOGGER_API int __stdcall se_set_measurement_label(const char *measurement_id, const char *label)
Definition: selogger.cpp:931
SELOGGER_API int __stdcall se_set_block_values(const std::vector< std::string > &block_names, const std::vector< std::string > &block_values)
Definition: selogger.cpp:484
SELOGGER_API int __stdcall se_set_block_details(const char *block_name, const char *setpoint_value, const char *vi_name, const char *read_control_label, const char *set_control_label, const char *button_control_label, unsigned options, const char *nexus_name, float low_limit, float high_limit, const char *units, const char *current_value)
Definition: selogger.cpp:784
int arrayVariantLength(VARIANT *v)
HRESULT SESetBlockValue(BSTR block_name, BSTR block_value)
Definition: selog.cpp:66
int unaccessArrayVariant(VARIANT *v)
HRESULT SENewSECIConfig(BSTR config_name)
Definition: selog.cpp:52
int makeVariantFromArray(VARIANT *v, const std::vector< T > &the_array)
SELOGGER_API int __stdcall se_log_values_async(long run_number, const char *source, const std::vector< std::string > &iso_times, const std::vector< std::string > &block_names, const std::vector< std::string > &block_values)
Definition: selogger.cpp:572