ISIS Logo
NetShrVar
An EPICS support module to export National Instruments Network Shared Variables as process variables
NetShrVarInterface.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 NETSHRVAR_INTERFACE_H
12 #define NETSHRVAR_INTERFACE_H
13 
14 #ifdef epicsExportSharedSymbols
15 #define NetShrVarSymbols
16 #undef epicsExportSharedSymbols
17 #include <shareLib.h>
18 #endif
19 
20 #include <stdio.h>
21 #include <sys/timeb.h>
22 
23 #include <string>
24 #include <vector>
25 #include <map>
26 #include <list>
27 #include <stdexcept>
28 #include <sstream>
29 #include <fstream>
30 #include <iostream>
31 #include <cstdint>
32 
33 #if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1700 /* Pre VS2012 */
34 // boost atomic is not header only, volatile should be enough here
35 // as we will no longer care about 2010 soon
36 #define NSV_EMULATE_ATOMIC
37 typedef volatile uint32_t my_atomic_uint32_t;
38 typedef volatile int64_t my_atomic_uint64_t; // needs to be signed for later Interlocked operation
39 #else
40 #include <atomic>
41 typedef std::atomic<uint32_t> my_atomic_uint32_t;
42 typedef std::atomic<uint64_t> my_atomic_uint64_t;
43 #endif
44 
45 #include <epicsMutex.h>
46 #include <epicsThread.h>
47 #include <epicsExit.h>
48 #include <macLib.h>
49 #include <asynDriver.h>
50 
51 #include <cvirte.h>
52 #include <userint.h>
53 #include <cvinetv.h>
54 
55 #include "pugixml.hpp"
56 
57 #ifdef NetShrVarSymbols
58 #undef NetShrVarSymbols
59 #define epicsExportSharedSymbols
60 #include <shareLib.h>
61 #endif
62 
65 
66 struct NvItem;
67 class asynPortDriver;
68 struct CallbackData;
69 
70 
72 class epicsShareClass NetShrVarInterface
73 {
74 public:
75  NetShrVarInterface(const char* configSection, const char *configFile, int options);
76  size_t nParams();
78  void updateValues();
79  void createParams(asynPortDriver* driver);
80  void report(FILE* fp, int details);
81  void readValue(const char* param);
82  void dataTransferredCallback (void * handle, int error, CallbackData* cb_data);
83  void dataCallback (void * handle, CNVData data, CallbackData* cb_data);
84  void statusCallback (void * handle, CNVConnectionStatus status, int error, CallbackData* cb_data);
85  template<typename T> void setValue(const char* param, const T& value);
86  template<typename T> void setArrayValue(const char* param, const T* value, size_t nElements);
87  template<typename T> void readArrayValue(const char* paramName, T* value, size_t nElements, size_t* nIn);
88  static bool varExists(const std::string& path);
89  static bool pathExists(const std::string& path);
90 
91 private:
92  std::string m_configSection;
93  std::string m_configFile;
94  int m_options;
95 // epicsMutex m_lock;
96  asynPortDriver* m_driver;
97  typedef std::map<std::string,NvItem*> params_t;
99  pugi::xml_document m_xmlconfig;
100  MAC_HANDLE* m_mac_env;
103 
106  struct timeb m_last_report;
107 
108  inline void updateBytesReadCount(unsigned nbytes)
109  {
110 #ifdef NSV_EMULATE_ATOMIC
111  InterlockedIncrement(&m_items_read);
112  InterlockedExchangeAdd64(&m_bytes_read, nbytes);
113 #else
114  ++m_items_read;
115  m_bytes_read += nbytes;
116 #endif
117  }
118 
119  template<typename T> void getAsynParamValue(int param, T& value);
120  char* envExpand(const char *str);
121  void getParams();
122  void setValueCNV(const std::string& name, CNVData value);
123  static void epicsExitFunc(void* arg);
124  bool checkOption(NetShrVarOptions option) { return ( m_options & static_cast<int>(option) ) != 0; }
125  void connectVars();
126  bool convertTimeStamp(unsigned __int64 timestamp, epicsTimeStamp *epicsTS);
127  template<typename T> void updateParamValue(int param_index, T val, epicsTimeStamp* epicsTS, bool do_asyn_param_callbacks);
128  template<typename T> void updateParamArrayValue(int param_index, T* val, size_t nElements,
129  epicsTimeStamp* epicsTS, bool do_asyn_param_callbacks);
130  void updateParamCNV (int param_index, CNVData data, epicsTimeStamp* epicsTS, bool do_asyn_param_callbacks);
131  template<CNVDataType cnvType> void updateParamCNVImpl(int param_index, CNVData data, CNVDataType type,
132  unsigned int nDims, epicsTimeStamp* epicsTS, bool do_asyn_param_callbacks);
133  template<typename T,typename U> void updateParamArrayValueImpl(int param_index, T* val, size_t nElements);
134  void readVarInit(NvItem* item);
135  void setParamStatus(int param_id, asynStatus status, epicsAlarmCondition alarmStat = epicsAlarmNone, epicsAlarmSeverity alarmSevr = epicsSevNone);
136  void getParamStatus(int param_id, asynStatus& status, int& alarmStat, int& alarmSevr);
137  void initAsynParamIds();
138  void updateConnectedAlarmStatus(const std::string& paramName, int value, const std::string& alarmStr, epicsAlarmCondition stat, epicsAlarmSeverity sevr);
139 };
140 
141 #endif /* NETSHRVAR_INTERFACE_H */
int m_b_writer_wait_ms
how long to wait for a buffered write operation to complete in milliseconds
Stores information to be passed back via a shared variable callback on a subscriber connection...
int m_options
the various NetShrVarOptions currently in use
std::string m_configSection
section of configFile to load information from
std::atomic< uint64_t > my_atomic_uint64_t
void updateBytesReadCount(unsigned nbytes)
pugi::xml_document m_xmlconfig
Manager class for the NetVar Interaction. Parses an netvarconfig.xml file and provides access to the ...
bool checkOption(NetShrVarOptions option)
std::map< std::string, NvItem * > params_t
NetShrVarOptions
option argument in NetShrVarConfigure() of st.cmd not used at present
asynPortDriver * m_driver
int m_writer_wait_ms
how long to wait for a write operation to complete in milliseconds
details about a network shared variable we have connected to an asyn parameter
std::atomic< uint32_t > my_atomic_uint32_t
my_atomic_uint64_t m_bytes_read
my_atomic_uint32_t m_items_read
Copyright © 2013 Science and Technology Facilities Council | Generated by   doxygen 1.8.5