ICP  1
instctrl.cpp
Go to the documentation of this file.
1 // instctrl.cpp : Defines the entry point for the console application.
2 //
3 
4 #include "stdafx.h"
5 
6 //#import "progid:isisicp.Idae" named_guids
7 #import "..\\isisicp\\isisicp.tlb" named_guids
8 #import "..\\tlb\\Seci.tlb" named_guids
9 #import "..\\tlb\\LabVIEW.tlb" named_guids
10 
11 class InstCtrlApp : public Poco::Util::Application
12 {
13 public:
14  InstCtrlApp() : Poco::Util::Application() { }
15  virtual int main(const std::vector<std::string>& args);
16 protected:
17  void initialize(Poco::Util::Application& self)
18  {
19  loadConfiguration();
20  Application::initialize(self);
21  }
22 };
23 
24 int _tmain(int argc, _TCHAR* argv[])
25 {
26  InstCtrlApp app;
27  app.init(argc, argv);
28  int ret = app.run();
29  return ret;
30 }
31 
32 typedef HRESULT (isisicpLib::Idae::*comm_func_t)(BSTR* messages);
33 typedef HRESULT (isisicpLib::Idae::*comm_func_s_i_t)(_bstr_t name, long value, BSTR* messages);
34 typedef HRESULT (isisicpLib::Idae::*comm_func_i_t)(long value, BSTR* messages);
35 
36 static const char* comm_names[] = { "BEGIN", "END", "PAUSE", "RESUME", "ABORT", "UPDATE", "STORE", "QUIT", "WAIT", "ENDWAIT", NULL };
37 static comm_func_t comm_funcs[] = { &isisicpLib::Idae::beginRun, &isisicpLib::Idae::endRun,
38  &isisicpLib::Idae::pauseRun, &isisicpLib::Idae::resumeRun, &isisicpLib::Idae::abortRun,
39  &isisicpLib::Idae::updateCRPT, &isisicpLib::Idae::storeCRPT, &isisicpLib::Idae::quit,
40  &isisicpLib::Idae::startSEWait, &isisicpLib::Idae::endSEWait, NULL };
41 
42 static const char* comm_s_i_names[] = { "SETVAL", "LOAD", NULL };
43 static comm_func_s_i_t comm_s_i_funcs[] = { &isisicpLib::Idae::setICPValueLong, &isisicpLib::Idae::loadDAEWithData, NULL };
44 
45 static const char* comm_i_names[] = { "CHANGE_PERIOD", NULL };
46 static comm_func_i_t comm_i_funcs[] = { &isisicpLib::Idae::changePeriod, NULL };
47 
48 BOOST_STATIC_ASSERT( sizeof(comm_names) == sizeof(comm_funcs) );
50 BOOST_STATIC_ASSERT( sizeof(comm_i_names) == sizeof(comm_i_funcs) );
51 
52 int InstCtrlApp::main(const std::vector<std::string>& args)
53 {
54  Poco::Logger::root().setLevel(Poco::Message::PRIO_TRACE); // default for new loggers
55  logger().setLevel(Poco::Message::PRIO_TRACE); // sets for current application logger
56  CComPtr<isisicpLib::Idae> icp;
57  HRESULT hr;
58  try
59  {
60  CoInitializeEx(NULL, COINIT_MULTITHREADED);
61  hr = icp.CoCreateInstance(isisicpLib::CLSID_dae, 0, CLSCTX_LOCAL_SERVER);
62  if (FAILED(hr))
63  {
64  throw _com_error(hr);
65  }
66  BSTR messages;
67  for(std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
68  {
69  for(int i=0; comm_names[i] != NULL; ++i)
70  {
71  if (!stricmp(comm_names[i], it->c_str()))
72  {
73  std::cerr << "INSTCTRL: " << comm_names[i] << std::endl;
74  hr = (icp->*comm_funcs[i])(&messages);
75  if (FAILED(hr))
76  {
77  throw _com_error(hr);
78  }
79  std::cerr << COLE2CT(messages) << std::endl;
80  return 0;
81  }
82  }
83  for(int i=0; comm_s_i_names[i] != NULL; ++i)
84  {
85  if (!stricmp(comm_s_i_names[i], it->c_str()))
86  {
87  const std::string& name = *(++it);
88  if ( ++it != args.end() )
89  {
90  long value = atol(it->c_str());
91  std::cerr << "INSTCTRL: "<< comm_s_i_names[i] << " \"" << name << "\" " << value << std::endl;
92  hr = (icp->*comm_s_i_funcs[i])(name.c_str(), value, &messages);
93  if (FAILED(hr))
94  {
95  throw _com_error(hr);
96  }
97  std::cerr << COLE2CT(messages) << std::endl;
98  }
99  else
100  {
101  std::cerr << "INSTCTRL: Missing 2nd (integer) argument to command \"" << comm_s_i_names[i] << "\"" << std::endl;
102  }
103  return 0;
104  }
105  }
106  for(int i=0; comm_i_names[i] != NULL; ++i)
107  {
108  if (!stricmp(comm_i_names[i], it->c_str()))
109  {
110  long value = atol((++it)->c_str());
111  std::cerr << "INSTCTRL: "<< comm_i_names[i] << " " << value << std::endl;
112  hr = (icp->*comm_i_funcs[i])(value, &messages);
113  if (FAILED(hr))
114  {
115  throw _com_error(hr);
116  }
117  std::cerr << COLE2CT(messages) << std::endl;
118  return 0;
119  }
120  }
121  }
122  }
123  catch (const _com_error& ex)
124  {
125  std::cerr << ex.Source() << ": " << ex.ErrorMessage() << ": " << ex.Description() << std::endl;
126  }
127  catch (const std::exception& ex)
128  {
129  std::cerr << ex.what() << std::endl;
130  }
131  return 0;
132 }
133 
virtual int main(const std::vector< std::string > &args)
Definition: instctrl.cpp:52
void initialize(Poco::Util::Application &self)
Definition: instctrl.cpp:17
static const char * comm_i_names[]
Definition: instctrl.cpp:45
static const char * comm_names[]
Definition: instctrl.cpp:36
BOOST_STATIC_ASSERT(sizeof(DAEEventHeaderInfo)==4)
HRESULT(isisicpLib::Idae::* comm_func_t)(BSTR *messages)
Definition: instctrl.cpp:32
static comm_func_i_t comm_i_funcs[]
Definition: instctrl.cpp:46
static comm_func_s_i_t comm_s_i_funcs[]
Definition: instctrl.cpp:43
HRESULT(isisicpLib::Idae::* comm_func_s_i_t)(_bstr_t name, long value, BSTR *messages)
Definition: instctrl.cpp:33
static const char * comm_s_i_names[]
Definition: instctrl.cpp:42
HRESULT(isisicpLib::Idae::* comm_func_i_t)(long value, BSTR *messages)
Definition: instctrl.cpp:34
static comm_func_t comm_funcs[]
Definition: instctrl.cpp:37
int _tmain(int argc, _TCHAR *argv[])
Definition: newicp.cpp:11