lvDCOM
An EPICS support module to export LabVIEW values as process variables
lvDCOMInterface.h
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2013 Science and Technology Facilities Council (STFC), GB.
3 * All rights reverved.
4 * This file is distributed subject to a Software License Agreement found
5 * in the file LICENSE.txt that is included with this distribution.
6 \*************************************************************************/
7 
10 
11 #ifndef LV_DCOM_INTERFACE_H
12 #define LV_DCOM_INTERFACE_H
13 
14 #include <stdio.h>
15 
16 //#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
17 #include <windows.h>
18 #include <tchar.h>
19 //#include <sys/stat.h>
20 //#include <process.h>
21 //#include <fcntl.h>
22 
23 #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
24 #include <atlbase.h>
25 #include <atlstr.h>
26 #include <atlcom.h>
27 #include <atlwin.h>
28 #include <atltypes.h>
29 #include <atlctl.h>
30 #include <atlhost.h>
31 
32 #include <string>
33 #include <vector>
34 #include <map>
35 #include <list>
36 #include <stdexcept>
37 #include <sstream>
38 #include <fstream>
39 #include <iostream>
40 
41 #include <epicsMutex.h>
42 #include <epicsThread.h>
43 #include <epicsExit.h>
44 
45 //#import "LabVIEW.tlb" named_guids
46 // The above statement would generate labview.tlh and labview.tli from an installed copy of LabVIEW, but we include pre-built versions in the source
47 #include "labview.tlh"
48 
49 #include <msxml2.h>
50 
51 // TinyXPath, we tried this but it did not work, so use msxml as we will always be on Windows
52 //#include <xpath_processor.h>
53 //#include <xpath_static.h>
54 
56 struct ViRef
57 {
58  LabVIEW::VirtualInstrumentPtr vi_ref;
59  bool reentrant;
60  bool started;
61  ViRef(LabVIEW::VirtualInstrumentPtr vi_ref_, bool reentrant_, bool started_) : vi_ref(vi_ref_), reentrant(reentrant_), started(started_) { }
62  ViRef() : vi_ref(NULL), reentrant(false), started(false) { }
63 };
64 
68 {
73 };
74 
77 {
78 public:
79  lvDCOMInterface(const char* configSection, const char *configFile, const char* host, int options, const char* progid, const char* username, const char* password);
80  long nParams();
81  void getParams(std::map<std::string,std::string>& res);
82  template<typename T> void setLabviewValue(const char* param, const T& value);
83  template<typename T> void getLabviewValue(const char* param, T* value);
84  template<typename T> void getLabviewValue(const char* param, T* value, size_t nElements, size_t& nIn);
85  ~lvDCOMInterface() { if (m_pxmldom != NULL) { m_pxmldom->Release(); m_pxmldom = 0; } }
86  std::string doPath(const std::string& xpath);
87  std::string doXPATH(const std::string& xpath);
88  bool doXPATHbool(const std::string& xpath);
89  void report(FILE* fp, int details);
90 
91 private:
92  std::string m_configSection;
93  std::string m_configFile;
94  std::string m_host;
95  std::string m_progid;
96  CLSID m_clsid;
97  std::string m_username;
98  std::string m_password;
99  int m_options;
100  typedef std::map<std::wstring, ViRef> vi_map_t;
102  epicsMutex m_lock;
103  // TiXmlDocument* m_doc;
104  // TiXmlElement* m_root;
105  IXMLDOMDocument2 *m_pxmldom;
106  CComBSTR m_extint;
107  CComPtr<LabVIEW::_Application> m_lv;
108  COAUTHIDENTITY* m_pidentity;
109  std::map<std::string,std::string> m_xpath_map;
110  std::map<std::string,bool> m_xpath_bool_map;
111 
112  void DomFromCOM();
113  void getViRef(BSTR vi_name, bool reentrant, LabVIEW::VirtualInstrumentPtr &vi);
114  void createViRef(BSTR vi_name, bool reentrant, LabVIEW::VirtualInstrumentPtr &vi);
115  void getLabviewValue(BSTR vi_name, BSTR control_name, VARIANT* value);
116  void setLabviewValue(BSTR vi_name, BSTR control_name, const VARIANT& value);
117  void setLabviewValueExt(BSTR vi_name, BSTR control_name, const VARIANT& value, VARIANT* results);
118  void callLabview(BSTR vi_name, VARIANT& names, VARIANT& values, VARIANT_BOOL reentrant, VARIANT* results);
119  void waitForLabviewBoolean(BSTR vi_name, BSTR control_name, bool value);
120  COAUTHIDENTITY* createIdentity(const std::string& user, const std::string& domain, const std::string& pass);
121  HRESULT setIdentity(COAUTHIDENTITY* pidentity, IUnknown* pUnk);
122  static void epicsExitFunc(void* arg);
123  void stopVis(bool only_ones_we_started);
124  bool checkOption(lvDCOMOptions option) { return ( m_options & static_cast<int>(option) ) != 0; }
125 };
126 
127 #endif /* LV_DCOM_INTERFACE_H */
lvDCOMOptions
Options that can be passed from EPICS iocsh via lvDCOMConfigure command.
COAUTHIDENTITY * m_pidentity
std::string m_configSection
section of configFile to load information from
(4) On IOC exit, stop any LabVIEW VIs that we started due to viStartIfIdle being specified ...
CComPtr< LabVIEW::_Application > m_lv
std::string m_progid
bool started
did we start this vi because it was idle and viStartIfIdle was specified
void waitForLabviewBoolean(BSTR vi_name, BSTR control_name, bool value)
(8) On IOC exit, stop any LabVIEW VIs that we have connected to
std::string doPath(const std::string &xpath)
std::string m_password
IXMLDOMDocument2 * m_pxmldom
void callLabview(BSTR vi_name, VARIANT &names, VARIANT &values, VARIANT_BOOL reentrant, VARIANT *results)
void report(FILE *fp, int details)
Helper for EPICS driver report function.
bool reentrant
is the VI reentrant
int m_options
the various lvDCOMOptions currently in use
std::map< std::string, bool > m_xpath_bool_map
void getParams(std::map< std::string, std::string > &res)
std::string doXPATH(const std::string &xpath)
std::map< std::string, std::string > m_xpath_map
static void epicsExitFunc(void *arg)
void stopVis(bool only_ones_we_started)
Manager class for LabVIEW DCOM Interaction. Parses an lvinput.xml file and provides access to the Lab...
void setLabviewValue(const char *param, const T &value)
std::map< std::wstring, ViRef > vi_map_t
ViRef(LabVIEW::VirtualInstrumentPtr vi_ref_, bool reentrant_, bool started_)
HRESULT setIdentity(COAUTHIDENTITY *pidentity, IUnknown *pUnk)
(1) If the LabVIEW VI is idle when we connect to it, issue a warning message
Hold a reference to a LabVIEW VI.
void getLabviewValue(const char *param, T *value)
(2) If the LabVIEW VI is idle when we connect to it, attempt to start it
std::string m_configFile
std::string m_host
COAUTHIDENTITY * createIdentity(const std::string &user, const std::string &domain, const std::string &pass)
bool checkOption(lvDCOMOptions option)
void createViRef(BSTR vi_name, bool reentrant, LabVIEW::VirtualInstrumentPtr &vi)
void setLabviewValueExt(BSTR vi_name, BSTR control_name, const VARIANT &value, VARIANT *results)
std::string m_username
LabVIEW::VirtualInstrumentPtr vi_ref
bool doXPATHbool(const std::string &xpath)
lvDCOMInterface(const char *configSection, const char *configFile, const char *host, int options, const char *progid, const char *username, const char *password)
section name of configFile to use to configure this asyn port
void getViRef(BSTR vi_name, bool reentrant, LabVIEW::VirtualInstrumentPtr &vi)