├── .gitattributes ├── README.md ├── client_qt_project ├── LICENSE.md ├── OPCUAMQTT.pro ├── OPCUAMQTT.pro.user ├── aboutdialog.cpp ├── aboutdialog.h ├── aboutdialog.ui ├── clientstates.h ├── config.h ├── coupleritem.cpp ├── coupleritem.h ├── icon.ico ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── mqttclient.cpp ├── mqttclient.h ├── opcuaclient.cpp ├── opcuaclient.h ├── opcuaepwrapper.cpp ├── opcuaepwrapper.h ├── opcuaepwrappercpp.cpp └── resources.qrc ├── images ├── client_hierarchy_simple.png └── gateway_client_gui.png └── libraries ├── freeopcua ├── LICENSE.md ├── README.md ├── freeopcua_include │ └── opc │ │ ├── common │ │ ├── addons_core │ │ │ ├── addon.h │ │ │ ├── addon_manager.h │ │ │ ├── addon_parameters.h │ │ │ ├── config_file.h │ │ │ ├── dynamic_addon.h │ │ │ ├── dynamic_addon_factory.h │ │ │ └── errors.h │ │ ├── class_pointers.h │ │ ├── errors.h │ │ ├── exception.h │ │ ├── interface.h │ │ ├── modules.h │ │ ├── object_id.h │ │ ├── thread.h │ │ └── uri_facade.h │ │ └── ua │ │ ├── client │ │ ├── addon.h │ │ ├── binary_client.h │ │ ├── client.h │ │ └── remote_connection.h │ │ ├── connection_listener.h │ │ ├── errors.h │ │ ├── event.h │ │ ├── global.h │ │ ├── model.h │ │ ├── node.h │ │ ├── protocol │ │ ├── attribute_ids.h │ │ ├── binary │ │ │ ├── common.h │ │ │ └── stream.h │ │ ├── channel.h │ │ ├── data_value.h │ │ ├── datetime.h │ │ ├── describe.h │ │ ├── endpoints.h │ │ ├── enums.h │ │ ├── expanded_object_ids.h │ │ ├── extension_identifiers.h │ │ ├── guid.h │ │ ├── input_from_buffer.h │ │ ├── message_identifiers.h │ │ ├── monitored_items.h │ │ ├── node_management.h │ │ ├── nodeid.h │ │ ├── object_ids.h │ │ ├── protocol.h │ │ ├── protocol_auto.h │ │ ├── reference_ids.h │ │ ├── secure_channel.h │ │ ├── session.h │ │ ├── status_codes.h │ │ ├── string_utils.h │ │ ├── strings.h │ │ ├── types.h │ │ ├── types_manual.h │ │ ├── utils.h │ │ ├── variable_access_level.h │ │ ├── variant.h │ │ ├── variant_visitor.h │ │ └── view.h │ │ ├── server │ │ ├── addons │ │ │ ├── address_space.h │ │ │ ├── asio_addon.h │ │ │ ├── common_addons.h │ │ │ ├── endpoints_services.h │ │ │ ├── opc_tcp_async.h │ │ │ ├── opcua_protocol.h │ │ │ ├── services_registry.h │ │ │ ├── standard_address_space.h │ │ │ ├── subscription_service.h │ │ │ └── xml_ns.h │ │ ├── address_space.h │ │ ├── endpoints_services.h │ │ ├── opc_tcp_async.h │ │ ├── server.h │ │ ├── services_registry.h │ │ ├── standard_address_space.h │ │ └── subscription_service.h │ │ ├── server_operations.h │ │ ├── services │ │ ├── attributes.h │ │ ├── endpoints.h │ │ ├── method.h │ │ ├── node_management.h │ │ ├── services.h │ │ ├── subscriptions.h │ │ └── view.h │ │ ├── socket_channel.h │ │ └── subscription.h └── freeopcua_libs_mingw32 │ ├── libopcuaclient.dll │ ├── libopcuaclient.dll.a │ ├── libopcuacore.dll │ ├── libopcuacore.dll.a │ ├── libopcuaprotocol.dll │ ├── libopcuaprotocol.dll.a │ ├── libopcuaserver.dll │ └── libopcuaserver.dll.a └── mosquitto ├── LICENSE.md ├── README.md ├── mosquitto_include ├── cpp │ └── mosquittopp.h └── mosquitto.h └── mosquitto_libs_mingw32 ├── libmosquitto.dll ├── libmosquitto.dll.a ├── libmosquittopp.dll └── libmosquittopp.dll.a /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OPC UA -> MQTT Gateway client 2 | 3 | The purpose of this client software is to allow the transfer of OPC UA node value data to a target MQTT broker. 4 | 5 | I made it as an assignment for the class "network programming" at my school Seinäjoki University of Applied Sciences. 6 | 7 | ### Dependencies 8 | 9 | - Compiler that supports C++11 10 | - Qt 5.5 11 | - FreeOpcUa library 12 | - Boost libraries 13 | - Mosquitto library 14 | - C-Ares 15 | - PThread 16 | - OpenSSL 17 | 18 | I personally used Qt 5.5 & MinGW32 4.9.2 while developing this and I only provide compiled library files for MinGW32 in this repository. Compiling & linking on linux shouldn't be an issue but you will probably struggle if you want to compile and link some of those libraries under Windows with MSVC. 19 | 20 | ### Repository structure 21 | 22 | - **client_qt_project**: This folder contains the source code of the client & Qt Creator project files. 23 | - **images**: Contains images related to the gateway client project. 24 | - **libraries**: This folder contains pre-compiled Windows library files for FreeOpcUa/Mosquitto & include headers. 25 | 26 | ### UML Diagram, clientside relations 27 | 28 | ![UML Diagram, simplified](images/client_hierarchy_simple.png "Rough UML diagram.") 29 | _Very rough diagram showing the interaction between the MQTT & OPC UA client objects._ 30 | 31 | 1. Subscription to node data change events is made on the OpcUa-side via client GUI. 32 | 2. Node value changes. 33 | * DataChange event function is executed in OPCUASubClient object, 34 | * Node value is transformed into a c-string (char *) & size of data is calculated. 35 | * MQTTClient::publish(...) is called, arguments passed are topic, node value and size in bytes. 36 | 3. Node value is published on the MQTT server. 37 | * Topic is "ChosenMainTopic/NodeNamespace/NodeBrowseName" 38 | * ChosenMainTopic can be changed via the client GUI. 39 | 40 | ### Screenshot of client GUI 41 | 42 | ![Gateway client GUI](images/gateway_client_gui.png "Screenshot of the Gateway client.") 43 | _Screenshot of the Gateway client._ 44 | 45 | Screenshot showing the GUI of the client. Connected to a FreeOpcUa python server & a Mosquitto MQTT broker. -------------------------------------------------------------------------------- /client_qt_project/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Toni Hämeenniemi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /client_qt_project/OPCUAMQTT.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2015-12-18T23:23:40 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | CONFIG += console 9 | 10 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 11 | 12 | # C++11 13 | QMAKE_CXXFLAGS += -std=c++11 -Werror=return-type 14 | 15 | # Optimization for release 16 | QMAKE_CXXFLAGS_RELEASE += -Ofast 17 | 18 | # Includes 19 | INCLUDEPATH += C:/boost/boost_mingw # boost 20 | INCLUDEPATH += ./include # freeopcua, mqtt 21 | 22 | # Libraries 23 | LIBS += -LC:/boost/boost_mingw/stage/lib \ # boost 24 | -lws2_32 \ # winsock 25 | -lboost_system-mgw49-mt-d-1_60 # boost system 26 | 27 | LIBS += -L"$$PWD/lib/opcua" \ # freeopcua 28 | -lopcuacore \ 29 | -lopcuaprotocol \ 30 | -lopcuaclient 31 | 32 | LIBS += -L"$$PWD/lib/mqtt" \ # mqtt 33 | -lmosquitto \ 34 | -lmosquittopp 35 | 36 | TARGET = OPCUAMQTT 37 | TEMPLATE = app 38 | 39 | SOURCES += main.cpp\ 40 | mainwindow.cpp \ 41 | aboutdialog.cpp \ 42 | opcuaclient.cpp \ 43 | coupleritem.cpp \ 44 | mqttclient.cpp \ 45 | opcuaepwrapper.cpp 46 | 47 | HEADERS += mainwindow.h \ 48 | aboutdialog.h \ 49 | config.h \ 50 | opcuaclient.h \ 51 | coupleritem.h \ 52 | mqttclient.h \ 53 | clientstates.h \ 54 | opcuaepwrapper.h 55 | 56 | FORMS += mainwindow.ui \ 57 | aboutdialog.ui 58 | 59 | RESOURCES += \ 60 | resources.qrc 61 | -------------------------------------------------------------------------------- /client_qt_project/aboutdialog.cpp: -------------------------------------------------------------------------------- 1 | #include "aboutdialog.h" 2 | #include "ui_aboutdialog.h" 3 | #include "config.h" 4 | #include 5 | #include 6 | 7 | AboutDialog::AboutDialog(QWidget *parent) : 8 | QDialog(parent), 9 | m_ui(new Ui::AboutDialog) 10 | { 11 | // Basic UI setup 12 | m_ui->setupUi(this); 13 | setWindowTitle("About"); 14 | QPixmap logo(":/res/icon.ico"); 15 | m_ui->lb_logo->setPixmap(logo); 16 | m_ui->lb_logo->setScaledContents(true); 17 | std::ostringstream s; 18 | s << "OPC UA -> MQTT Gateway client\n" << 19 | VERSION_S; 20 | m_ui->lb_about1->setText(std::string(s.str()).c_str()); 21 | m_ui->lb_about2->setOpenExternalLinks(true); 22 | m_ui->lb_about2->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard); 23 | m_ui->lb_about2->setText("https://github.com/harha/"); 24 | 25 | // Signal -> Slot connections 26 | connect(m_ui->pb_close, SIGNAL(clicked(bool)), 27 | this, SLOT(close())); 28 | } 29 | 30 | AboutDialog::~AboutDialog() 31 | { 32 | if (m_ui) 33 | delete m_ui; 34 | } 35 | -------------------------------------------------------------------------------- /client_qt_project/aboutdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef ABOUTDIALOG_H 2 | #define ABOUTDIALOG_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Ui { 8 | class AboutDialog; 9 | } 10 | 11 | class AboutDialog : public QDialog 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit AboutDialog(QWidget *parent = 0); 17 | ~AboutDialog(); 18 | private: 19 | Ui::AboutDialog *m_ui; 20 | }; 21 | 22 | #endif // ABOUTDIALOG_H 23 | -------------------------------------------------------------------------------- /client_qt_project/aboutdialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AboutDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 320 10 | 240 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | 21 | 320 22 | 240 23 | 24 | 25 | 26 | 27 | 320 28 | 240 29 | 30 | 31 | 32 | About 33 | 34 | 35 | 36 | 37 | 260 38 | 210 39 | 51 40 | 21 41 | 42 | 43 | 44 | Close 45 | 46 | 47 | 48 | 49 | 50 | 70 51 | 10 52 | 241 53 | 41 54 | 55 | 56 | 57 | lb_about1 58 | 59 | 60 | Qt::AutoText 61 | 62 | 63 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop 64 | 65 | 66 | Qt::LinksAccessibleByMouse 67 | 68 | 69 | 70 | 71 | 72 | 70 73 | 40 74 | 241 75 | 16 76 | 77 | 78 | 79 | lb_about2 80 | 81 | 82 | Qt::AutoText 83 | 84 | 85 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop 86 | 87 | 88 | 89 | 90 | 91 | 10 92 | 10 93 | 51 94 | 51 95 | 96 | 97 | 98 | lb_logo 99 | 100 | 101 | Qt::AutoText 102 | 103 | 104 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop 105 | 106 | 107 | Qt::LinksAccessibleByMouse 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /client_qt_project/clientstates.h: -------------------------------------------------------------------------------- 1 | #ifndef CLIENTSTATES_H 2 | #define CLIENTSTATES_H 3 | 4 | enum CLIENT_STATE 5 | { 6 | NOTSTARTED = 0, RUNNING = 1, STOPPED = 2, FINISHED = 3 7 | }; 8 | 9 | enum CLIENT_STATUS 10 | { 11 | ERROR = -1, CONNECTED = 0, DISCONNECTED = 1 12 | }; 13 | 14 | #endif // CLIENTSTATES_H 15 | -------------------------------------------------------------------------------- /client_qt_project/config.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_H 2 | #define CONFIG_H 3 | 4 | #define VERSION_R 0 5 | #define VERSION_B 0 6 | #define VERSION_A 2 7 | #define VERSION_S "Version " << VERSION_R << "." << VERSION_B << "." << VERSION_A 8 | 9 | #endif // CONFIG_H 10 | -------------------------------------------------------------------------------- /client_qt_project/coupleritem.cpp: -------------------------------------------------------------------------------- 1 | #include "coupleritem.h" 2 | 3 | CouplerItem::CouplerItem(QObject *parent, OpcUa::Node opcuanode) : 4 | QObject(parent), 5 | m_opcuanode(opcuanode), 6 | m_subhandle(0) 7 | { 8 | 9 | } 10 | 11 | CouplerItem::CouplerItem(const CouplerItem &obj) : 12 | QObject(obj.parent()), 13 | m_opcuanode(obj.getOpcUaNode()) 14 | { 15 | 16 | } 17 | 18 | void CouplerItem::setOpcUaNode(OpcUa::Node node) 19 | { 20 | m_opcuanode = node; 21 | } 22 | 23 | void CouplerItem::setSubHandle(uint32_t handle) 24 | { 25 | m_subhandle = handle; 26 | } 27 | 28 | OpcUa::Node CouplerItem::getOpcUaNode() const 29 | { 30 | return m_opcuanode; 31 | } 32 | 33 | uint32_t CouplerItem::getSubHandle() const 34 | { 35 | return m_subhandle; 36 | } 37 | -------------------------------------------------------------------------------- /client_qt_project/coupleritem.h: -------------------------------------------------------------------------------- 1 | #ifndef COUPLERITEM_H 2 | #define COUPLERITEM_H 3 | 4 | #include 5 | #include 6 | 7 | class CouplerItem : public QObject 8 | { 9 | Q_OBJECT 10 | 11 | public: 12 | CouplerItem(QObject *parent = nullptr, OpcUa::Node opcuanode = OpcUa::Node()); 13 | CouplerItem(const CouplerItem &obj); 14 | void setOpcUaNode(OpcUa::Node node); 15 | void setSubHandle(uint32_t handle); 16 | OpcUa::Node getOpcUaNode() const; 17 | uint32_t getSubHandle() const; 18 | private: 19 | OpcUa::Node m_opcuanode; 20 | uint32_t m_subhandle; 21 | 22 | }; 23 | 24 | Q_DECLARE_METATYPE(CouplerItem) 25 | Q_DECLARE_METATYPE(CouplerItem *) 26 | 27 | #endif // COUPLERITEM_H 28 | -------------------------------------------------------------------------------- /client_qt_project/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Harha/OPC-UA-to-MQTT-Gateway/7afa2157c3ae79bd1272da1d4efdfa4f7a24f05c/client_qt_project/icon.ico -------------------------------------------------------------------------------- /client_qt_project/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | a.setQuitOnLastWindowClosed(true); 8 | MainWindow w; 9 | w.show(); 10 | int rc = a.exec(); 11 | return rc; 12 | } 13 | -------------------------------------------------------------------------------- /client_qt_project/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "opcuaclient.h" 8 | #include "mqttclient.h" 9 | 10 | namespace Ui { 11 | class MainWindow; 12 | } 13 | 14 | class AboutDialog; 15 | 16 | // -------------------------------------------------------- 17 | // MainWindow class below 18 | // -------------------------------------------------------- 19 | class MainWindow : public QMainWindow 20 | { 21 | Q_OBJECT 22 | 23 | public: 24 | explicit MainWindow(QWidget *parent = 0); 25 | ~MainWindow(); 26 | 27 | void createOpcUaMqttLink(QTreeWidgetItem *item); 28 | void removeOpcUaMqttLink(QTreeWidgetItem *item); 29 | QTreeWidgetItem *treeAddRoot(QTreeWidget *tree, OpcUa::Node *node); 30 | QTreeWidgetItem *treeAddChild(QTreeWidgetItem *parent, OpcUa::Node *node); 31 | void treeShowNodeInfo(QTreeWidgetItem *item); 32 | void treeSetNodeValue(QTreeWidgetItem *item, OpcUa::VariantType type); 33 | void treeAddNode(QTreeWidgetItem *item, int type); 34 | void treeBuildOpcUa(OpcUa::Node *node, QTreeWidgetItem *parent, int n); 35 | void setOpcUaStatus(CLIENT_STATUS status); 36 | void setMqttStatus(CLIENT_STATUS status); 37 | 38 | public slots: 39 | void saveSettings(); 40 | void loadSettings(); 41 | void trigAboutMenu(); 42 | void reqEndpointsOpcUaClient(); 43 | void initOpcUaClient(); 44 | void initMqttClient(); 45 | void setMqttTopic(); 46 | void treeUpdateItem(QTreeWidgetItem *item, int slot); 47 | void showOpcUaVarMenu(const QPoint &pos); 48 | 49 | private: 50 | Ui::MainWindow *m_ui; 51 | AboutDialog *m_about; 52 | QString m_settingsFile; 53 | std::string m_opcua_addr; 54 | std::string m_mqtt_addr; 55 | OPCUAClient *m_opcua_client; 56 | MQTTClient *m_mqtt_client; 57 | 58 | }; 59 | 60 | #endif // MAINWINDOW_H 61 | -------------------------------------------------------------------------------- /client_qt_project/mqttclient.cpp: -------------------------------------------------------------------------------- 1 | #include "mqttclient.h" 2 | #include 3 | 4 | // -------------------------------------------------------- 5 | // Callback functions below 6 | // -------------------------------------------------------- 7 | void on_connect(struct mosquitto *mosq, void *obj, int rc) 8 | { 9 | MQTTClient *client = (MQTTClient *) obj; 10 | 11 | if (rc == 0) // Success 12 | { 13 | qDebug() << "MQTT: Successful connect!"; 14 | 15 | client->setStatus(CONNECTED); 16 | } 17 | else if (rc == 1) // Refused (Unacceptable protocol version) 18 | { 19 | qDebug() << "MQTT: Connection refused (Unacceptable protocol version)."; 20 | 21 | client->setStatus(ERROR); 22 | } 23 | else if (rc == 2) // Refused (Identifier rejected) 24 | { 25 | qDebug() << "MQTT: Connection refused (Identifier rejected)."; 26 | 27 | client->setStatus(ERROR); 28 | } 29 | else if (rc == 3) // Refused (Broker unavailable) 30 | { 31 | qDebug() << "MQTT: Connection refused (Broker unavailable)."; 32 | 33 | client->setStatus(ERROR); 34 | } 35 | else // Refused (Unknown) 36 | { 37 | qDebug() << "MQTT: Connection refused (Unknown)."; 38 | 39 | client->setStatus(ERROR); 40 | } 41 | } 42 | 43 | void on_disconnect(struct mosquitto *mosq, void *obj, int rc) 44 | { 45 | MQTTClient *client = (MQTTClient *) obj; 46 | 47 | if (rc == 0) // Disconnected via mosquitto_disconnect 48 | { 49 | qDebug() << "MQTT: Disconnected (mosquitto_disconnect)."; 50 | 51 | client->setStatus(DISCONNECTED); 52 | } 53 | else // Unexpected disconnection 54 | { 55 | qDebug() << "MQTT: Disconnected (Unexpected)."; 56 | 57 | client->setStatus(DISCONNECTED); 58 | } 59 | } 60 | 61 | void on_publish(struct mosquitto *mosq, void *obj, int rc) 62 | { 63 | 64 | } 65 | 66 | void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message) 67 | { 68 | 69 | } 70 | 71 | void on_subscribe(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos) 72 | { 73 | 74 | } 75 | 76 | void on_unsubscribe(struct mosquitto *mosq, void *obj, int mid) 77 | { 78 | 79 | } 80 | 81 | void on_log(struct mosquitto *mosq, void *obj, int level, const char *str) 82 | { 83 | //qDebug() << "MQTT: " << str; 84 | } 85 | 86 | // -------------------------------------------------------- 87 | // MQTTClient class below 88 | // -------------------------------------------------------- 89 | MQTTClient::MQTTClient(std::string host, int port, int id, std::string topic) : 90 | m_client(NULL), 91 | m_host(host), 92 | m_port(port), 93 | m_id(id), 94 | m_topic(topic), 95 | m_runstate(NOTSTARTED), 96 | m_status(DISCONNECTED) 97 | { 98 | mosqpp::lib_init(); 99 | int major = 0, minor = 0, revision = 0; 100 | mosqpp::lib_version(&major, &minor, &revision); 101 | qDebug() << "MQTT: Mosquitto library, version " << major << minor << revision; 102 | } 103 | 104 | MQTTClient::~MQTTClient() 105 | { 106 | destroy_client(); 107 | mosqpp::lib_cleanup(); 108 | } 109 | 110 | void MQTTClient::create_client() 111 | { 112 | if (m_client == nullptr || m_client == NULL) 113 | { 114 | m_client = mosquitto_new(NULL, true, (void *) this); // pass pointer of this class as user data, to be used in callbacks 115 | mosquitto_connect_callback_set(m_client, on_connect); 116 | mosquitto_disconnect_callback_set(m_client, on_disconnect); 117 | mosquitto_publish_callback_set(m_client, on_publish); 118 | mosquitto_message_callback_set(m_client, on_message); 119 | mosquitto_subscribe_callback_set(m_client, on_subscribe); 120 | mosquitto_unsubscribe_callback_set(m_client, on_unsubscribe); 121 | mosquitto_log_callback_set(m_client, on_log); 122 | } 123 | } 124 | 125 | void MQTTClient::destroy_client() 126 | { 127 | if (m_client != NULL) 128 | { 129 | if (m_status == CONNECTED) 130 | mosquitto_disconnect(m_client); 131 | 132 | mosquitto_destroy(m_client); 133 | m_client = NULL; 134 | } 135 | } 136 | 137 | void MQTTClient::publish_message(std::string subtopic, int payloadlen, const void *payload) 138 | { 139 | mosquitto_publish(m_client, NULL, (m_topic + "/" + subtopic).c_str(), payloadlen, payload, 1, true); 140 | } 141 | 142 | void MQTTClient::run() 143 | { 144 | if (m_runstate != NOTSTARTED && m_runstate != FINISHED) 145 | return; 146 | 147 | // Delete old instance of the client if it somehow still exists 148 | destroy_client(); 149 | 150 | // Create client instance with random ID 151 | create_client(); 152 | 153 | m_runstate = RUNNING; 154 | 155 | // Connect to target server, the error checking has to be done here like this because 156 | // connect callback doesn't work at this point. 157 | qDebug() << "MQTT: Connecting to" << m_host.c_str() << "..."; 158 | int valueconnect = mosquitto_connect(m_client, m_host.c_str(), m_port, 60); 159 | 160 | if (valueconnect != MOSQ_ERR_SUCCESS) 161 | { 162 | qDebug() << "MQTT: Failed to connect to selected server."; 163 | m_runstate = NOTSTARTED; 164 | m_status = ERROR; 165 | return; 166 | } 167 | 168 | m_status = CONNECTED; 169 | 170 | if (m_status != CONNECTED) 171 | { 172 | m_runstate = NOTSTARTED; 173 | return; 174 | } 175 | 176 | // TODO: This could be set to be configurable via GUI 177 | int reconnAttempts = 0; 178 | int reconnMax = 100; 179 | 180 | while (m_runstate == RUNNING) 181 | { 182 | if (m_status == ERROR) 183 | { 184 | m_runstate = STOPPED; 185 | } 186 | else 187 | { 188 | if (reconnAttempts >= reconnMax) 189 | { 190 | m_status = DISCONNECTED; 191 | m_runstate = STOPPED; 192 | } 193 | 194 | if (m_status == DISCONNECTED && reconnAttempts < reconnMax) 195 | { 196 | qDebug() << "MQTT: Disconnected from server! Attempting to reconnect, attempts: " << reconnAttempts << "/" << reconnMax; 197 | 198 | int valuereconnect = mosquitto_reconnect(m_client); 199 | reconnAttempts++; 200 | 201 | /* <-- Not needed because we are relying completely on the callback functions now for state changes. 202 | if (valueconnect != MOSQ_ERR_SUCCESS) 203 | { 204 | qDebug() << "MQTT: Failed to reconnect to the selected server."; 205 | } 206 | else 207 | { 208 | qDebug() << "MQTT: Successfully reconnected to the selected server!"; 209 | reconnAttempts = 0; 210 | } 211 | */ 212 | } 213 | 214 | mosquitto_loop(m_client, -1, 1); 215 | } 216 | } 217 | 218 | destroy_client(); 219 | m_runstate = FINISHED; 220 | qDebug() << "MQTT: Disconnecting from server..."; 221 | } 222 | 223 | void MQTTClient::setHost(std::string host) 224 | { 225 | m_host = host; 226 | } 227 | 228 | void MQTTClient::setPort(int port) 229 | { 230 | m_port = port; 231 | } 232 | 233 | void MQTTClient::setTopic(std::string topic) 234 | { 235 | m_topic = topic; 236 | } 237 | 238 | void MQTTClient::setRunState(const CLIENT_STATE state) 239 | { 240 | m_runstate = state; 241 | } 242 | 243 | void MQTTClient::setStatus(const CLIENT_STATUS status) 244 | { 245 | m_status = status; 246 | } 247 | 248 | std::string MQTTClient::getHost() const 249 | { 250 | return m_host; 251 | } 252 | 253 | int MQTTClient::getPort() const 254 | { 255 | return m_port; 256 | } 257 | 258 | int MQTTClient::getId() const 259 | { 260 | return m_id; 261 | } 262 | 263 | std::string MQTTClient::getTopic() const 264 | { 265 | return m_topic; 266 | } 267 | 268 | CLIENT_STATE MQTTClient::getRunState() const 269 | { 270 | return m_runstate; 271 | } 272 | 273 | CLIENT_STATUS MQTTClient::getStatus() const 274 | { 275 | return m_status; 276 | } 277 | -------------------------------------------------------------------------------- /client_qt_project/mqttclient.h: -------------------------------------------------------------------------------- 1 | #ifndef MQTTCLIENT_H 2 | #define MQTTCLIENT_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "clientstates.h" 9 | 10 | // -------------------------------------------------------- 11 | // Callback functions below 12 | // -------------------------------------------------------- 13 | void on_connect(struct mosquitto *mosq, void *obj, int rc); 14 | void on_disconnect(struct mosquitto *mosq, void *obj, int rc); 15 | void on_publish(struct mosquitto *mosq, void *obj, int rc); 16 | void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message); 17 | void on_subscribe(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos); 18 | void on_unsubscribe(struct mosquitto *mosq, void *obj, int mid); 19 | void on_log(struct mosquitto *mosq, void *obj, int level, const char *str); 20 | 21 | // -------------------------------------------------------- 22 | // MQTTClient class below 23 | // 24 | // TODO: Add encryption support (SSL/TLS) 25 | // -------------------------------------------------------- 26 | class MQTTClient : public QThread 27 | { 28 | Q_OBJECT 29 | 30 | public: 31 | MQTTClient(std::string host = "localhost", int port = 1883, int id = 0, std::string topic = "opcuamqtt"); 32 | ~MQTTClient(); 33 | 34 | void create_client(); 35 | void destroy_client(); 36 | void publish_message(std::string subtopic, int payloadlen, const void *payload); 37 | void setHost(std::string host); 38 | void setPort(int port); 39 | void setTopic(std::string topic); 40 | void setRunState(const CLIENT_STATE state); 41 | void setStatus(const CLIENT_STATUS status); 42 | std::string getHost() const; 43 | int getPort() const; 44 | int getId() const; 45 | std::string getTopic() const; 46 | CLIENT_STATE getRunState() const; 47 | CLIENT_STATUS getStatus() const; 48 | 49 | private: 50 | mosquitto *m_client; 51 | std::string m_host; 52 | int m_port; 53 | int m_id; 54 | std::string m_topic; 55 | volatile CLIENT_STATE m_runstate; 56 | volatile CLIENT_STATUS m_status; 57 | 58 | protected: 59 | void run() override; 60 | 61 | }; 62 | 63 | #endif // MQTTCLIENT_H 64 | -------------------------------------------------------------------------------- /client_qt_project/opcuaclient.cpp: -------------------------------------------------------------------------------- 1 | #include "opcuaclient.h" 2 | #include "mainwindow.h" 3 | #include "mqttclient.h" 4 | #include "coupleritem.h" 5 | #include 6 | #include 7 | 8 | // -------------------------------------------------------- 9 | // Callback client class below 10 | // -------------------------------------------------------- 11 | OPCUASubClient::OPCUASubClient(MQTTClient *cli) : m_mqttclient(cli) 12 | { 13 | 14 | } 15 | 16 | void OPCUASubClient::DataChange(uint32_t handle, const OpcUa::Node& node, const OpcUa::Variant& val, OpcUa::AttributeId attr) 17 | { 18 | //qDebug() << "OPCUA: DataChange event, value of Node " << node.ToString().c_str() << " is now: " << val.ToString().c_str(); 19 | 20 | if (m_mqttclient->getStatus() == CONNECTED) 21 | { 22 | std::string strval = val.ToString(); 23 | 24 | m_mqttclient->publish_message(std::to_string(node.GetId().GetNamespaceIndex()) + "/" + node.GetBrowseName().Name, strval.size(), (const void *) strval.c_str()); 25 | } 26 | } 27 | 28 | // -------------------------------------------------------- 29 | // OPC UA Client class below 30 | // -------------------------------------------------------- 31 | OPCUAClient::OPCUAClient(MQTTClient *cl, std::string ep) : 32 | m_mqttclient(cl), 33 | m_initEndpoint(ep), 34 | m_endpoints(std::vector()), 35 | m_targetEndpoint(OpcUa::EndpointDescription()), 36 | m_client(new OpcUa::UaClient(false)), 37 | m_subclient(new OPCUASubClient(m_mqttclient)), 38 | m_subs(std::map>()), 39 | m_root(nullptr), 40 | m_objects(nullptr), 41 | m_runstate(NOTSTARTED), 42 | m_status(DISCONNECTED) 43 | { 44 | 45 | } 46 | 47 | OPCUAClient::~OPCUAClient() 48 | { 49 | if (m_objects) 50 | delete m_objects; 51 | 52 | if (m_root) 53 | delete m_root; 54 | 55 | if (m_subclient) 56 | delete m_subclient; 57 | 58 | if (m_client) 59 | { 60 | if (m_runstate == RUNNING) 61 | m_runstate = STOPPED; 62 | 63 | if (m_status == CONNECTED) 64 | m_client->Disconnect(); 65 | 66 | msleep(100); 67 | 68 | delete m_client; 69 | } 70 | } 71 | 72 | // TODO: Handle subscriptions in some better way... 73 | void OPCUAClient::createOpcUaMqttLink(CouplerItem *item, int period) 74 | { 75 | OpcUa::Node node = item->getOpcUaNode(); 76 | std::string key = node.ToString(); 77 | 78 | if (getSubs().find(key) == getSubs().end() || item->getSubHandle() == 0) 79 | { 80 | getSubs()[key] = m_client->CreateSubscription((unsigned int) period, *m_subclient); 81 | uint32_t handle = getSubs().at(key).get()->SubscribeDataChange(node); 82 | item->setSubHandle(handle); 83 | } 84 | } 85 | 86 | void OPCUAClient::removeOpcUaMqttLink(CouplerItem *item) 87 | { 88 | std::string key = item->getOpcUaNode().ToString(); 89 | 90 | if (getSubs().find(key) != getSubs().end()) 91 | { 92 | OpcUa::Subscription *sub = getSubs().at(key).get(); 93 | sub->UnSubscribe(item->getSubHandle()); 94 | item->setSubHandle(0); 95 | } 96 | } 97 | 98 | void OPCUAClient::requestEndpoints() 99 | { 100 | if (m_runstate != NOTSTARTED && m_runstate != FINISHED) 101 | return; 102 | 103 | // Empty current endpoints 104 | m_endpoints.clear(); 105 | 106 | try 107 | { 108 | qDebug() << "OPCUA: Getting endpoints from" << m_initEndpoint.c_str() << "..."; 109 | m_endpoints = m_client->GetServerEndpoints(m_initEndpoint); 110 | m_client->Disconnect(); 111 | } 112 | catch (const std::exception &exc) 113 | { 114 | qDebug() << exc.what(); 115 | m_status = ERROR; 116 | } 117 | catch (...) 118 | { 119 | qDebug() << "Unknown error."; 120 | m_status = ERROR; 121 | } 122 | } 123 | 124 | void OPCUAClient::run() 125 | { 126 | if (m_runstate != NOTSTARTED && m_runstate != FINISHED) 127 | return; 128 | 129 | // Prevent memory leak -> Delete old data 130 | if (m_root) 131 | delete m_root; 132 | if (m_objects) 133 | delete m_objects; 134 | 135 | // Delete old subscriptions 136 | if (!m_subs.empty()) 137 | m_subs.clear(); 138 | 139 | m_runstate = RUNNING; 140 | 141 | try 142 | { 143 | qDebug() << "OPCUA: Connecting to" << m_targetEndpoint.EndpointUrl.c_str() << "..."; 144 | m_client->Connect(m_targetEndpoint); 145 | qDebug() << "OPCUA: Security policy: " << m_client->GetSecurityPolicy().c_str(); 146 | m_status = CONNECTED; 147 | 148 | qDebug() << "OPCUA: Getting root & object nodes from the server..."; 149 | m_root = new OpcUa::Node(m_client->GetRootNode()); 150 | m_objects = new OpcUa::Node(m_client->GetObjectsNode()); 151 | qDebug() << "OPCUA: Requested root node is" << m_root->ToString().c_str(); 152 | qDebug() << "OPCUA: Requested objects node is" << m_objects->ToString().c_str(); 153 | 154 | // The test below works, but emits errors. QT Doesn't like other threads 155 | // accessing the main UI thread widgets. 156 | // ------------------------------------- 157 | // qDebug() << "OPCUA: Building treewidget nodes..."; 158 | // m_mainwin->treeBuildOpcUa(m_root, nullptr, 0); 159 | // qDebug() << "OPCUA: Finished building the treewidget."; 160 | 161 | while (m_runstate == RUNNING) 162 | { 163 | if (m_status == ERROR) 164 | m_runstate = STOPPED; 165 | 166 | msleep(100); // Do something, currently nothing. 167 | } 168 | 169 | qDebug() << "OPCUA: Disconnecting from server..."; 170 | m_client->Disconnect(); 171 | m_status = DISCONNECTED; 172 | } 173 | catch (const std::exception &exc) 174 | { 175 | qDebug() << exc.what(); 176 | m_status = ERROR; 177 | m_runstate = STOPPED; 178 | } 179 | catch (...) 180 | { 181 | qDebug() << "OPCUA: Unknown error."; 182 | m_status = ERROR; 183 | m_runstate = STOPPED; 184 | } 185 | 186 | m_runstate = FINISHED; 187 | } 188 | 189 | void OPCUAClient::setInitEndpoint(std::string endpoint) 190 | { 191 | m_initEndpoint = endpoint; 192 | } 193 | 194 | void OPCUAClient::setTargetEndpoint(OpcUa::EndpointDescription endpoint) 195 | { 196 | m_targetEndpoint = endpoint; 197 | } 198 | 199 | void OPCUAClient::setRunState(const CLIENT_STATE state) 200 | { 201 | m_runstate = state; 202 | } 203 | 204 | void OPCUAClient::setStatus(const CLIENT_STATUS status) 205 | { 206 | m_status = status; 207 | } 208 | 209 | std::string OPCUAClient::getInitEndpoint() const 210 | { 211 | return m_initEndpoint; 212 | } 213 | 214 | std::vector OPCUAClient::getEndpoints() const 215 | { 216 | return m_endpoints; 217 | } 218 | 219 | OpcUa::EndpointDescription OPCUAClient::getTargetEndpoint() const 220 | { 221 | return m_targetEndpoint; 222 | } 223 | 224 | OpcUa::UaClient *OPCUAClient::getClient() const 225 | { 226 | return m_client; 227 | } 228 | 229 | OPCUASubClient *OPCUAClient::getSubClient() const 230 | { 231 | return m_subclient; 232 | } 233 | 234 | boost::mutex mutex; 235 | std::map> &OPCUAClient::getSubs() 236 | { 237 | boost::lock_guard lock(mutex); 238 | return m_subs; 239 | } 240 | 241 | OpcUa::Node *OPCUAClient::getRootNode() const 242 | { 243 | return m_root; 244 | } 245 | 246 | OpcUa::Node *OPCUAClient::getObjectsNode() const 247 | { 248 | return m_objects; 249 | } 250 | 251 | CLIENT_STATE OPCUAClient::getRunState() const 252 | { 253 | return m_runstate; 254 | } 255 | 256 | CLIENT_STATUS OPCUAClient::getStatus() const 257 | { 258 | return m_status; 259 | } 260 | 261 | std::string OPCUAClient::securityLevelToString(int level) 262 | { 263 | if (level == 0) 264 | return "#None"; 265 | else if (level == 1) 266 | return "#Basic128"; 267 | else if (level == 2) 268 | return "#Basic256"; 269 | else 270 | return "#Unknown"; 271 | } 272 | -------------------------------------------------------------------------------- /client_qt_project/opcuaclient.h: -------------------------------------------------------------------------------- 1 | #ifndef OPCUACLIENT_H 2 | #define OPCUACLIENT_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "clientstates.h" 11 | 12 | class MQTTClient; 13 | class CouplerItem; 14 | 15 | // -------------------------------------------------------- 16 | // Callback client class below 17 | // -------------------------------------------------------- 18 | class OPCUASubClient : public OpcUa::SubscriptionHandler 19 | { 20 | 21 | public: 22 | OPCUASubClient(MQTTClient *cl = nullptr); 23 | 24 | private: 25 | virtual void DataChange(uint32_t handle, const OpcUa::Node& node, const OpcUa::Variant& val, OpcUa::AttributeId attr) override; 26 | 27 | MQTTClient *m_mqttclient; 28 | 29 | }; 30 | 31 | // -------------------------------------------------------- 32 | // OPC UA Client class below 33 | // -------------------------------------------------------- 34 | class OPCUAClient : public QThread 35 | { 36 | Q_OBJECT 37 | 38 | public: 39 | OPCUAClient(MQTTClient *cl = nullptr, std::string ep = "opc.tcp://localhost:4841/"); 40 | ~OPCUAClient(); 41 | 42 | void createOpcUaMqttLink(CouplerItem *item, int period); 43 | void removeOpcUaMqttLink(CouplerItem *item); 44 | void requestEndpoints(); 45 | void setInitEndpoint(std::string endpoint); 46 | void setTargetEndpoint(OpcUa::EndpointDescription endpoint); 47 | void setRunState(const CLIENT_STATE state); 48 | void setStatus(const CLIENT_STATUS status); 49 | std::string getInitEndpoint() const; 50 | std::vector getEndpoints() const; 51 | OpcUa::EndpointDescription getTargetEndpoint() const; 52 | OpcUa::UaClient *getClient() const; 53 | OPCUASubClient *getSubClient() const; 54 | std::map> &getSubs(); 55 | OpcUa::Node *getRootNode() const; 56 | OpcUa::Node *getObjectsNode() const; 57 | CLIENT_STATE getRunState() const; 58 | CLIENT_STATUS getStatus() const; 59 | static std::string securityLevelToString(int level); 60 | 61 | private: 62 | MQTTClient *m_mqttclient; 63 | std::string m_initEndpoint; 64 | std::vector m_endpoints; 65 | OpcUa::EndpointDescription m_targetEndpoint; 66 | OpcUa::UaClient *m_client; 67 | OPCUASubClient *m_subclient; 68 | std::map> m_subs; 69 | OpcUa::Node *m_root; 70 | OpcUa::Node *m_objects; 71 | volatile CLIENT_STATE m_runstate; 72 | volatile CLIENT_STATUS m_status; 73 | 74 | protected: 75 | void run() override; 76 | 77 | }; 78 | 79 | #endif // OPCUACLIENT_H 80 | -------------------------------------------------------------------------------- /client_qt_project/opcuaepwrapper.cpp: -------------------------------------------------------------------------------- 1 | #include "opcuaepwrapper.h" 2 | 3 | // -------------------------------------------------------- 4 | // OPCUAEpWrapper class, wraps an OpcUa::EndpointDescription object into a Q_OBJECT 5 | // Stupid wrapper class to be stored as QVariant data in widgets 6 | // -------------------------------------------------------- 7 | OPCUAEpWrapper::OPCUAEpWrapper(QObject *parent, OpcUa::EndpointDescription ep) : 8 | QObject(parent), 9 | m_endpoint(ep) 10 | { 11 | 12 | } 13 | 14 | OPCUAEpWrapper::OPCUAEpWrapper(const OPCUAEpWrapper &obj) : 15 | QObject(obj.parent()), 16 | m_endpoint(obj.getEndpoint()) 17 | { 18 | 19 | } 20 | 21 | OpcUa::EndpointDescription OPCUAEpWrapper::getEndpoint() const 22 | { 23 | return m_endpoint; 24 | } 25 | -------------------------------------------------------------------------------- /client_qt_project/opcuaepwrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef OPCUAEPWRAPPER_H 2 | #define OPCUAEPWRAPPER_H 3 | 4 | #include 5 | #include 6 | 7 | // -------------------------------------------------------- 8 | // OPCUAEpWrapper class, wraps an OpcUa::EndpointDescription object into a Q_OBJECT 9 | // Stupid wrapper class to be stored as QVariant data in widgets 10 | // -------------------------------------------------------- 11 | class OPCUAEpWrapper : public QObject 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | OPCUAEpWrapper(QObject *parent = nullptr, OpcUa::EndpointDescription ep = OpcUa::EndpointDescription()); 17 | OPCUAEpWrapper(const OPCUAEpWrapper &obj); 18 | 19 | OpcUa::EndpointDescription getEndpoint() const; 20 | 21 | private: 22 | OpcUa::EndpointDescription m_endpoint; 23 | 24 | }; 25 | 26 | Q_DECLARE_METATYPE(OPCUAEpWrapper) 27 | Q_DECLARE_METATYPE(OPCUAEpWrapper *) 28 | 29 | #endif // OPCUAEPWRAPPER_H 30 | -------------------------------------------------------------------------------- /client_qt_project/opcuaepwrappercpp.cpp: -------------------------------------------------------------------------------- 1 | #include "opcuaepwrapper.h" 2 | 3 | // -------------------------------------------------------- 4 | // OPCUAEpWrapper class, wraps an OpcUa::EndpointDescription object into a Q_OBJECT 5 | // Stupid wrapper class to be stored as QVariant data in widgets 6 | // -------------------------------------------------------- 7 | OPCUAEpWrapper::OPCUAEpWrapper(QObject *parent, OpcUa::EndpointDescription ep) : 8 | QObject(parent), 9 | m_endpoint(ep) 10 | { 11 | 12 | } 13 | 14 | OPCUAEpWrapper::OPCUAEpWrapper(const OPCUAEpWrapper &obj) : 15 | QObject(obj.parent()), 16 | m_endpoint(obj.getEndpoint()) 17 | { 18 | 19 | } 20 | 21 | OpcUa::EndpointDescription OPCUAEpWrapper::getEndpoint() const 22 | { 23 | return m_endpoint; 24 | } 25 | -------------------------------------------------------------------------------- /client_qt_project/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | icon.ico 4 | 5 | 6 | -------------------------------------------------------------------------------- /images/client_hierarchy_simple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Harha/OPC-UA-to-MQTT-Gateway/7afa2157c3ae79bd1272da1d4efdfa4f7a24f05c/images/client_hierarchy_simple.png -------------------------------------------------------------------------------- /images/gateway_client_gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Harha/OPC-UA-to-MQTT-Gateway/7afa2157c3ae79bd1272da1d4efdfa4f7a24f05c/images/gateway_client_gui.png -------------------------------------------------------------------------------- /libraries/freeopcua/README.md: -------------------------------------------------------------------------------- 1 | # FreeOpcUa C++ Library 2 | 3 | https://freeopcua.github.io/ -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/common/addons_core/addon.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2011 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Addon interface definition 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __COMMON_ADDON_H__ 12 | #define __COMMON_ADDON_H__ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace Common 20 | { 21 | 22 | class Addon : private Common::Interface 23 | { 24 | public: 25 | DEFINE_CLASS_POINTERS(Addon); 26 | 27 | public: 28 | /// @brief initialize addon. 29 | /// @note Calls when all addons dependencies resolved. 30 | /// suppose that addon fully ready for work. 31 | virtual void Initialize(AddonsManager& manager, const AddonParameters& parameters) = 0; 32 | 33 | /// @brief Stopping addon work. 34 | /// After calling this method addon should throw exception on any calls. 35 | virtual void Stop() = 0; 36 | }; 37 | 38 | // @brief factory of addon. 39 | class AddonFactory : private Common::Interface 40 | { 41 | public: 42 | DEFINE_CLASS_POINTERS(AddonFactory); 43 | 44 | public: 45 | /// @brief Create instance of addon. 46 | virtual Addon::UniquePtr CreateAddon() = 0; 47 | }; 48 | 49 | } // namespace Common 50 | 51 | #endif // __COMMON_ADDON_H__ 52 | 53 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/common/addons_core/addon_manager.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2011 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Addons manager interface definition 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | 12 | #ifndef __COMMON_ADDONS_MANAGER_H__ 13 | #define __COMMON_ADDONS_MANAGER_H__ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace Common 22 | { 23 | typedef std::string AddonId; 24 | 25 | class Addon; 26 | class AddonFactory; 27 | 28 | struct AddonInformation 29 | { 30 | AddonId Id; 31 | std::shared_ptr Factory; 32 | std::vector Dependencies; 33 | AddonParameters Parameters; 34 | }; 35 | 36 | class AddonsManager : private Interface 37 | { 38 | public: 39 | DEFINE_CLASS_POINTERS(AddonsManager); 40 | 41 | public: 42 | /// @brief register new addon. 43 | /// @param addonConfiguration configuration of new addon. 44 | /// @throws if addon already redistered. If manager started thows if not all dependencies resolved. 45 | /// If manager already started addon will be immediately created and initialized. 46 | virtual void Register(const AddonInformation& caddonConfiguration) = 0; 47 | 48 | /// @brief unregister addon 49 | /// @param id id of unregistering addon 50 | /// @throws if addon not found 51 | /// For unregistering addon will be called method Addon::Stop() and addon data will be removed. 52 | virtual void Unregister(const AddonId& id) = 0; 53 | 54 | /// @brief getting addon by id 55 | /// @param id id of the required addon 56 | /// @return addon instance 57 | /// @throws if addon is not registered or not initialized yet. 58 | 59 | virtual std::shared_ptr GetAddon(const AddonId& id) const = 0; 60 | 61 | virtual std::shared_ptr GetAddon(const char id[]) const 62 | { 63 | return GetAddon(AddonId(id)); 64 | } 65 | 66 | /// @brief Get instance of addon 67 | /// @return instance of addon casted to specified type 68 | /// @throws if unable to cast addon, unable to find addon, or in casr of error 69 | template 70 | typename std::shared_ptr GetAddon(const AddonId& id) const; 71 | 72 | // template 73 | // typename std::shared_ptr GetAddon(const char* id) const; 74 | 75 | template 76 | typename std::shared_ptr GetAddon(const char id[]) const; 77 | 78 | 79 | /// @brief starting work. 80 | /// creates all addons and initializes them. 81 | /// @throws if not all addons dependencies can be resolved. 82 | virtual void Start(/*const AddonsConfiguration& config*/) = 0; 83 | 84 | // @brief Stopping all addons; 85 | virtual void Stop() = 0; 86 | }; 87 | 88 | 89 | /// @brief Get instance of addons core 90 | /// @throws in case of error 91 | /// @note Only one instance of addons manager can be at one time. 92 | /// When all smart pointers are gone addons manager deletes. 93 | AddonsManager::UniquePtr CreateAddonsManager(); 94 | 95 | template 96 | typename std::shared_ptr AddonsManager::GetAddon(const AddonId& id) const 97 | { 98 | return std::dynamic_pointer_cast(GetAddon(id)); 99 | } 100 | 101 | template 102 | typename std::shared_ptr AddonsManager::GetAddon(const char id[]) const 103 | { 104 | return std::dynamic_pointer_cast(GetAddon(AddonId(id))); 105 | } 106 | 107 | 108 | } // namespace Common 109 | 110 | #endif // __COMMON_ADDONS_MANAGER_H__ 111 | 112 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/common/addons_core/addon_parameters.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Addon parameters 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | 12 | #ifndef OPCCORE_ADDONS_CORE_ADDON_PARAMETERS_H 13 | #define OPCCORE_ADDONS_CORE_ADDON_PARAMETERS_H 14 | 15 | #include 16 | #include 17 | 18 | namespace Common 19 | { 20 | 21 | struct Parameter 22 | { 23 | std::string Name; 24 | std::string Value; 25 | 26 | Parameter() 27 | { 28 | } 29 | 30 | Parameter(const std::string& name, const std::string& value) 31 | : Name(name) 32 | , Value(value) 33 | { 34 | } 35 | }; 36 | 37 | struct ParametersGroup 38 | { 39 | std::string Name; 40 | std::vector Parameters; 41 | std::vector Groups; 42 | 43 | ParametersGroup() 44 | { 45 | } 46 | 47 | ParametersGroup(const std::string& name) 48 | : Name(name) 49 | { 50 | } 51 | }; 52 | 53 | 54 | struct AddonParameters 55 | { 56 | std::vector Groups; 57 | std::vector Parameters; 58 | }; 59 | 60 | } 61 | 62 | #endif // OPCCORE_ADDONS_CORE_ADDON_PARAMETERS_H 63 | 64 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/common/addons_core/config_file.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief OPC UA Address space part. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | namespace Common 17 | { 18 | 19 | struct ModuleConfiguration 20 | { 21 | AddonId Id; 22 | std::vector Dependencies; 23 | std::string Path; 24 | AddonParameters Parameters; 25 | }; 26 | 27 | typedef std::vector ModulesConfiguration; 28 | 29 | struct Configuration 30 | { 31 | Common::AddonParameters Parameters; 32 | std::vector Modules; 33 | }; 34 | 35 | Common::AddonInformation GetAddonInfomation(const ModuleConfiguration& config); 36 | 37 | Configuration ParseConfiguration(const std::string& configPath); 38 | void SaveConfiguration(const ModulesConfiguration& configuration, const std::string& configPath); 39 | 40 | Configuration ParseConfigurationFiles(const std::string& directory); 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/common/addons_core/dynamic_addon.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2011 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Addon interface definition 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef OPC_CORE_DYNAMIC_ADDON_H 12 | #define OPC_CORE_DYNAMIC_ADDON_H 13 | 14 | #include 15 | 16 | extern "C" Common::Addon* CreateAddon(); 17 | 18 | typedef Common::Addon* (*CreateAddonFunc)(); 19 | 20 | #endif // OPC_CORE_DYNAMIC_ADDON_H 21 | 22 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/common/addons_core/dynamic_addon_factory.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2011 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Addon interface definition 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef OPC_CORE_DYNAMIC_ADDON_FACTORY_H 12 | #define OPC_CORE_DYNAMIC_ADDON_FACTORY_H 13 | 14 | #include 15 | 16 | 17 | namespace Common 18 | { 19 | 20 | AddonFactory::UniquePtr CreateDynamicAddonFactory(const char* modulePath); 21 | 22 | inline AddonFactory::UniquePtr CreateDynamicAddonFactory(const std::string& modulePath) 23 | { 24 | return ::Common::CreateDynamicAddonFactory(modulePath.c_str()); 25 | } 26 | 27 | } 28 | 29 | #endif // OPC_CORE_DYNAMIC_ADDON_FACTORY_H 30 | 31 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/common/addons_core/errors.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2011 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Errors of Addons Manager 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | extern Common::ErrorData UnableToRegisterAddonWhenStarted; 16 | extern Common::ErrorData AddonsManagerAlreadyStarted; 17 | extern Common::ErrorData AddonsManagerAlreadyStopped; 18 | extern Common::ErrorData AddonNotFound; 19 | extern Common::ErrorData AddonNotInitializedYet; 20 | extern Common::ErrorData AddonNotRegistered; 21 | extern Common::ErrorData AddonRegisteredButShouldnt; 22 | extern Common::ErrorData AddonIsNotStarted; 23 | extern Common::ErrorData UnableToLoadDynamicLibrary; 24 | extern Common::ErrorData UnableToFundSymbolInTheLibrary; 25 | extern Common::ErrorData FailedToStartAddons; 26 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/common/class_pointers.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2011 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Exception declarations 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __class_pointers_h__74b02386_fb4e_434a_8b54_ef3a676fac54 12 | #define __class_pointers_h__74b02386_fb4e_434a_8b54_ef3a676fac54 13 | 14 | #include 15 | 16 | 17 | #define DEFINE_CLASS_POINTERS(ClassName) \ 18 | typedef std::unique_ptr UniquePtr; \ 19 | typedef std::shared_ptr SharedPtr; \ 20 | typedef std::weak_ptr WeakPtr; 21 | 22 | #endif // __class_pointers_h__74b02386_fb4e_434a_8b54_ef3a676fac54 23 | 24 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/common/errors.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2011 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Common errors declarations 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | extern Common::ErrorData InvalidValueType; 16 | extern Common::ErrorData UnsupportedFeature; 17 | extern Common::ErrorData NotImplemented; 18 | extern Common::ErrorData StdException; 19 | extern Common::ErrorData OsError; 20 | extern Common::ErrorData CannotParseUri; 21 | extern Common::ErrorData ApplicationAlreayStarted; 22 | extern Common::ErrorData ApplicationNotStarted; 23 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/common/interface.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2012 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Interface base class. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __OPC_UA_INTERFACE_BASE_H__ 12 | #define __OPC_UA_INTERFACE_BASE_H__ 13 | 14 | namespace Common 15 | { 16 | 17 | class Interface 18 | { 19 | protected: 20 | Interface(){} 21 | virtual ~Interface(){} 22 | 23 | Interface(const Interface&) = delete; 24 | const Interface& operator=(const Interface&) = delete; 25 | }; 26 | 27 | } 28 | 29 | #endif // __OPC_UA_INTERFACE_BASE_H__ 30 | 31 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/common/modules.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2011 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief modules identifiers. Used for building error codes. 4 | /// Modules are parts of project not addons. 5 | /// @license GNU LGPL 6 | /// 7 | /// Distributed under the GNU LGPL License 8 | /// (See accompanying file LICENSE or copy at 9 | /// http://www.gnu.org/licenses/lgpl.html) 10 | /// 11 | 12 | #ifndef __modules_h__f01eb2ae_a824_4dc3_a0f2_bf586d241024 13 | #define __modules_h__f01eb2ae_a824_4dc3_a0f2_bf586d241024 14 | 15 | namespace Common 16 | { 17 | enum Modules 18 | { 19 | MODULE_OS = 0, 20 | MODULE_COMMON, 21 | MODULE_ADDONS_MANAGER, 22 | MODULE_OPCUA_CORE, 23 | MODULE_OPCUA_Client, 24 | }; 25 | } 26 | 27 | #endif // __modules_h__f01eb2ae_a824_4dc3_a0f2_bf586d241024 28 | 29 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/common/object_id.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2011 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Object Id definitions. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __object_id_h__63482305_9391_49bb_af9c_34e95a1abd31 12 | #define __object_id_h__63482305_9391_49bb_af9c_34e95a1abd31 13 | 14 | namespace Common 15 | { 16 | typedef unsigned ObjectId; 17 | 18 | ObjectId GenerateNewId(); 19 | } 20 | 21 | 22 | #endif // __object_id_h__63482305_9391_49bb_af9c_34e95a1abd31 23 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/common/thread.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2012 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Thread wrapper with coockies. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | namespace Common 20 | { 21 | 22 | class ThreadObserver : private Common::Interface 23 | { 24 | public: 25 | /// @brief thread exited with Success. 26 | virtual void OnSuccess() = 0; 27 | /// @brief Thread exited with error. 28 | virtual void OnError(const std::exception& exc) = 0; 29 | }; 30 | 31 | typedef std::function ThreadProc; 32 | 33 | class Thread 34 | { 35 | public: 36 | DEFINE_CLASS_POINTERS(Thread); 37 | 38 | public: 39 | /// @brief Starts f in a separate thread. 40 | Thread(std::function f, ThreadObserver* observer = 0); 41 | 42 | static Thread::UniquePtr Create(ThreadProc f, ThreadObserver* observer = 0) 43 | { 44 | return Thread::UniquePtr(new Thread(f, observer)); 45 | } 46 | 47 | static Thread::UniquePtr Create(void (*f)(), ThreadObserver* observer = 0) 48 | { 49 | Common::ThreadProc proc(f); 50 | return Thread::UniquePtr(new Common::Thread(proc, observer)); 51 | } 52 | 53 | ~Thread(); 54 | /// @brief Wait until started thread stop. 55 | void Join(); 56 | 57 | public: 58 | /// @brief Calls in the separate thread from ThreadProc. 59 | void Run(); 60 | /// @brief static member required for std::thread 61 | static void ThreadProc(Thread* thread); 62 | 63 | private: 64 | ThreadObserver* Observer; 65 | Common::ThreadProc Func; 66 | std::thread Impl; 67 | }; 68 | 69 | } // namespace Common 70 | 71 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/common/uri_facade.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Uri. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | namespace Common 16 | { 17 | 18 | class Uri 19 | { 20 | public: 21 | explicit Uri(const std::string& uriString) 22 | { 23 | Initialize(uriString.c_str(), uriString.size()); 24 | } 25 | 26 | explicit Uri(const char* uriString) 27 | { 28 | Initialize(uriString, 0); 29 | } 30 | 31 | std::string Scheme() const 32 | { 33 | return SchemeStr; 34 | } 35 | 36 | std::string User() const 37 | { 38 | return UserStr; 39 | } 40 | 41 | std::string Password() const 42 | { 43 | return PasswordStr; 44 | } 45 | 46 | std::string Host() const 47 | { 48 | return HostStr; 49 | } 50 | 51 | unsigned Port() const 52 | { 53 | return PortNum; 54 | } 55 | 56 | private: 57 | void Initialize(const char* uriString, std::size_t len); 58 | 59 | private: 60 | std::string SchemeStr; 61 | std::string UserStr; 62 | std::string PasswordStr; 63 | std::string HostStr; 64 | unsigned PortNum; 65 | }; 66 | 67 | } // namespace Common 68 | 69 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/client/addon.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief OPC UA Address space part. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace OpcUa 19 | { 20 | namespace Client 21 | { 22 | class Addon : public Common::Addon 23 | { 24 | public: 25 | DEFINE_CLASS_POINTERS(Addon); 26 | 27 | public: 28 | virtual std::string GetProtocol() const = 0; 29 | virtual OpcUa::Services::SharedPtr Connect(const std::string& url) = 0; 30 | }; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/client/binary_client.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Opc Ua server interface. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | 16 | 17 | #include 18 | 19 | namespace OpcUa 20 | { 21 | 22 | struct SecureConnectionParams 23 | { 24 | std::string EndpointUrl; 25 | std::string SecurePolicy; 26 | std::vector SenderCertificate; 27 | std::vector ReceiverCertificateThumbPrint; 28 | uint32_t SecureChannelId; 29 | 30 | SecureConnectionParams() 31 | : SecureChannelId(0) 32 | { 33 | } 34 | }; 35 | 36 | /// @brief Create server based on opc ua binary protocol. 37 | /// @param channel channel wich will be used for sending requests data. 38 | Services::SharedPtr CreateBinaryClient(IOChannel::SharedPtr channel, const SecureConnectionParams& params, bool debug = false); 39 | Services::SharedPtr CreateBinaryClient(const std::string& endpointUrl, bool debug = false); 40 | 41 | } // namespace OpcUa 42 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/client/client.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (C) 2014-2014 by Sintef Raufoss Manufacturing * 3 | * olivier.roulet@gmail.com * 4 | * * 5 | * This library is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU Lesser General Public License as * 7 | * published by the Free Software Foundation; version 3 of the License. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesser General Public License for more details. * 13 | * * 14 | * You should have received a copy of the GNU Lesser General Public License * 15 | * along with this library; if not, write to the * 16 | * Free Software Foundation, Inc., * 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 | ******************************************************************************/ 19 | 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | namespace OpcUa 36 | { 37 | 38 | class KeepAliveThread 39 | { 40 | public: 41 | /// @brief Internal 42 | // Send keepalive request to server so it does not disconnect us 43 | KeepAliveThread(bool debug=false) : StopRequest(false), Running(false), Debug(debug) {} 44 | void Start( Services::SharedPtr server, Node node, Duration period); 45 | void Stop(); 46 | 47 | private: 48 | void Run(); 49 | mutable std::thread Thread; 50 | Node NodeToRead; 51 | Services::SharedPtr Server; 52 | Duration Period = 1200000; 53 | std::atomic StopRequest; 54 | std::atomic Running; 55 | std::condition_variable Condition; 56 | std::mutex Mutex; 57 | bool Debug = false; 58 | }; 59 | 60 | 61 | class UaClient 62 | { 63 | public: 64 | /// @brief create high level client 65 | /// this class is meant to be used to quickly/easily connect to an OPCUA server 66 | /// it may not offer absolutely all features available in protocol 67 | /// you may want to look at code and implement your own client if you need 68 | /// debug argument will make freeopcua write A LOT to stdout 69 | /// set endpoint uri on wich server will listen. 70 | /// opc.tcp://localhost:4841/opcua/server 71 | /// opc.tcp://192.168.1.1:4840/opcua/server 72 | /// opc.tcp://server.freeopca.org:4841/opcua/server 73 | UaClient(bool debug=false) : KeepAlive(debug), Debug(debug) {} 74 | ~UaClient(); 75 | 76 | UaClient(const UaClient&&) = delete; 77 | UaClient(const UaClient&) = delete; 78 | UaClient& operator=(const UaClient&) = delete; 79 | 80 | /// @brief set session name 81 | void SetSessionName(const std::string& str) { SessionName = str; } 82 | std::string GetSessionName() const { return SessionName; } 83 | 84 | /// @brief connect to a server, specify endpoint as string 85 | // a connection will be made to server to get endpoint description 86 | // an endpoint description will be selected and then a connection will attempted 87 | void Connect(const std::string& endpoint); 88 | 89 | /// @brief connect to a server, specify endpoint as EndpointDesciption 90 | // EndpointDescription can be defined by hand or gotten through 91 | // a call to GetServerEndpoints() 92 | void Connect(const EndpointDescription&); 93 | 94 | /// @brief Disconnect from server 95 | // close communication with OPC-UA server, close all threads and subscriptions 96 | void Disconnect(); 97 | 98 | /// @brief Abort server connection 99 | // abort communication with OPC-UA server, close all threads and subcsriptions 100 | // Like Disconnect() but without CloseSession() call, which is not possible on faulty connection anyway 101 | void Abort(); 102 | 103 | /// @brief Connect to server and get endpoints 104 | std::vector GetServerEndpoints(const std::string& endpoint); 105 | 106 | /// @brief Connect to server and select one endpoint 107 | EndpointDescription SelectEndpoint(const std::string&); 108 | 109 | /// @brief get endpoints from server, assume we are already connected 110 | std::vector GetServerEndpoints(); 111 | std::string GetEndpoint() const { return Endpoint.EndpointUrl; } 112 | 113 | /// @brief set application description 114 | std::string GetApplicationURI() const { return ApplicationUri; } 115 | void SetApplicationURI(std::string uri) { ApplicationUri = uri; } 116 | std::string GetProductURI() const { return ProductUri; } 117 | void SetProductURI(std::string uri) { ProductUri = uri; } 118 | 119 | /// @brief set security policy 120 | // anyway freeopcua currently only support MessageSecurityMode::None 121 | void SetSecurityPolicy(std::string sec) {SecurityPolicy = sec;} 122 | std::string GetSecurityPolicy() const { return SecurityPolicy; } 123 | 124 | /// @brief Get namespaces used by server. 125 | // Deduce index from order or call GetNamespaceIndex(uri) 126 | std::vector GetServerNamespaces(); 127 | uint32_t GetNamespaceIndex(std::string uri); 128 | 129 | /// @brief Get a specific node by nodeid 130 | // you can also access a standard node from addressspace using 131 | // ObjectId, for example: 132 | // Node mynode = GetNode(ObjectId::Server); 133 | // using a string is also possible: 134 | // Node mynode = GetNode("ns=3;i=55"); 135 | Node GetNode(const NodeId& nodeid) const; 136 | Node GetNode(const std::string& nodeid) const; 137 | 138 | /// @brief helper methods for node you will probably want to access 139 | Node GetRootNode() const; 140 | Node GetObjectsNode() const; 141 | Node GetServerNode() const; 142 | 143 | 144 | /// @brief Create a subscription objects 145 | // returned object can then be used to subscribe 146 | // to datachange or custom events from server 147 | std::unique_ptr CreateSubscription(unsigned int period, SubscriptionHandler& client); 148 | 149 | /// @brief Create a server operations object 150 | ServerOperations CreateServerOperations(); 151 | 152 | private: 153 | void OpenSecureChannel(); 154 | void CloseSecureChannel(); 155 | 156 | EndpointDescription Endpoint; 157 | // defined some sensible defaults that should let us connect to most servers 158 | std::string SessionName = "Open source OPC-UA Client Session"; 159 | std::string ApplicationUri = "urn:freeopcua:client"; 160 | std::string ProductUri = "urn:freeopcua.github.no:client"; 161 | std::string SecurityPolicy = "none"; 162 | KeepAliveThread KeepAlive; 163 | uint32_t SecureChannelId; 164 | bool Debug = false; 165 | uint32_t DefaultTimeout = 3600000; 166 | 167 | protected: 168 | Services::SharedPtr Server; 169 | 170 | }; 171 | 172 | } // namespace OpcUa 173 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/client/remote_connection.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2012 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Opc binary cnnection channel. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __OPC_UA_BINARY_CHANNEL 12 | #define __OPC_UA_BINARY_CHANNEL 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | namespace OpcUa 20 | { 21 | 22 | class RemoteConnection : public IOChannel 23 | { 24 | public: 25 | virtual std::size_t Receive(char* data, std::size_t size) = 0; 26 | virtual void Send(const char* message, std::size_t size) = 0; 27 | 28 | virtual std::string GetHost() const = 0; 29 | virtual unsigned GetPort() const = 0; 30 | }; 31 | 32 | 33 | std::unique_ptr Connect(const std::string& host, unsigned port); 34 | 35 | } // namespace OpcUa 36 | 37 | #endif // __OPC_UA_BINARY_CHANNEL 38 | 39 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/connection_listener.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2012 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Opc binary cnnection channel. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | namespace OpcUa 19 | { 20 | namespace Server 21 | { 22 | 23 | class IncomingConnectionProcessor : private Common::Interface 24 | { 25 | public: 26 | virtual void Process(IOChannel::SharedPtr clientChannel) = 0; 27 | virtual void StopProcessing(IOChannel::SharedPtr clientChannel) = 0; 28 | }; 29 | 30 | class ConnectionListener : private Common::Interface 31 | { 32 | public: 33 | virtual void Start(std::shared_ptr connectionProcssor) = 0; 34 | virtual void Stop() = 0; 35 | }; 36 | 37 | } // namespace UaServer 38 | } // namespace OpcUA 39 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/errors.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2011 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Common errors declarations 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | #define DEFINE_COMMON_ERROR(name) extern Common::ErrorData name; 16 | 17 | DEFINE_COMMON_ERROR(CannotCreateChannelOnInvalidSocket); 18 | 19 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/event.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | 13 | 14 | namespace OpcUa 15 | { 16 | typedef std::map, Variant> PathMap; 17 | typedef std::map AttributeMap; 18 | 19 | class Event 20 | { 21 | 22 | public: 23 | //Instanciate a new event object 24 | //The optional argument is the type of the event 25 | //If not set BaseEventType is used 26 | //If you want to send custom data, you need custom event type on server 27 | //The attributes of BaseEventType are accesible as class member, 28 | //Other attributes must be set using SetValue and accessed using GetValue 29 | // This API is a draft, it WILL change 30 | Event(const Node& type); 31 | Event(const NodeId& type); 32 | Event(); 33 | 34 | //Attributes of an BaseEventType 35 | ByteString EventId; //unique id 36 | NodeId EventType; //The type of event, defines attribues, connections, ... 37 | DateTime LocalTime; //Time zone information 38 | DateTime ReceiveTime; //Time at which the server received the event 39 | DateTime Time; //Time at which the event occured, should come from underlying system 40 | LocalizedText Message; //human readable event description 41 | uint16_t Severity = 1; //Priority, from 1 to 1000. 1 is lowest priority 42 | NodeId SourceNode; //The node that has generated the event 43 | std::string SourceName; //Description of the source 44 | 45 | 46 | //Set value of a variable(or object) 47 | //This value will be used when the event is fired 48 | //You can set arbitrary data, but clients will not be able to discover them thus subscribe to them 49 | void SetValue(const std::vector& path, Variant value); 50 | void SetValue(AttributeId attribute, Variant value); 51 | void SetValue(const QualifiedName& path, Variant value); 52 | void SetValue(const std::string& qualifiedname, Variant value); //helper method for the most common case 53 | 54 | //Return value og variable identified by its relative path 55 | //or value of attribute identified by its Id 56 | //returns null variant if no match 57 | Variant GetValue(const std::vector& path) const; 58 | Variant GetValue(AttributeId attribute) const; 59 | Variant GetValue(const QualifiedName& path) const; 60 | Variant GetValue(const std::string& qualifiedname) const; //helper method for the most common case 61 | 62 | //Get the list of available values in this event 63 | std::vector> GetValueKeys(); 64 | 65 | protected: 66 | PathMap PathValues; 67 | AttributeMap AttributeValues; 68 | }; 69 | 70 | std::string ToString(const Event& event); 71 | 72 | inline std::ostream& operator<<(std::ostream& os, const Event& event) 73 | { 74 | os << "{" << ToString(event) << "}"; 75 | return os; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/global.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (C) 2014-2014 Olivier Roulet-Dubonnet * 3 | * olivier.roulet@gmail.com * 4 | * * 5 | * This library is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU Lesser General Public License as * 7 | * published by the Free Software Foundation; version 3 of the License. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesser General Public License for more details. * 13 | * * 14 | * You should have received a copy of the GNU Lesser General Public License * 15 | * along with this library; if not, write to the * 16 | * Free Software Foundation, Inc., * 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 | ******************************************************************************/ 19 | 20 | #pragma once 21 | 22 | # define OPCUA_UNUSED(x) (void)x 23 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/node.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (C) 2014-2014 Olivier Roulet-Dubonnet * 3 | * olivier.roulet@gmail.com * 4 | * * 5 | * This library is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU Lesser General Public License as * 7 | * published by the Free Software Foundation; version 3 of the License. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesser General Public License for more details. * 13 | * * 14 | * You should have received a copy of the GNU Lesser General Public License * 15 | * along with this library; if not, write to the * 16 | * Free Software Foundation, Inc., * 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 | ******************************************************************************/ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | #include 25 | 26 | 27 | namespace OpcUa 28 | { 29 | 30 | class NodeNotFoundException : public std::runtime_error 31 | { 32 | public: 33 | NodeNotFoundException() : std::runtime_error("NodeNotFoundException") { } 34 | }; 35 | 36 | /// @brief A Node object represent an OPC-UA node. 37 | /// It is high level object intended for developper who want to expose 38 | /// data through OPC-UA or read data from an OPCUA server. 39 | /// Node are usually not create directly but obtained through call 40 | /// to GetRootNode of GetObjectsNode on server or client side 41 | 42 | class Node 43 | { 44 | public: 45 | // Creating Root Node. 46 | explicit Node(Services::SharedPtr srv); 47 | Node(Services::SharedPtr srv, const NodeId& id); 48 | Node(const Node& other); 49 | Node(){} 50 | 51 | NodeId GetId() const; 52 | 53 | QualifiedName GetBrowseName() const; 54 | //void SetBrowseName(const QualifiedName& name) const; 55 | 56 | /// @brief List childrenn nodes by specified reference 57 | /// @return One or zero chilren nodes. 58 | std::vector GetChildren(const OpcUa::ReferenceId& refid) const; 59 | 60 | /// @brief Get ghildren by hierarchal referencies. 61 | /// @return One or zero chilren nodes. 62 | std::vector GetChildren() const; 63 | 64 | //The GetChildNode methods return a node defined by its path from the node. A path is defined by 65 | // a sequence of browse name(QualifiedName). A browse name is either defined through a qualifiedname object 66 | // or a string of format namespace:browsename. If a namespace is not specified it is assumed to be 67 | //the same as the parent 68 | Node GetChild(const std::vector& path) const; 69 | Node GetChild(const std::vector& path) const; 70 | Node GetChild(const std::string& browsename) const ; 71 | 72 | std::vector GetProperties() const {return GetChildren(OpcUa::ReferenceId::HasProperty);} 73 | std::vector GetVariables() const {return GetChildren(OpcUa::ReferenceId::HasComponent);} //Not correct should filter by variable type 74 | 75 | 76 | 77 | //TODO: How to get References? 78 | 79 | //The Read and Write methods read or write attributes of the node 80 | //FIXME: add possibility to read and write several nodes at once 81 | DataValue GetAttribute(const AttributeId attr) const; 82 | void SetAttribute(AttributeId attr, const DataValue &dval) const; 83 | //std::vector WriteAttrs(OpcUa::AttributeId attr, const Variant &val); 84 | 85 | //Helper method to get/set VALUE attribute of a node (Not all nodes support VALUE attribute) 86 | Variant GetValue() const; 87 | DataValue GetDataValue() const; 88 | void SetValue(const Variant& val) const; 89 | void SetValue(const DataValue& dval) const; 90 | 91 | Variant GetDataType() const; 92 | 93 | // CallMethod 94 | std::vector CallMethod(NodeId methodId, std::vector inputArguments) const; 95 | std::vector> CallMethods(std::vector methodIds, std::vector> inputArguments) const; 96 | 97 | //OpcUa low level methods to to modify address space model 98 | std::vector AddNodes(std::vector items) const; 99 | std::vector AddReferences(std::vector items) const; 100 | 101 | 102 | //Helper classes to modify address space model 103 | Node AddFolder(const NodeId& folderId, const QualifiedName& browseName) const; 104 | Node AddFolder(const std::string& nodeid, const std::string& browseName) const; 105 | Node AddFolder(uint32_t namespaceidx, const std::string& browseName) const; 106 | 107 | Node AddObject(const NodeId& folderId, const QualifiedName& browseName) const; 108 | Node AddObject(const std::string& nodeid, const std::string& browseName) const; 109 | Node AddObject(uint32_t namespaceidx, const std::string& browseName) const; 110 | 111 | Node AddVariable(const NodeId& variableId, const QualifiedName& browsename, const Variant& val) const; 112 | Node AddVariable(uint32_t namespaceidx, const std::string& BrowseName, const Variant& val) const; 113 | Node AddVariable(const std::string& nodeId, const std::string& browseName, const Variant& val) const; 114 | 115 | Node AddProperty(const NodeId& propertyId, const QualifiedName& browsename, const Variant& val) const; 116 | Node AddProperty(const std::string& nodeid, const std::string& browseName, const Variant& val) const; 117 | Node AddProperty(uint32_t namespaceidx, const std::string& browseName, const Variant& val) const; 118 | 119 | Node AddMethod(const NodeId& variableId, const QualifiedName& browsename, std::function (std::vector arguments)> method) const; 120 | Node AddMethod(uint32_t namespaceidx, const std::string& BrowseName, std::function (std::vector arguments)> method) const; 121 | Node AddMethod(const std::string& nodeId, const std::string& browseName, std::function (std::vector arguments)> method) const; 122 | 123 | std::string ToString() const; 124 | 125 | bool operator==(Node const& x) const { return Id == x.Id; } 126 | bool operator!=(Node const& x) const { return Id != x.Id; } 127 | 128 | //FIXME: I need this to create a copy for python binding, another way? 129 | OpcUa::Services::SharedPtr GetServices() const {return Server;} 130 | 131 | protected: 132 | OpcUa::Services::SharedPtr Server; 133 | NodeId Id; 134 | }; 135 | 136 | 137 | std::ostream& operator<<(std::ostream& os, const Node& node); 138 | 139 | //FIXME: The following methods should be moved somewhere else!!! 140 | 141 | ObjectId VariantTypeToDataType(VariantType vt); 142 | 143 | 144 | } // namespace OpcUa 145 | 146 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/attribute_ids.h: -------------------------------------------------------------------------------- 1 | // 2 | // DO NOT EDIT THIS FILE! 3 | // It is automatically generated from opcfoundation.org schemas. 4 | // 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace OpcUa 11 | { 12 | enum class AttributeId : uint32_t 13 | { 14 | NodeId = 1, 15 | NodeClass = 2, 16 | BrowseName = 3, 17 | DisplayName = 4, 18 | Description = 5, 19 | WriteMask = 6, 20 | UserWriteMask = 7, 21 | IsAbstract = 8, 22 | Symmetric = 9, 23 | InverseName = 10, 24 | ContainsNoLoops = 11, 25 | EventNotifier = 12, 26 | Value = 13, 27 | DataType = 14, 28 | ValueRank = 15, 29 | ArrayDimensions = 16, 30 | AccessLevel = 17, 31 | UserAccessLevel = 18, 32 | MinimumSamplingInterval = 19, 33 | Historizing = 20, 34 | Executable = 21, 35 | UserExecutable = 22, 36 | Unknown = ~uint32_t(), 37 | }; 38 | } // namespace OpcUa 39 | 40 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/binary/common.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2012 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Opc binary messages. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __OPC_UA_BINARY_COMMON_H__ 12 | #define __OPC_UA_BINARY_COMMON_H__ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace OpcUa 24 | { 25 | namespace Binary 26 | { 27 | template 28 | std::size_t RawSize(const T& obj); 29 | 30 | template 31 | std::size_t RawSizeContainer(const T& container) 32 | { 33 | const std::size_t headerSize = 4; 34 | std::size_t totalSize = headerSize; 35 | std::for_each(container.begin(), container.end(), [&] (const typename T::value_type& val) {totalSize += RawSize(val);}); 36 | return totalSize; 37 | } 38 | 39 | 40 | enum MessageType 41 | { 42 | MT_INVALID = 0, 43 | MT_HELLO = 1, 44 | MT_ACKNOWLEDGE, 45 | MT_ERROR, 46 | MT_SECURE_OPEN, 47 | MT_SECURE_CLOSE, 48 | MT_SECURE_MESSAGE, 49 | }; 50 | 51 | enum ChunkType 52 | { 53 | CHT_INVALID = 0, 54 | CHT_SINGLE = 1, 55 | CHT_INTERMEDIATE, 56 | CHT_FINAL, 57 | }; 58 | 59 | struct Header 60 | { 61 | MessageType Type; 62 | ChunkType Chunk; 63 | uint32_t Size; 64 | 65 | Header(); 66 | explicit Header(MessageType type, ChunkType chunk); 67 | std::size_t AddSize(std::size_t size); 68 | std::size_t MessageSize() const; 69 | void ResetSize(); 70 | }; 71 | 72 | 73 | // Hello 74 | // os << Header << Hello << flush 75 | // is >> Header >> Acknowledge; 76 | 77 | struct Hello 78 | { 79 | uint32_t ProtocolVersion; 80 | uint32_t ReceiveBufferSize; 81 | uint32_t SendBufferSize; 82 | uint32_t MaxMessageSize; 83 | uint32_t MaxChunkCount; 84 | std::string EndpointUrl; 85 | 86 | Hello(); 87 | }; 88 | 89 | struct Acknowledge 90 | { 91 | uint32_t ProtocolVersion; 92 | uint32_t ReceiveBufferSize; 93 | uint32_t SendBufferSize; 94 | uint32_t MaxMessageSize; 95 | uint32_t MaxChunkCount; 96 | 97 | Acknowledge(); 98 | }; 99 | 100 | struct Error 101 | { 102 | uint32_t Code; 103 | std::string Reason; 104 | 105 | Error(); 106 | }; 107 | 108 | struct SecureHeader 109 | { 110 | MessageType Type; 111 | ChunkType Chunk; 112 | uint32_t Size; 113 | uint32_t ChannelId; 114 | 115 | SecureHeader(); 116 | explicit SecureHeader(MessageType type, ChunkType chunk, uint32_t channelId); 117 | 118 | std::size_t AddSize(std::size_t size); 119 | std::size_t MessageSize() const; 120 | void ResetSize(); 121 | }; 122 | 123 | struct AsymmetricAlgorithmHeader 124 | { 125 | std::string SecurityPolicyUri; 126 | std::vector SenderCertificate; 127 | std::vector ReceiverCertificateThumbPrint; 128 | }; 129 | 130 | struct SymmetricAlgorithmHeader 131 | { 132 | uint32_t TokenId; 133 | 134 | SymmetricAlgorithmHeader(); 135 | }; 136 | 137 | struct SequenceHeader 138 | { 139 | uint32_t SequenceNumber; 140 | uint32_t RequestId; 141 | 142 | SequenceHeader(); 143 | }; 144 | 145 | } // namespace Binary 146 | } // namespace OpcUa 147 | 148 | 149 | #endif // __OPC_UA_BINARY_COMMON_H__ 150 | 151 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/binary/stream.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2012 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Opc binary stream. 4 | /// Stream classes perform Serialization/Deserialization of opc ua structures. 5 | /// @license GNU LGPL 6 | /// 7 | /// Distributed under the GNU LGPL License 8 | /// (See accompanying file LICENSE or copy at 9 | /// http://www.gnu.org/licenses/lgpl.html) 10 | /// 11 | 12 | 13 | #ifndef __OPC_UA_MAPPING_SERIALIZE_H__ 14 | #define __OPC_UA_MAPPING_SERIALIZE_H__ 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | #define OPCUA_DEFAULT_BUFFER_SIZE 4096 23 | 24 | namespace OpcUa 25 | { 26 | namespace Binary 27 | { 28 | 29 | class DataSerializer 30 | { 31 | public: 32 | explicit DataSerializer(std::size_t defBufferSize = OPCUA_DEFAULT_BUFFER_SIZE) 33 | { 34 | Buffer.reserve(defBufferSize); 35 | } 36 | 37 | template 38 | DataSerializer& operator<<(const T& value) 39 | { 40 | Serialize(value); 41 | return *this; 42 | } 43 | 44 | template 45 | void Flush(Acceptor& aceptor) 46 | { 47 | aceptor.Send(&Buffer[0], Buffer.size()); 48 | Buffer.clear(); 49 | } 50 | 51 | template 52 | void Serialize(const T& value); 53 | 54 | private: 55 | std::vector Buffer; 56 | }; 57 | 58 | class DataSupplier 59 | { 60 | public: 61 | virtual size_t Read(char* buffer, size_t size) = 0; 62 | }; 63 | 64 | class DataDeserializer 65 | { 66 | public: 67 | DataDeserializer(DataSupplier& supplier) 68 | : In(supplier) 69 | { 70 | } 71 | 72 | virtual ~DataDeserializer() 73 | { 74 | } 75 | 76 | template 77 | DataDeserializer& operator>>(T& value) 78 | { 79 | Deserialize(value); 80 | return *this; 81 | } 82 | 83 | template 84 | void Deserialize(T&); 85 | 86 | private: 87 | DataSupplier& In; 88 | }; 89 | 90 | 91 | struct RawMessage 92 | { 93 | const char* Data; 94 | std::size_t Size; 95 | 96 | RawMessage(const char* data, std::size_t size) 97 | : Data(data) 98 | , Size(size) 99 | { 100 | } 101 | }; 102 | 103 | 104 | template 105 | class OStream 106 | { 107 | public: 108 | explicit OStream(std::shared_ptr channel) 109 | : Out(*channel) 110 | , Holder(channel) 111 | { 112 | } 113 | 114 | explicit OStream(OutputChannelType& channel) 115 | : Out(channel) 116 | { 117 | } 118 | 119 | virtual ~OStream() 120 | { 121 | } 122 | 123 | template 124 | OStream& operator<<(const T& value) 125 | { 126 | Serializer << value; 127 | return *this; 128 | } 129 | 130 | OStream& operator<< (OStream& (*pf)(OStream& out)) 131 | { 132 | return pf(*this); 133 | } 134 | 135 | void Flush() 136 | { 137 | Serializer.Flush(Out); 138 | } 139 | 140 | private: 141 | OutputChannelType& Out; 142 | std::shared_ptr Holder; 143 | DataSerializer Serializer; 144 | }; 145 | 146 | template 147 | inline OStream& flush(OStream& os) 148 | { 149 | os.Flush(); 150 | return os; 151 | } 152 | 153 | struct RawBuffer 154 | { 155 | char* Data; 156 | std::size_t Size; 157 | 158 | RawBuffer(char* data, std::size_t size) 159 | : Data(data) 160 | , Size(size) 161 | { 162 | } 163 | }; 164 | 165 | 166 | template 167 | class IStream : private DataSupplier 168 | { 169 | public: 170 | explicit IStream(std::shared_ptr channel) 171 | : In(*channel) 172 | , Holder(channel) 173 | , Deserializer(*this) 174 | { 175 | } 176 | 177 | explicit IStream(InputChannelType& channel) 178 | : In(channel) 179 | , Deserializer(*this) 180 | { 181 | } 182 | 183 | virtual ~IStream() 184 | { 185 | } 186 | 187 | template 188 | IStream& operator>>(T& value) 189 | { 190 | Deserializer >> value; 191 | return *this; 192 | } 193 | 194 | private: 195 | virtual size_t Read(char* buffer, size_t size) 196 | { 197 | return In.Receive(buffer, size); 198 | } 199 | 200 | private: 201 | InputChannelType& In; 202 | std::shared_ptr Holder; 203 | DataDeserializer Deserializer; 204 | }; 205 | 206 | 207 | template 208 | class IOStream : public IStream, public OStream 209 | { 210 | public: 211 | IOStream(std::shared_ptr channel) 212 | : IStream(channel) 213 | , OStream(channel) 214 | { 215 | } 216 | }; 217 | 218 | template 219 | class InputOutputStream : public IStream, public OStream 220 | { 221 | public: 222 | InputOutputStream(std::shared_ptr input, std::shared_ptr output) 223 | : IStream(input) 224 | , OStream(output) 225 | { 226 | } 227 | }; 228 | 229 | typedef OpcUa::Binary::IOStream IOStreamBinary; 230 | typedef OpcUa::Binary::IStream IStreamBinary; 231 | typedef OpcUa::Binary::OStream OStreamBinary; 232 | 233 | } // namespace Binary 234 | } // namespace OpcUa 235 | 236 | #endif // __OPC_UA_MAPPING_SERIALIZE_H__ 237 | 238 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/channel.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2012 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Input/output channels interfaces. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace OpcUa 19 | { 20 | 21 | class BreakableChannel 22 | { 23 | public: 24 | virtual ~BreakableChannel(){} 25 | BreakableChannel(){} 26 | BreakableChannel(const BreakableChannel&) = delete; 27 | BreakableChannel(BreakableChannel&&) = delete; 28 | BreakableChannel& operator=(const BreakableChannel&) = delete; 29 | 30 | public: 31 | virtual void Stop() = 0; 32 | }; 33 | 34 | 35 | class InputChannel : public virtual BreakableChannel 36 | { 37 | public: 38 | typedef std::shared_ptr SharedPtr; 39 | typedef std::unique_ptr UniquePtr; 40 | 41 | public: 42 | virtual ~InputChannel(){} 43 | InputChannel(){} 44 | InputChannel(const InputChannel&) = delete; 45 | InputChannel(InputChannel&&) = delete; 46 | InputChannel& operator=(const InputChannel&) = delete; 47 | 48 | public: 49 | /// @brief Receive data 50 | /// @param data data for send 51 | /// @param size size of data 52 | /// @return size of received data 53 | virtual std::size_t Receive(char* data, std::size_t size) = 0; 54 | }; 55 | 56 | 57 | class OutputChannel : public virtual BreakableChannel 58 | { 59 | public: 60 | typedef std::shared_ptr SharedPtr; 61 | typedef std::unique_ptr UniquePtr; 62 | 63 | public: 64 | virtual ~OutputChannel(){} 65 | 66 | OutputChannel(){} 67 | OutputChannel(const OutputChannel&) = delete; 68 | OutputChannel(OutputChannel&&) = delete; 69 | OutputChannel& operator=(const OutputChannel&) = delete; 70 | 71 | public: 72 | virtual void Send(const char* message, std::size_t size) = 0; 73 | }; 74 | 75 | 76 | class IOChannel : 77 | public InputChannel, 78 | public OutputChannel 79 | { 80 | public: 81 | typedef std::shared_ptr SharedPtr; 82 | typedef std::unique_ptr UniquePtr; 83 | }; 84 | 85 | } 86 | 87 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/data_value.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief C++ types of binary protocol. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __OPC_UA_DATA_VALUE_H__ 12 | #define __OPC_UA_DATA_VALUE_H__ 13 | 14 | #include 15 | 16 | namespace OpcUa 17 | { 18 | const uint8_t DATA_VALUE = 1; 19 | const uint8_t DATA_VALUE_STATUS_CODE = 2; 20 | const uint8_t DATA_VALUE_SOURCE_TIMESTAMP = 4; 21 | const uint8_t DATA_VALUE_Server_TIMESTAMP = 8; 22 | const uint8_t DATA_VALUE_SOURCE_PICOSECONDS = 16; 23 | const uint8_t DATA_VALUE_Server_PICOSECONDS = 32; 24 | const uint8_t DATA_VALUE_ALL = ~uint8_t(); 25 | 26 | struct DataValue 27 | { 28 | uint8_t Encoding; 29 | Variant Value; 30 | StatusCode Status; 31 | DateTime SourceTimestamp; 32 | uint16_t SourcePicoseconds; 33 | DateTime ServerTimestamp; 34 | uint16_t ServerPicoseconds; 35 | 36 | DataValue() 37 | : Encoding(0) 38 | , Status(StatusCode::Good) 39 | , SourceTimestamp(0) 40 | , SourcePicoseconds(0) 41 | , ServerTimestamp(0) 42 | , ServerPicoseconds(0) 43 | { 44 | } 45 | 46 | DataValue(const DataValue& data) = default; 47 | 48 | explicit DataValue(const Variant& value) 49 | : DataValue() 50 | { 51 | Value = value; 52 | Encoding |= DATA_VALUE; 53 | } 54 | 55 | template 56 | explicit DataValue(const T val) 57 | : DataValue() 58 | { 59 | Value = Variant(val); 60 | Encoding |= DATA_VALUE; 61 | } 62 | 63 | DataValue& operator= (const Variant& value) 64 | { 65 | Value = value; 66 | Encoding |= DATA_VALUE; 67 | return *this; 68 | } 69 | 70 | template 71 | DataValue& operator= (const T& value) 72 | { 73 | Value = Variant(value); 74 | Encoding |= DATA_VALUE; 75 | return *this; 76 | } 77 | 78 | template 79 | bool operator== (const T& t) const 80 | { 81 | return (Encoding & DATA_VALUE) && Value == t; 82 | } 83 | 84 | bool operator== (const DataValue& data) const 85 | { 86 | if (Encoding != data.Encoding) 87 | return false; 88 | if ((Encoding & DATA_VALUE) && Value != data.Value) 89 | return false; 90 | if ((Encoding & DATA_VALUE_STATUS_CODE) && Status != data.Status) 91 | return false; 92 | if ((Encoding & DATA_VALUE_SOURCE_TIMESTAMP) && SourceTimestamp != data.SourceTimestamp) 93 | return false; 94 | if ((Encoding & DATA_VALUE_SOURCE_PICOSECONDS) && SourcePicoseconds != data.SourcePicoseconds) 95 | return false; 96 | if ((Encoding & DATA_VALUE_Server_TIMESTAMP) && ServerTimestamp != data.ServerTimestamp) 97 | return false; 98 | if ((Encoding & DATA_VALUE_Server_PICOSECONDS) && ServerPicoseconds != data.ServerPicoseconds) 99 | return false; 100 | 101 | return true; 102 | } 103 | 104 | void SetSourceTimestamp(const DateTime& t) 105 | { 106 | SourceTimestamp = t; 107 | Encoding |= DATA_VALUE_SOURCE_TIMESTAMP; 108 | } 109 | 110 | void SetServerTimestamp(const DateTime& t) 111 | { 112 | ServerTimestamp = t; 113 | Encoding |= DATA_VALUE_Server_TIMESTAMP; 114 | } 115 | }; 116 | 117 | } // namespace OpcUa 118 | 119 | #endif // __OPC_UA_DATA_VALUE_H__ 120 | 121 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/datetime.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Opc Ua Binary DateTime type. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __OPC_UA_BINARY_DATE_TIME__H__ 12 | #define __OPC_UA_BINARY_DATE_TIME__H__ 13 | 14 | #include 15 | #include 16 | 17 | namespace OpcUa 18 | { 19 | 20 | struct DateTime 21 | { 22 | DateTime() 23 | : Value(0) 24 | { 25 | } 26 | 27 | explicit DateTime(int64_t value) 28 | : Value(value) 29 | { 30 | } 31 | 32 | static DateTime Current(); 33 | static DateTime FromTimeT(time_t t, unsigned usec = 0); 34 | static time_t ToTimeT(DateTime dateTime); 35 | 36 | DateTime(const DateTime&) = default; 37 | DateTime& operator=(const DateTime&) = default; 38 | DateTime& operator+=(const DateTime& val) 39 | { 40 | Value += val.Value; 41 | return *this; 42 | } 43 | 44 | operator int64_t() const 45 | { 46 | return Value; 47 | } 48 | 49 | int64_t Value; 50 | }; 51 | 52 | 53 | typedef double Duration; // Time duration in miliseconds. 54 | 55 | } // OpcUa 56 | 57 | 58 | #endif // __OPC_UA_BINARY_DATE_TIME__H__ 59 | 60 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/describe.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Descriptions of OPC UA structures. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __OPCUA_DESCRIPTIONS_H 12 | #define __OPCUA_DESCRIPTIONS_H 13 | 14 | #include 15 | #include 16 | 17 | namespace OpcUa 18 | { 19 | 20 | struct Tabs 21 | { 22 | explicit Tabs(unsigned num = 0) 23 | : Num(num) 24 | { 25 | } 26 | 27 | unsigned Num; 28 | }; 29 | 30 | std::ostream& operator <<(std::ostream& os, const Tabs& tabs) 31 | { 32 | for (unsigned i = 0; i < tabs.Num; ++i) 33 | { 34 | os << " "; 35 | } 36 | return os; 37 | } 38 | 39 | template 40 | std::string Describe(const T& object, const Tabs& tabs); 41 | 42 | } 43 | 44 | #endif // __OPCUA_DESCRIPTIONS_H 45 | 46 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/endpoints.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2012 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Opc Ua Binary. Secure channel service. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __OPC_UA_MESSAGES_DISCOVERY_SERVICE_H__ 12 | #define __OPC_UA_MESSAGES_DISCOVERY_SERVICE_H__ 13 | 14 | #include 15 | #include 16 | 17 | namespace OpcUa 18 | { 19 | 20 | //////////////////////////////////////////////////////// 21 | // FindServersRequest 22 | //////////////////////////////////////////////////////// 23 | struct FindServersParameters 24 | { 25 | std::string EndpointUrl; 26 | std::vector Locales; 27 | std::vector ServersToReturn; 28 | }; 29 | 30 | struct FindServersRequest 31 | { 32 | NodeId TypeId; 33 | RequestHeader Header; 34 | FindServersParameters Parameters; 35 | 36 | FindServersRequest(); 37 | }; 38 | 39 | struct FindServersData 40 | { 41 | std::vector Descriptions; 42 | }; 43 | 44 | struct FindServersResponse 45 | { 46 | NodeId TypeId; 47 | ResponseHeader Header; 48 | FindServersData Data; 49 | 50 | FindServersResponse(); 51 | }; 52 | 53 | } // namespace OpcUa 54 | 55 | #endif // __OPC_UA_MESSAGES_DISCOVERY_SERVICE_H__ 56 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/expanded_object_ids.h: -------------------------------------------------------------------------------- 1 | /// @author Olivier Roulet-Dubonnet 2013 2 | /// @brief Well known attributes identifiers. 3 | /// @license GNU LGPL 4 | /// 5 | /// Distributed under the GNU LGPL License 6 | /// (See accompanying file LICENSE or copy at 7 | /// http://www.gnu.org/licenses/lgpl.html) 8 | /// 9 | 10 | #ifndef __OPC_UA_EXPANDED_OBJECTS_IdS 11 | #define __OPC_UA_EXPANDED_OBJECTS_IdS 12 | 13 | #include 14 | 15 | namespace OpcUa 16 | { 17 | enum class ExpandedObjectId : uint32_t 18 | { 19 | Null = 0, 20 | ObjectAttribute = 354, 21 | VariableAttribute = 357, 22 | MethodAttribute = 360, 23 | ObjectTypeAttribute = 363, 24 | VariableTypeAttribute = 366 , 25 | ReferenceTypeAttribute = 369, 26 | DataTypeAttribute = 372, 27 | ViewAttribute = 375, 28 | 29 | DataChangeNotification = 811, 30 | EventNotificationList = 916, //812, 31 | StatusChangeNotification = 820, 32 | 33 | DataChangeFilter = 724, 34 | EventFilter = 727, 35 | AggregateFilter = 730, 36 | 37 | ElementOperand = 594, 38 | LiteralOperand = 597, 39 | AttributeOperand = 600, 40 | SimpleAttributeOperand = 603 41 | 42 | 43 | }; 44 | } 45 | 46 | #endif // __OPC_UA_BINARY_IdENTIFIERS 47 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/extension_identifiers.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Opc binary cnnection channel. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __OPC_UA_BINARY_EXTENSION_IdENTIFIERS 12 | #define __OPC_UA_BINARY_EXTENSION_IdENTIFIERS 13 | 14 | #include 15 | 16 | namespace OpcUa 17 | { 18 | enum ExtensionObjectId : uint16_t 19 | { 20 | USER_IdENTIFY_TOKEN_ANONYMOUS = 0x141, // 321 21 | USER_IdENTIFY_TOKEN_USERNAME = 0x144, // 324 22 | }; 23 | } 24 | 25 | #endif // __OPC_UA_BINARY_EXTENSION_IdENTIFIERS 26 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/guid.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Guid. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef opcua_guid_h_ 12 | #define opcua_guid_h_ 13 | 14 | #include 15 | #include 16 | 17 | namespace OpcUa 18 | { 19 | struct Guid 20 | { 21 | uint32_t Data1; 22 | uint16_t Data2; 23 | uint16_t Data3; 24 | uint8_t Data4[8]; 25 | 26 | Guid() 27 | : Data1(0) 28 | , Data2(0) 29 | , Data3(0) 30 | { 31 | for (unsigned i = 0; i < 8; ++i) 32 | { 33 | Data4[i] = 0; 34 | } 35 | } 36 | 37 | inline bool operator== (const Guid& r) const 38 | { 39 | for (unsigned i = 0; i < 8; ++i) 40 | { 41 | if (Data4[i] != r.Data4[i]) 42 | { 43 | return false; 44 | } 45 | } 46 | 47 | return Data1 == r.Data1 && Data2 == r.Data2 && Data3 == r.Data3; 48 | } 49 | 50 | inline bool operator< (const Guid& r) const 51 | { 52 | if (Data1 > r.Data1) 53 | { 54 | return false; 55 | } 56 | 57 | if (Data1 < r.Data1) 58 | { 59 | return true; 60 | } 61 | 62 | if (Data2 > r.Data2) 63 | { 64 | return false; 65 | } 66 | 67 | if (Data2 < r.Data2) 68 | { 69 | return true; 70 | } 71 | 72 | if (Data3 > r.Data3) 73 | { 74 | return false; 75 | } 76 | 77 | if (Data3 < r.Data3) 78 | { 79 | return true; 80 | } 81 | 82 | for (unsigned i = 0; i < 8; ++i) 83 | { 84 | if (Data4[i] > r.Data4[i]) 85 | { 86 | return false; 87 | } 88 | 89 | if (Data4[i] < r.Data4[i]) 90 | { 91 | return true; 92 | } 93 | } 94 | 95 | return false; 96 | } 97 | 98 | }; 99 | 100 | } // namespace OpcUa 101 | 102 | #endif // opcua_guid_h_ 103 | 104 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/input_from_buffer.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (C) 2013-2014 by Alexander Rykovanov * 3 | * rykovanov.as@gmail.com * 4 | * * 5 | * This library is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU Lesser General Public License as * 7 | * published by the Free Software Foundation; version 3 of the License. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesser General Public License for more details. * 13 | * * 14 | * You should have received a copy of the GNU Lesser General Public License * 15 | * along with this library; if not, write to the * 16 | * Free Software Foundation, Inc., * 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 | ******************************************************************************/ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | namespace OpcUa 25 | { 26 | 27 | class InputFromBuffer : public OpcUa::InputChannel 28 | { 29 | public: 30 | InputFromBuffer(const char* buf, std::size_t bufSize); 31 | 32 | virtual std::size_t Receive(char* data, std::size_t size) override; 33 | 34 | size_t GetRemainSize() const; 35 | 36 | virtual void Stop(){} 37 | 38 | private: 39 | const char* Buffer; 40 | std::size_t Size; 41 | }; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/message_identifiers.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Opc binary cnnection channel. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __OPC_UA_BINARY_MESSAGE_IdENTIFIERS 12 | #define __OPC_UA_BINARY_MESSAGE_IdENTIFIERS 13 | 14 | namespace OpcUa 15 | { 16 | enum MessageId 17 | { 18 | INVALID = 0, 19 | 20 | ACTIVATE_SESSION_REQUEST = 0x1d3, //467; 21 | ACTIVATE_SESSION_RESPONSE = 0x1d6, //470; 22 | 23 | BROWSE_REQUEST = 0x20f, // 527; 24 | BROWSE_RESPONSE = 0x212, //530; 25 | 26 | BROWSE_NEXT_REQUEST = 0x215, // 533 27 | BROWSE_NEXT_RESPONSE = 0x218, // 536 28 | 29 | CLOSE_SECURE_CHANNEL_REQUEST = 0x1c4, // 452 30 | 31 | CLOSE_SESSION_REQUEST = 0x1d9, // 473; 32 | CLOSE_SESSION_RESPONSE = 0x1dc, // 476; 33 | 34 | // Session services 35 | CREATE_SESSION_REQUEST = 0x1cd, // 461; 36 | CREATE_SESSION_RESPONSE = 0x1d0, // 464; 37 | 38 | // Endpoints services 39 | FIND_ServerS_REQUEST = 0x1A6, // 422 40 | FIND_ServerS_RESPONSE = 0x1A9, // 425 41 | 42 | GET_ENDPOINTS_REQUEST = 0x1ac, // 428 43 | GET_ENDPOINTS_RESPONSE = 0x1af, // 431 44 | 45 | // Secure channel services 46 | OPEN_SECURE_CHANNEL_REQUEST = 0x1be, // 446 47 | OPEN_SECURE_CHANNEL_RESPONSE = 0x1c1, // 449 48 | 49 | TRANSLATE_BROWSE_PATHS_TO_NODE_IdS_REQUEST = 0x22A, // 554 50 | TRANSLATE_BROWSE_PATHS_TO_NODE_IdS_RESPONSE = 0x22D, // 557 51 | 52 | REGISTER_NODES_REQUEST = 0x230, // 560 53 | REGISTER_NODES_RESPONSE = 0x233, // 563 54 | 55 | UNREGISTER_NODES_REQUEST = 0x234, // 564 56 | UNREGISTER_NODES_RESPONSE = 0x237, // 567 57 | 58 | READ_REQUEST = 0x277, // 631 59 | READ_RESPONSE = 0x27A, // 634 60 | 61 | WRITE_REQUEST = 0x2A1, //673 62 | WRITE_RESPONSE = 0x2A4, // 676 63 | 64 | 65 | CALL_REQUEST = 712, 66 | CALL_RESPONSE = 715, // 754 67 | 68 | CREATE_MONITORED_ITEMS_REQUEST = 0x2EF, // 751 69 | CREATE_MONITORED_ITEMS_RESPONSE = 0x2F2, // 754 70 | 71 | DELETE_MONITORED_ITEMS_REQUEST = 0x30d, // 781 72 | DELETE_MONITORED_ITEMS_RESPONSE = 0x310, // 784 73 | 74 | CREATE_SUBSCRIPTION_REQUEST = 0x313, //787 75 | CREATE_SUBSCRIPTION_RESPONSE = 0x316, //790 76 | 77 | DELETE_SUBSCRIPTION_REQUEST = 0x34f, //847 78 | DELETE_SUBSCRIPTION_RESPONSE = 0x352, //850 79 | 80 | PUBLISH_REQUEST = 0x33A, // 826 81 | PUBLISH_RESPONSE = 0x33D, // 829 82 | 83 | REPUBLISH_REQUEST = 832, 84 | REPUBLISH_RESPONSE = 835, 85 | 86 | SET_PUBLISHING_MODE_REQUEST = 0x31F, // 799 87 | SET_PUBLISHING_MODE_RESPONSE = 0x322, // 802 88 | 89 | ADD_NODES_REQUEST = 0x1e8, //488; 90 | ADD_NODES_RESPONSE = 0x1eb, //491; 91 | 92 | DELETE_NODES_REQUEST = 0x1f4, //500; 93 | DELETE_NODES_RESPONSE = 0x1f7, //503; 94 | 95 | ADD_REFERENCES_REQUEST = 0x1ee, //494; 96 | ADD_REFERENCES_RESPONSE = 0x1f1, //497; 97 | 98 | DELETE_REFERENCES_REQUEST = 0x1fa, //506; 99 | DELETE_REFERENCES_RESPONSE = 0x1fd, //509; 100 | 101 | SERVICE_FAULT = 0x18d, //397; 102 | }; 103 | 104 | struct NodeId; 105 | 106 | MessageId GetMessageId(const NodeId& id); 107 | 108 | } 109 | 110 | #endif // __OPC_UA_BINARY_MESSAGE_IdENTIFIERS 111 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/monitored_items.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Monitored items services. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef OPC_UA_MAPPINGS_MONITORED_ITEMS_H_ 12 | #define OPC_UA_MAPPINGS_MONITORED_ITEMS_H_ 13 | 14 | #include 15 | 16 | namespace OpcUa 17 | { 18 | 19 | } 20 | 21 | #endif // OPC_UA_MAPPINGS_MONITORED_ITEMS_H_ 22 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/node_management.h: -------------------------------------------------------------------------------- 1 | /// @author Olivier Roulet-Dubonnet 2014 2 | /// @email olivier.roulet@gmail.com 3 | /// @brief Opc Ua Binary. Attributes service. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __OPC_UA_BINARY_NODEMANAGEMENT_H_ 12 | #define __OPC_UA_BINARY_NODEMANAGEMENT_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace OpcUa 24 | { 25 | 26 | // 27 | // AddNode Message definition 28 | // 29 | 30 | enum SpecifiedAttributesEncoding : uint32_t 31 | { 32 | AccessLevel = 0, 33 | ArrayDimensions = 1, 34 | ContainsNoLoops = 3, 35 | DataType = 4, 36 | Description = 5, 37 | DisplayName = 6, 38 | EventNotifier = 7, 39 | Executable = 8, 40 | Historizing = 9, 41 | InverseName = 10, 42 | IsAbstract = 11, 43 | MinimumSamplingInterval = 12, 44 | Symmetric = 15, 45 | UserAccessLevel = 16, 46 | UserExecutable = 17, 47 | UserWriteMask = 18, 48 | ValueRank = 19, 49 | WriteMask = 20, 50 | Value = 21, 51 | }; 52 | 53 | struct EventNotifier 54 | { 55 | static const uint8_t SubscribeToEvents = 1 << 0; 56 | static const uint8_t Reserved = 1 << 1; 57 | static const uint8_t HistoryRead = 1 << 2; 58 | static const uint8_t HistoryWrite = 1 << 3; 59 | //all other bytes are reserved 60 | }; 61 | 62 | typedef std::bitset IntBits; 63 | 64 | struct ObjectAttributes 65 | { 66 | uint32_t SpecifiedAttributes; 67 | LocalizedText DisplayName; 68 | LocalizedText Description; 69 | uint8_t EventNotifier = 0; 70 | uint32_t WriteMask = 0; 71 | uint32_t UserWriteMask = 0; 72 | }; 73 | 74 | struct VariableAttributes 75 | { 76 | uint32_t SpecifiedAttributes; 77 | LocalizedText DisplayName; 78 | LocalizedText Description; 79 | Variant Value; 80 | NodeId Type; 81 | int32_t Rank = 0; 82 | std::vector Dimensions; 83 | VariableAccessLevel AccessLevel = VariableAccessLevel::CurrentRead; 84 | VariableAccessLevel UserAccessLevel = VariableAccessLevel::CurrentRead; 85 | Duration MinimumSamplingInterval = 0; 86 | bool Historizing = false; 87 | uint32_t WriteMask = 0; 88 | uint32_t UserWriteMask = 0; 89 | }; 90 | 91 | struct MethodAttributes 92 | { 93 | uint32_t SpecifiedAttributes; 94 | LocalizedText DisplayName; 95 | LocalizedText Description; 96 | bool Executable = false; 97 | bool UserExecutable = false; 98 | uint32_t WriteMask = 0; 99 | uint32_t UserWriteMask = 0; 100 | }; 101 | 102 | struct ObjectTypeAttributes 103 | { 104 | uint32_t SpecifiedAttributes; 105 | LocalizedText DisplayName; 106 | LocalizedText Description; 107 | bool IsAbstract = false; 108 | uint32_t WriteMask = 0; 109 | uint32_t UserWriteMask = 0; 110 | }; 111 | 112 | struct VariableTypeAttributes 113 | { 114 | uint32_t SpecifiedAttributes; 115 | LocalizedText DisplayName; 116 | LocalizedText Description; 117 | Variant Value; 118 | NodeId Type; 119 | int32_t Rank = 0; 120 | std::vector Dimensions; 121 | bool IsAbstract = false; 122 | uint32_t WriteMask = 0; 123 | uint32_t UserWriteMask = 0; 124 | }; 125 | 126 | struct ReferenceTypeAttributes 127 | { 128 | uint32_t SpecifiedAttributes; 129 | LocalizedText DisplayName; 130 | LocalizedText Description; 131 | bool IsAbstract = false; 132 | bool Symmetric = false; 133 | LocalizedText InverseName; 134 | uint32_t WriteMask = 0; 135 | uint32_t UserWriteMask = 0; 136 | }; 137 | 138 | struct DataTypeAttributes 139 | { 140 | uint32_t SpecifiedAttributes; 141 | LocalizedText DisplayName; 142 | LocalizedText Description; 143 | bool IsAbstract = false; 144 | uint32_t WriteMask = 0; 145 | uint32_t UserWriteMask = 0; 146 | }; 147 | 148 | struct ViewAttributes 149 | { 150 | uint32_t SpecifiedAttributes; 151 | LocalizedText DisplayName; 152 | LocalizedText Description; 153 | bool ContainsNoLoops = true; 154 | uint32_t WriteMask = 0; 155 | uint32_t UserWriteMask = 0; 156 | }; 157 | 158 | struct NodeAttributes 159 | { 160 | ExtensionObjectHeader Header; 161 | uint32_t SpecifiedAttributes; 162 | std::map Attributes; 163 | 164 | NodeAttributes(){} 165 | NodeAttributes(const ObjectAttributes&); 166 | NodeAttributes(const VariableAttributes&); 167 | NodeAttributes(const MethodAttributes&); 168 | NodeAttributes(const ObjectTypeAttributes&); 169 | NodeAttributes(const VariableTypeAttributes&); 170 | NodeAttributes(const ReferenceTypeAttributes&); 171 | NodeAttributes(const DataTypeAttributes&); 172 | NodeAttributes(const ViewAttributes&); 173 | }; 174 | 175 | // TODO Rename to NodeParameters 176 | struct AddNodesItem 177 | { 178 | NodeId ParentNodeId; 179 | NodeId ReferenceTypeId; 180 | NodeId RequestedNewNodeId; 181 | QualifiedName BrowseName; 182 | NodeClass Class; 183 | NodeAttributes Attributes; 184 | NodeId TypeDefinition; 185 | }; 186 | 187 | 188 | struct AddNodesParameters 189 | { 190 | std::vector NodesToAdd; 191 | }; 192 | 193 | struct AddNodesRequest 194 | { 195 | NodeId TypeId; 196 | RequestHeader Header; 197 | AddNodesParameters Parameters; 198 | AddNodesRequest(); 199 | }; 200 | 201 | struct AddNodesResult 202 | { 203 | StatusCode Status; 204 | NodeId AddedNodeId; 205 | }; 206 | 207 | struct AddNodesResponse 208 | { 209 | NodeId TypeId; 210 | ResponseHeader Header; 211 | std::vector results; 212 | DiagnosticInfoList Diagnostics; 213 | AddNodesResponse(); 214 | }; 215 | 216 | 217 | // 218 | // AddReference 219 | // 220 | 221 | struct AddReferencesItem 222 | { 223 | NodeId SourceNodeId; 224 | NodeId ReferenceTypeId; 225 | bool IsForward; 226 | std::string TargetServerUri; 227 | NodeId TargetNodeId; 228 | NodeClass TargetNodeClass; 229 | }; 230 | 231 | struct AddReferencesParameters 232 | { 233 | std::vector ReferencesToAdd; 234 | }; 235 | 236 | struct AddReferencesRequest 237 | { 238 | NodeId TypeId; 239 | RequestHeader Header; 240 | AddReferencesParameters Parameters; 241 | 242 | AddReferencesRequest(); 243 | }; 244 | 245 | struct AddReferencesResponse 246 | { 247 | NodeId TypeId; 248 | ResponseHeader Header; 249 | std::vector Results; 250 | DiagnosticInfoList Diagnostics; 251 | 252 | AddReferencesResponse(); 253 | }; 254 | 255 | //FIXME: move somewhere else!! 256 | const char* GetObjectIdName(const NodeId& id) ; 257 | 258 | 259 | } 260 | 261 | #endif 262 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/nodeid.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Node Id. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace OpcUa 25 | { 26 | 27 | enum NodeIdEncoding : uint8_t 28 | { 29 | EV_TWO_BYTE = 0, 30 | EV_FOUR_BYTE = 1, 31 | EV_NUMERIC = 2, 32 | EV_STRING = 3, 33 | EV_GUId = 4, 34 | EV_BYTE_STRING = 5, 35 | 36 | EV_Server_INDEX_FLAG = 0x40, 37 | EV_NAMESPACE_URI_FLAG = 0x80, 38 | 39 | EV_VALUE_MASK = 0x3f, 40 | }; 41 | 42 | struct ExpandedNodeId; 43 | 44 | struct NodeId 45 | { 46 | NodeIdEncoding Encoding; 47 | std::string NamespaceURI; 48 | uint32_t ServerIndex; 49 | 50 | struct TwoByteDataType 51 | { 52 | uint8_t Identifier; 53 | 54 | TwoByteDataType() 55 | : Identifier(0) 56 | { 57 | } 58 | 59 | } TwoByteData; 60 | 61 | struct FourByteDataType 62 | { 63 | uint8_t NamespaceIndex; 64 | uint16_t Identifier; 65 | 66 | FourByteDataType() 67 | : NamespaceIndex(0) 68 | , Identifier(0) 69 | { 70 | } 71 | }FourByteData; 72 | 73 | struct NumericDataType 74 | { 75 | uint16_t NamespaceIndex; 76 | uint32_t Identifier; 77 | 78 | NumericDataType() 79 | : NamespaceIndex(0) 80 | , Identifier(0) 81 | { 82 | } 83 | }NumericData; 84 | 85 | 86 | struct StringDataType 87 | { 88 | uint16_t NamespaceIndex; 89 | std::string Identifier; 90 | 91 | StringDataType() 92 | : NamespaceIndex(0) 93 | { 94 | } 95 | 96 | }StringData; 97 | 98 | struct BinaryDataType 99 | { 100 | uint16_t NamespaceIndex; 101 | std::vector Identifier; 102 | 103 | BinaryDataType() 104 | : NamespaceIndex(0) 105 | { 106 | } 107 | 108 | }BinaryData; 109 | 110 | struct GuidDataType 111 | { 112 | uint16_t NamespaceIndex; 113 | Guid Identifier; 114 | 115 | GuidDataType() 116 | : NamespaceIndex(0) 117 | { 118 | } 119 | 120 | }GuidData; 121 | 122 | NodeId(); 123 | NodeId(const NodeId& node); 124 | NodeId(const ExpandedNodeId& node); 125 | NodeId(MessageId messageId); 126 | NodeId(ReferenceId referenceId); 127 | NodeId(ObjectId objectId); 128 | NodeId(ExpandedObjectId objectId); 129 | NodeId(uint32_t integerId, uint16_t index); 130 | NodeId(std::string stringId, uint16_t index); 131 | 132 | NodeId& operator= (const NodeId& node); 133 | NodeId& operator= (const ExpandedNodeId& node); 134 | 135 | explicit operator ExpandedNodeId(); 136 | 137 | NodeId& operator= (MessageId messageId) 138 | { 139 | *this = NodeId(messageId); 140 | return *this; 141 | } 142 | 143 | NodeId& operator= (ReferenceId referenceId) 144 | { 145 | *this = NodeId(referenceId); 146 | return *this; 147 | } 148 | 149 | NodeId& operator= (ObjectId objectId) 150 | { 151 | *this = NodeId(objectId); 152 | return *this; 153 | } 154 | 155 | NodeId& operator= (ExpandedObjectId objectId) 156 | { 157 | *this = NodeId(objectId); 158 | return *this; 159 | } 160 | 161 | bool operator== (const NodeId& node) const; 162 | bool operator== (MessageId messageId) const; 163 | bool operator== (ReferenceId referenceId) const; 164 | bool operator== (ObjectId objectId) const; 165 | bool operator== (ExpandedObjectId objectId) const; 166 | 167 | bool operator!= (const NodeId& node) const; 168 | bool operator!= (MessageId messageId) const; 169 | bool operator!= (ReferenceId referenceId) const; 170 | bool operator!= (ObjectId objectId) const; 171 | bool operator!= (ExpandedObjectId objectId) const; 172 | 173 | bool operator< (const NodeId& node) const; 174 | 175 | NodeIdEncoding GetEncodingValue() const; 176 | bool HasNamespaceURI() const; 177 | bool HasServerIndex() const; 178 | 179 | void SetNamespaceURI(const std::string& uri); 180 | void SetServerIndex(uint32_t index); 181 | void SetNamespaceIndex(uint32_t ns); 182 | 183 | bool IsInteger() const; 184 | bool IsString() const; 185 | bool IsBinary() const; 186 | bool IsGuid() const; 187 | 188 | uint32_t GetNamespaceIndex() const; 189 | 190 | uint32_t GetIntegerIdentifier() const; 191 | std::string GetStringIdentifier() const; 192 | std::vector GetBinaryIdentifier() const; 193 | Guid GetGuidIdentifier() const; 194 | 195 | protected: 196 | void CopyNodeId(const NodeId& node); 197 | }; 198 | 199 | inline NodeId TwoByteNodeId(uint8_t value) 200 | { 201 | NodeId id; 202 | id.Encoding = EV_TWO_BYTE; 203 | id.TwoByteData.Identifier = value; 204 | return id; 205 | } 206 | 207 | inline NodeId FourByteNodeId(uint16_t value, uint8_t namespaceIndex = 0) 208 | { 209 | NodeId id; 210 | id.Encoding = EV_FOUR_BYTE; 211 | id.FourByteData.Identifier = value; 212 | id.FourByteData.NamespaceIndex = namespaceIndex; 213 | return id; 214 | } 215 | 216 | inline NodeId NumericNodeId(uint32_t value, uint16_t namespaceIndex = 0) 217 | { 218 | NodeId id; 219 | id.Encoding = EV_NUMERIC; 220 | id.NumericData.Identifier = value; 221 | id.NumericData.NamespaceIndex = namespaceIndex; 222 | return id; 223 | } 224 | 225 | inline NodeId StringNodeId(std::string value, uint16_t namespaceIndex = 0) 226 | { 227 | NodeId id; 228 | id.Encoding = EV_STRING; 229 | id.StringData.Identifier = value; 230 | id.StringData.NamespaceIndex = namespaceIndex; 231 | return id; 232 | } 233 | 234 | inline NodeId BinaryNodeId(std::vector value, uint16_t namespaceIndex = 0) 235 | { 236 | NodeId id; 237 | id.Encoding = EV_BYTE_STRING; 238 | id.BinaryData.Identifier = value; 239 | id.BinaryData.NamespaceIndex = namespaceIndex; 240 | return id; 241 | } 242 | 243 | inline NodeId GuidNodeId(Guid value, uint16_t namespaceIndex = 0) 244 | { 245 | NodeId id; 246 | id.Encoding = EV_GUId; 247 | id.GuidData.Identifier = value; 248 | id.GuidData.NamespaceIndex = namespaceIndex; 249 | return id; 250 | } 251 | 252 | struct ExpandedNodeId : public NodeId 253 | { 254 | ExpandedNodeId(); 255 | ExpandedNodeId(const NodeId& node); 256 | ExpandedNodeId(const ExpandedNodeId& node); 257 | ExpandedNodeId(MessageId messageId); 258 | ExpandedNodeId(ReferenceId referenceId); 259 | ExpandedNodeId(ObjectId objectId); 260 | ExpandedNodeId(ExpandedObjectId objectId); 261 | ExpandedNodeId(uint32_t integerId, uint16_t index); 262 | ExpandedNodeId(std::string stringId, uint16_t index); 263 | 264 | //using NodeId::NodeId; 265 | //using base::base; 266 | }; 267 | 268 | } // namespace OpcUa 269 | 270 | 271 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/protocol.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace OpcUa 6 | { 7 | ReadValueId inline ToReadValueId(NodeId id, AttributeId attr) 8 | { 9 | ReadValueId rv; 10 | rv.NodeId = id; 11 | rv.AttributeId = attr; 12 | return rv; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/reference_ids.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Well known referencies identifiers. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef opc_ua_referencie_ids_h 12 | #define opc_ua_referencie_ids_h 13 | 14 | #include 15 | 16 | namespace OpcUa 17 | { 18 | 19 | enum class ReferenceId : uint32_t 20 | { 21 | References = 31, 22 | NonHierarchicalReferences = 32, 23 | HierarchicalReferences = 33, 24 | HasChild = 34, 25 | Organizes = 35, 26 | HasEventSource = 36, 27 | HasModellingRule = 37, 28 | HasEncoding = 38, 29 | HasDescription = 39, 30 | HasTypeDefinition = 40, 31 | GeneratesEvent = 41, 32 | Aggregates = 44, 33 | HasSubtype = 45, 34 | HasProperty = 46, 35 | HasComponent = 47, 36 | HasNotifier = 48, 37 | HasOrderedComponent = 49, 38 | HasModelParent = 50, 39 | FromState = 51, 40 | ToState = 52, 41 | HasCause = 53, 42 | HasEffect = 54, 43 | HasHistoricalConfiguration = 56, 44 | HasHistoricalEventConfiguration = 57, 45 | HasSubStateMachine = 117, 46 | HasEventHistory = 118, 47 | AlwaysGeneratesEvent = 3065, 48 | HasTrueSubState = 9004, 49 | HasFalseSubState = 9005, 50 | HasCondition = 9006, 51 | 52 | Unknown = ~uint32_t() 53 | }; 54 | 55 | } // namespace OpcUa 56 | #endif // opc_ua_referencie_ids_h 57 | 58 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/secure_channel.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2012 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Opc Ua Binary. Secure channel service. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __OPC_UA_MESSAGES_SECURE_CHANNEL_H__ 12 | #define __OPC_UA_MESSAGES_SECURE_CHANNEL_H__ 13 | 14 | #include 15 | 16 | namespace OpcUa 17 | { 18 | // OpenSecureChannel 19 | // os << SecureHeader 20 | // << AssymmetricAlgoripthmHeader 21 | // << SequenceHeader 22 | // << NodeId << ExpandedNodeId // if present 23 | // << RequestHeader 24 | // << OpenSecureChannel 25 | 26 | struct OpenSecureChannelParameters 27 | { 28 | uint32_t ClientProtocolVersion; 29 | SecurityTokenRequestType RequestType; 30 | MessageSecurityMode SecurityMode; 31 | std::vector ClientNonce; 32 | uint32_t RequestLifeTime; 33 | 34 | OpenSecureChannelParameters(); 35 | }; 36 | 37 | struct OpenSecureChannelRequest 38 | { 39 | ExpandedNodeId TypeId; 40 | RequestHeader Header; 41 | OpenSecureChannelParameters Parameters; 42 | 43 | OpenSecureChannelRequest(); 44 | }; 45 | 46 | 47 | // OpenSecureChannelResponse 48 | // is >> SecureHeader 49 | // >> AsymmetricAlgorithmHeader 50 | // >> SequenceHeader 51 | // >> ResponseHeader 52 | // >> GetEndpointsResponse 53 | 54 | struct SecurityToken 55 | { 56 | uint32_t SecureChannelId; 57 | uint32_t TokenId; 58 | DateTime CreatedAt; 59 | int32_t RevisedLifetime; 60 | 61 | SecurityToken() 62 | : SecureChannelId(0) 63 | , TokenId(0) 64 | , CreatedAt(0) 65 | , RevisedLifetime(0) 66 | { 67 | } 68 | }; 69 | 70 | struct OpenSecureChannelResponse 71 | { 72 | NodeId TypeId; 73 | ResponseHeader Header; 74 | 75 | uint32_t ServerProtocolVersion; 76 | SecurityToken ChannelSecurityToken; 77 | std::vector ServerNonce; 78 | 79 | OpenSecureChannelResponse(); 80 | }; 81 | 82 | struct CloseSecureChannelRequest 83 | { 84 | NodeId TypeId; 85 | RequestHeader Header; 86 | 87 | CloseSecureChannelRequest(); 88 | }; 89 | 90 | } // namespace OpcUa 91 | 92 | #endif // __OPC_UA_MESSAGES_SECURE_CHANNEL_H__ 93 | 94 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/session.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2012 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Opc Ua Binary. Secure channel service. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __OPC_UA_BINARY_SESSIONS_H__ 12 | #define __OPC_UA_BINARY_SESSIONS_H__ 13 | 14 | #include 15 | #include 16 | 17 | namespace OpcUa 18 | { 19 | //------------------------------------------------- 20 | // CloseSessionRequest 21 | //------------------------------------------------- 22 | 23 | struct CloseSessionRequest 24 | { 25 | NodeId TypeId; 26 | RequestHeader Header; 27 | 28 | bool DeleteSubscriptions; 29 | 30 | CloseSessionRequest(); 31 | }; 32 | 33 | struct CloseSessionResponse 34 | { 35 | NodeId TypeId; 36 | ResponseHeader Header; 37 | 38 | CloseSessionResponse(); 39 | }; 40 | 41 | ExpandedNodeId GenerateSessionId(); 42 | 43 | struct ServiceFaultResponse 44 | { 45 | NodeId TypeId; 46 | ResponseHeader Header; 47 | 48 | ServiceFaultResponse(); 49 | }; 50 | 51 | 52 | } // namespace OpcUa 53 | 54 | #endif // __OPC_UA_BINARY_SESSIONS_H__ 55 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/string_utils.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (C) 2013-2014 by Alexander Rykovanov * 3 | * rykovanov.as@gmail.com * 4 | * * 5 | * This library is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU Lesser General Public License as * 7 | * published by the Free Software Foundation; version 3 of the License. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesser General Public License for more details. * 13 | * * 14 | * You should have received a copy of the GNU Lesser General Public License * 15 | * along with this library; if not, write to the * 16 | * Free Software Foundation, Inc., * 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 | ******************************************************************************/ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace OpcUa 28 | { 29 | 30 | std::string ToString(const NodeId& id); 31 | std::string ToString(const Guid& guid); 32 | std::string ToString(const DateTime& t); 33 | std::string ToString(const BrowseDirection& direction); 34 | std::string ToString(const StatusCode& code); 35 | std::string ToString(const LocalizedText& code); 36 | 37 | Guid ToGuid(const std::string& str); 38 | NodeId ToNodeId(const std::string& str, uint32_t defaultNamespace=0); 39 | QualifiedName ToQualifiedName(const std::string& str, uint32_t default_ns=0); 40 | 41 | inline std::ostream& operator<<(std::ostream& os, const OpcUa::NodeId& nodeid) 42 | { 43 | os << OpcUa::ToString(nodeid).c_str(); 44 | return os; 45 | } 46 | 47 | inline std::ostream& operator<<(std::ostream& os, const OpcUa::LocalizedText& t) 48 | { 49 | os << OpcUa::ToString(t).c_str(); 50 | return os; 51 | } 52 | 53 | inline std::ostream& operator<<(std::ostream& os, const OpcUa::QualifiedName& qn) 54 | { 55 | os << "QualifiedName(" << qn.NamespaceIndex << ":" << qn.Name.c_str() << ")"; 56 | return os; 57 | } 58 | 59 | inline std::ostream& operator<<(std::ostream& os, const OpcUa::BrowseDirection& direction) 60 | { 61 | os << OpcUa::ToString(direction); 62 | return os; 63 | } 64 | 65 | inline std::ostream& operator<<(std::ostream& os, const OpcUa::Guid& guid) 66 | { 67 | os << "{" << ToString(guid) << "}"; 68 | return os; 69 | } 70 | 71 | inline std::ostream& operator<<(std::ostream& os, const OpcUa::ByteString& buf) 72 | { 73 | const std::size_t size = buf.Data.size(); 74 | unsigned pos = 0; 75 | os << "Data size: " << size << std::endl; 76 | while (pos < size) 77 | { 78 | if (pos) 79 | printf((pos % 16 == 0) ? "\n" : " "); 80 | 81 | const char letter = buf.Data[pos]; 82 | printf("%02x", (unsigned)letter & 0x000000FF); 83 | 84 | if (letter > ' ') 85 | os << "(" << letter << ")"; 86 | else 87 | os << " "; 88 | 89 | ++pos; 90 | } 91 | 92 | os << std::endl; 93 | return os; 94 | } 95 | } 96 | 97 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/types.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2012 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief C++ types of binary protocol. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __OPC_UA_MAPPING_TYPES_H__ 12 | #define __OPC_UA_MAPPING_TYPES_H__ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | namespace OpcUa 31 | { 32 | 33 | typedef std::string LocaleId; 34 | 35 | struct ByteString 36 | { 37 | std::vector Data; 38 | 39 | ByteString() 40 | { 41 | } 42 | 43 | explicit ByteString(const std::vector& val) 44 | : Data(val) 45 | { 46 | } 47 | 48 | bool operator== (const ByteString& str) const 49 | { 50 | return Data == str.Data; 51 | } 52 | 53 | // For tests 54 | 55 | }; 56 | 57 | class IntegerId 58 | { 59 | public: 60 | IntegerId(); 61 | IntegerId(const IntegerId& id); 62 | explicit IntegerId(uint32_t num); 63 | IntegerId& operator= (const IntegerId& id); 64 | IntegerId& operator= (uint32_t value); 65 | operator uint32_t() const; 66 | 67 | private: 68 | uint32_t Value; 69 | }; 70 | 71 | struct QualifiedName 72 | { 73 | uint16_t NamespaceIndex; 74 | std::string Name; // TODO rename to Text 75 | 76 | QualifiedName() 77 | : NamespaceIndex(0) 78 | { 79 | } 80 | 81 | QualifiedName(uint16_t nameSpace, const std::string& name) 82 | : NamespaceIndex(nameSpace) 83 | , Name(name) 84 | { 85 | } 86 | 87 | QualifiedName(const std::string& name, uint16_t nameSpace) 88 | : NamespaceIndex(nameSpace) 89 | , Name(name) 90 | { 91 | } 92 | 93 | explicit QualifiedName(const std::string& name) 94 | : NamespaceIndex(0) 95 | , Name(name) 96 | { 97 | } 98 | 99 | bool operator== (const QualifiedName& name) const 100 | { 101 | return NamespaceIndex == name.NamespaceIndex && Name == name.Name; 102 | } 103 | 104 | bool operator < (const QualifiedName& name) const 105 | { 106 | if (NamespaceIndex != name.NamespaceIndex) 107 | { 108 | return NamespaceIndex < name.NamespaceIndex; 109 | } 110 | return Name < name.Name; 111 | } 112 | }; 113 | 114 | struct RelativePathElement 115 | { 116 | NodeId ReferenceTypeId; 117 | bool IsInverse = false; 118 | bool IncludeSubtypes = false; 119 | QualifiedName TargetName; 120 | }; 121 | 122 | struct RelativePath 123 | { 124 | std::vector Elements; 125 | }; 126 | 127 | // LocalizedText encoding mask 128 | const uint8_t HAS_LOCALE = 1; 129 | const uint8_t HAS_TEXT = 2; 130 | 131 | struct LocalizedText 132 | { 133 | uint8_t Encoding; 134 | std::string Locale; 135 | std::string Text; // TODO rename to Data 136 | 137 | LocalizedText() 138 | : Encoding(0) 139 | { 140 | } 141 | 142 | explicit LocalizedText(const std::string& text) 143 | : Encoding(HAS_TEXT) 144 | , Text(text) 145 | { 146 | } 147 | 148 | explicit LocalizedText(const char* text) 149 | : Encoding(HAS_TEXT) 150 | , Text(text) 151 | { 152 | } 153 | 154 | LocalizedText(const std::string& text, const std::string& locale) 155 | : Encoding(HAS_TEXT | HAS_LOCALE) 156 | , Locale(locale) 157 | , Text(text) 158 | { 159 | } 160 | 161 | LocalizedText(const char* text, char* locale) 162 | : Encoding(HAS_TEXT | HAS_LOCALE) 163 | , Locale(locale) 164 | , Text(text) 165 | { 166 | } 167 | 168 | bool operator== (const LocalizedText& text) const 169 | { 170 | return Encoding == text.Encoding && Locale == text.Locale && Text == text.Text; 171 | } 172 | }; 173 | 174 | struct AdditionalHeader 175 | { 176 | ExpandedNodeId TypeId; 177 | uint8_t Encoding; 178 | 179 | AdditionalHeader() 180 | : Encoding(0) 181 | { 182 | } 183 | }; 184 | 185 | struct RequestHeader 186 | { 187 | ExpandedNodeId SessionAuthenticationToken; 188 | DateTime UtcTime; 189 | uint32_t RequestHandle = 0; 190 | uint32_t ReturnDiagnostics = 0; 191 | std::string AuditEntryId; 192 | uint32_t Timeout = 0; // in miliseconds 193 | AdditionalHeader Additional; 194 | 195 | RequestHeader(); 196 | }; 197 | 198 | 199 | enum DiagnosticInfoMask : uint8_t 200 | { 201 | DIM_NONE = 0, 202 | DIM_SYMBOLIC_Id = 0x1, 203 | DIM_NAMESPACE = 0x2, 204 | DIM_LOCALIZED_TEXT = 0x4, 205 | DIM_LOCALE = 0x8, 206 | DIM_ADDITIONAL_INFO = 0x10, 207 | DIM_INNER_STATUS_CODE = 0x20, 208 | DIM_INNER_DIAGNOSTIC_INFO = 0x40 209 | }; 210 | 211 | struct DiagnosticInfo 212 | { 213 | DiagnosticInfoMask EncodingMask; 214 | int32_t SymbolicId; 215 | int32_t NamespaceURI; 216 | int32_t LocalizedText; 217 | int32_t Locale; 218 | std::string AdditionalInfo; 219 | StatusCode InnerStatusCode; 220 | std::shared_ptr InnerDiagnostics; 221 | 222 | DiagnosticInfo() 223 | : EncodingMask(DiagnosticInfoMask::DIM_NONE) 224 | , SymbolicId(0) 225 | , NamespaceURI(0) 226 | , LocalizedText(0) 227 | , Locale(0) 228 | , InnerStatusCode(StatusCode::Good) 229 | { 230 | } 231 | 232 | bool operator== (const DiagnosticInfo& info) const 233 | { 234 | if ( 235 | EncodingMask == info.EncodingMask && 236 | SymbolicId == info.SymbolicId && 237 | NamespaceURI == info.NamespaceURI && 238 | LocalizedText == info.LocalizedText && 239 | Locale == info.Locale && 240 | InnerStatusCode == info.InnerStatusCode) 241 | { 242 | if (InnerDiagnostics && info.InnerDiagnostics) 243 | return *InnerDiagnostics == *info.InnerDiagnostics; 244 | 245 | return !InnerDiagnostics && !info.InnerDiagnostics; 246 | } 247 | return false; 248 | } 249 | }; 250 | 251 | typedef std::vector DiagnosticInfoList; 252 | 253 | struct ResponseHeader 254 | { 255 | DateTime Timestamp; 256 | uint32_t RequestHandle = 0; 257 | StatusCode ServiceResult = StatusCode::Good; 258 | DiagnosticInfo InnerDiagnostics; 259 | std::vector StringTable; 260 | AdditionalHeader Additional; 261 | 262 | ResponseHeader(); 263 | }; 264 | 265 | typedef std::vector CertificateData; 266 | 267 | // // TODO Serialization, RawSize 268 | // struct SignatureData 269 | // { 270 | // std::vector Signature; 271 | // std::string Algorithm; 272 | // }; 273 | 274 | enum ExtensionObjectEncoding : uint8_t 275 | { 276 | NONE = 0, 277 | HAS_BINARY_BODY = 1, 278 | HAS_XML_BODY = 2, 279 | }; 280 | 281 | //TODO serialization tests 282 | struct ExtensionObjectHeader 283 | { 284 | ExpandedNodeId TypeId; 285 | ExtensionObjectEncoding Encoding; 286 | 287 | ExtensionObjectHeader(); 288 | ExtensionObjectHeader(ExtensionObjectId objectId, ExtensionObjectEncoding encoding); 289 | }; 290 | 291 | } // namespace OpcUa 292 | 293 | #endif // __OPC_UA_MAPPING_TYPES_H__ 294 | 295 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/types_manual.h: -------------------------------------------------------------------------------- 1 | #ifndef __OPC_UA_MAPPING_TYPES_MANUAL_H__ 2 | #define __OPC_UA_MAPPING_TYPES_MANUAL_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | namespace OpcUa 17 | { 18 | /// Moved from session.h 19 | struct UserIdentifyToken 20 | { 21 | ExtensionObjectHeader Header; 22 | std::vector PolicyId; 23 | 24 | struct UserNameStruct 25 | { 26 | std::string UserName; 27 | std::string Password; 28 | std::string EncryptionAlgorithm; 29 | } UserName; 30 | 31 | UserIdentifyToken(); 32 | 33 | UserTokenType type() const; 34 | void setUser(const std::string &user, const std::string &password); 35 | void setPolicyId(const std::string &id); 36 | }; 37 | 38 | // Moved from subscriptions.h 39 | struct StatusChangeNotification 40 | { 41 | StatusCode Status; 42 | DiagnosticInfo Diagnostic; 43 | }; 44 | 45 | struct EventFieldList 46 | { 47 | IntegerId ClientHandle; 48 | std::vector EventFields; 49 | }; 50 | 51 | struct MonitoredItems 52 | { 53 | IntegerId ClientHandle; 54 | DataValue Value; 55 | }; 56 | 57 | struct EventNotificationList 58 | { 59 | std::vector Events; 60 | }; 61 | 62 | struct DataChangeNotification 63 | { 64 | std::vector Notification; 65 | DiagnosticInfoList Diagnostic; 66 | }; 67 | 68 | struct NotificationData 69 | { 70 | ExtensionObjectHeader Header; 71 | DataChangeNotification DataChange; 72 | EventNotificationList Events; 73 | StatusChangeNotification StatusChange; 74 | 75 | NotificationData(){} 76 | NotificationData(DataChangeNotification notification); 77 | NotificationData(EventNotificationList notification); 78 | NotificationData(StatusChangeNotification notification); 79 | }; 80 | 81 | 82 | // moved from monitored_items.h 83 | 84 | struct DataChangeFilter 85 | { 86 | DataChangeTrigger Trigger; 87 | DeadbandType Deadband; 88 | double DeadbandValue; 89 | }; 90 | 91 | struct SimpleAttributeOperand 92 | { 93 | NodeId TypeId; 94 | std::vector BrowsePath; 95 | AttributeId Attribute; 96 | std::vector IndexRange; 97 | }; 98 | 99 | struct ElementOperand 100 | { 101 | uint32_t Index; 102 | }; 103 | 104 | struct LiteralOperand 105 | { 106 | // BaseDataType Value; // TODO 107 | Variant Value; 108 | }; 109 | 110 | struct AttributeOperand 111 | { 112 | NodeId Node; 113 | std::string Alias; 114 | RelativePath Path; 115 | IntegerId AttributeId; 116 | std::vector IndexRange; 117 | }; 118 | 119 | struct FilterOperand 120 | { 121 | ExtensionObjectHeader Header; 122 | ElementOperand Element; 123 | LiteralOperand Literal; 124 | AttributeOperand Attribute; 125 | SimpleAttributeOperand SimpleAttribute; 126 | }; 127 | 128 | struct ContentFilterElement 129 | { 130 | FilterOperator Operator; 131 | std::vector FilterOperands; 132 | }; 133 | 134 | struct EventFilter 135 | { 136 | std::vector SelectClauses; 137 | std::vector WhereClause; 138 | }; 139 | 140 | struct AggregateFilter 141 | { 142 | DateTime StartTime; 143 | NodeId AggregateType; 144 | Duration ProcessingInterval; 145 | //AggregateConfiguration Configuration; //aggregate conf is in fact the following parameters 146 | bool UseServerCapabilitiesDefaults; 147 | bool TreatUncertainAsBad; 148 | uint8_t PercentDataBad; 149 | uint8_t PercentDataGood; 150 | bool SteppedSlopedExtrapolation; 151 | }; 152 | 153 | struct MonitoringFilter 154 | { 155 | ExtensionObjectHeader Header; 156 | DataChangeFilter DataChange; 157 | EventFilter Event; 158 | AggregateFilter Aggregate; 159 | MonitoringFilter() {} 160 | MonitoringFilter(DataChangeFilter filter); 161 | MonitoringFilter(EventFilter filter); 162 | MonitoringFilter(AggregateFilter filter); 163 | }; 164 | 165 | } // namespace OpcUa 166 | 167 | #endif // __OPC_UA_MAPPING_TYPES_H__ -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/utils.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (C) 2013-2014 by Alexander Rykovanov * 3 | * rykovanov.as@gmail.com * 4 | * * 5 | * This library is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU Lesser General Public License as * 7 | * published by the Free Software Foundation; version 3 of the License. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesser General Public License for more details. * 13 | * * 14 | * You should have received a copy of the GNU Lesser General Public License * 15 | * along with this library; if not, write to the * 16 | * Free Software Foundation, Inc., * 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 | ******************************************************************************/ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace OpcUa 28 | { 29 | 30 | inline void PrintBlob(const std::vector& buf, std::size_t size) 31 | { 32 | size = std::min(size, buf.size()); 33 | unsigned pos = 0; 34 | std::cout << "Data size: " << size << std::endl; 35 | while (pos < size) 36 | { 37 | if (pos) 38 | printf((pos % 16 == 0) ? "\n" : " "); 39 | 40 | const char letter = buf[pos]; 41 | printf("%02x", (unsigned)letter & 0x000000FF); 42 | 43 | if (letter > ' ') 44 | std::cout << "(" << letter << ")"; 45 | else 46 | std::cout << " "; 47 | 48 | ++pos; 49 | } 50 | 51 | std::cout << std::endl << std::flush; 52 | } 53 | 54 | inline void PrintBlob(const std::vector& buf) 55 | { 56 | PrintBlob(buf, buf.size()); 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/variable_access_level.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Well known attributes identifiers. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef OPC_UA_VARIABLE_ACCESS_LEVEL_H_ 12 | #define OPC_UA_VARIABLE_ACCESS_LEVEL_H_ 13 | 14 | #include 15 | 16 | namespace OpcUa 17 | { 18 | enum class VariableAccessLevel : uint8_t 19 | { 20 | CurrentRead = 1, 21 | CurrentWrite = 2, 22 | HistoryRead = 4, 23 | HistoryWrite = 8, 24 | SemanticChange = 16, 25 | }; 26 | } 27 | 28 | #endif /* OPC_UA_VARIABLE_ACCESS_LEVEL_H_ */ 29 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/variant_visitor.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Different implementations of varant visitors. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | 17 | namespace OpcUa 18 | { 19 | 20 | template 21 | class TypedVisitor : public VariantVisitor 22 | { 23 | public: 24 | typedef void result_type; 25 | 26 | public: 27 | TypedVisitor(Delegate& impl) 28 | : Impl(impl) 29 | { 30 | } 31 | 32 | public: 33 | virtual void Visit(bool val) { Impl.OnScalar(val); } 34 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 35 | virtual void Visit(int8_t val) { Impl.OnScalar(val); } 36 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 37 | virtual void Visit(uint8_t val) { Impl.OnScalar(val); } 38 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 39 | virtual void Visit(int16_t val) { Impl.OnScalar(val); } 40 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 41 | virtual void Visit(uint16_t val) { Impl.OnScalar(val); } 42 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 43 | virtual void Visit(int32_t val) { Impl.OnScalar(val); } 44 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 45 | virtual void Visit(uint32_t val) { Impl.OnScalar(val); } 46 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 47 | virtual void Visit(int64_t val) { Impl.OnScalar(val); } 48 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 49 | virtual void Visit(uint64_t val) { Impl.OnScalar(val); } 50 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 51 | virtual void Visit(float val) { Impl.OnScalar(val); } 52 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 53 | virtual void Visit(double val) { Impl.OnScalar(val); } 54 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 55 | virtual void Visit(const std::string& val) { Impl.OnScalar(val); } 56 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 57 | virtual void Visit(const DateTime& val) { Impl.OnScalar(val); } 58 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 59 | virtual void Visit(const Guid& val) { Impl.OnScalar(val); } 60 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 61 | virtual void Visit(const ByteString& val) { Impl.OnScalar(val); } 62 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 63 | virtual void Visit(const NodeId& val) { Impl.OnScalar(val); } 64 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 65 | virtual void Visit(const StatusCode& val) { Impl.OnScalar(val); } 66 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 67 | virtual void Visit(const LocalizedText& val) { Impl.OnScalar(val); } 68 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 69 | virtual void Visit(const QualifiedName& val) { Impl.OnScalar(val); } 70 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 71 | virtual void Visit(const Variant& val) { Impl.OnScalar(val); } 72 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 73 | virtual void Visit(const DiagnosticInfo& val) { Impl.OnScalar(val); } 74 | virtual void Visit(const std::vector& val) { Impl.OnContainer(val); } 75 | 76 | private: 77 | Delegate& Impl; 78 | }; 79 | 80 | 81 | } 82 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/protocol/view.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2012 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Opc Ua Binary. View service. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __OPC_UA_BINARY_VIEW_H__ 12 | #define __OPC_UA_BINARY_VIEW_H__ 13 | 14 | #include 15 | 16 | namespace OpcUa 17 | { 18 | 19 | //--------------------------------------------------- 20 | // Browse 21 | //--------------------------------------------------- 22 | 23 | 24 | 25 | struct ViewDescription 26 | { 27 | NodeId Id; 28 | DateTime Timestamp; 29 | uint32_t Version; 30 | 31 | ViewDescription(); 32 | }; 33 | 34 | struct BrowseDescription 35 | { 36 | NodeId NodeToBrowse; 37 | BrowseDirection Direction; 38 | NodeId ReferenceTypeId; 39 | bool IncludeSubtypes; // If false will follow strctly ReferenceTypeId. if true will follow subtypes of ReferenceTypeId. 40 | NodeClass NodeClasses; 41 | BrowseResultMask ResultMask; 42 | 43 | BrowseDescription(); 44 | }; 45 | 46 | struct NodesQuery 47 | { 48 | ViewDescription View; 49 | uint32_t MaxReferenciesPerNode; 50 | std::vector NodesToBrowse; 51 | 52 | NodesQuery(); 53 | }; 54 | 55 | struct BrowseRequest 56 | { 57 | NodeId TypeId; 58 | RequestHeader Header; 59 | NodesQuery Query; 60 | 61 | BrowseRequest(); 62 | }; 63 | 64 | 65 | struct ReferenceDescription 66 | { 67 | NodeId ReferenceTypeId; 68 | bool IsForward = true; 69 | NodeId TargetNodeId; 70 | QualifiedName BrowseName; 71 | LocalizedText DisplayName; 72 | NodeClass TargetNodeClass; 73 | NodeId TargetNodeTypeDefinition; 74 | 75 | ReferenceDescription(); 76 | }; 77 | 78 | struct BrowseResult 79 | { 80 | StatusCode Status; 81 | std::vector ContinuationPoint; 82 | std::vector Referencies; 83 | 84 | BrowseResult(); 85 | }; 86 | 87 | struct BrowseResponse 88 | { 89 | NodeId TypeId; 90 | ResponseHeader Header; 91 | 92 | std::vector Results; 93 | DiagnosticInfoList Diagnostics; 94 | 95 | BrowseResponse(); 96 | }; 97 | 98 | //--------------------------------------------------- 99 | // BrowseNext 100 | //--------------------------------------------------- 101 | 102 | struct BrowseNextRequest 103 | { 104 | NodeId TypeId; 105 | RequestHeader Header; 106 | 107 | bool ReleaseContinuationPoints; 108 | std::vector> ContinuationPoints; 109 | 110 | BrowseNextRequest(); 111 | }; 112 | 113 | struct BrowseNextResponse 114 | { 115 | NodeId TypeId; 116 | ResponseHeader Header; 117 | 118 | std::vector Results; 119 | DiagnosticInfoList Diagnostics; 120 | 121 | BrowseNextResponse(); 122 | }; 123 | 124 | //--------------------------------------------------- 125 | // TranslateBrowsePathsToNodeIds 126 | //--------------------------------------------------- 127 | 128 | struct BrowsePath 129 | { 130 | NodeId StartingNode; 131 | RelativePath Path; 132 | }; 133 | 134 | struct TranslateBrowsePathsParameters 135 | { 136 | std::vector BrowsePaths; 137 | }; 138 | 139 | struct TranslateBrowsePathsToNodeIdsRequest 140 | { 141 | NodeId TypeId; 142 | RequestHeader Header; 143 | TranslateBrowsePathsParameters Parameters; 144 | 145 | TranslateBrowsePathsToNodeIdsRequest(); 146 | }; 147 | 148 | //--------------------------------------------------- 149 | // TranslateBrowsePathsToNodeIds 150 | //--------------------------------------------------- 151 | 152 | struct BrowsePathTarget 153 | { 154 | NodeId Node; 155 | uint32_t RemainingPathIndex; 156 | 157 | BrowsePathTarget(); 158 | }; 159 | 160 | struct BrowsePathResult 161 | { 162 | StatusCode Status; 163 | std::vector Targets; 164 | 165 | BrowsePathResult(); 166 | }; 167 | 168 | struct TranslateBrowsePathsResult 169 | { 170 | std::vector Paths; 171 | DiagnosticInfoList Diagnostics; 172 | }; 173 | 174 | struct TranslateBrowsePathsToNodeIdsResponse 175 | { 176 | NodeId TypeId; 177 | ResponseHeader Header; 178 | TranslateBrowsePathsResult Result; 179 | 180 | TranslateBrowsePathsToNodeIdsResponse(); 181 | }; 182 | 183 | struct RegisterNodesRequest 184 | { 185 | OpcUa::NodeId TypeId; 186 | OpcUa::RequestHeader Header; 187 | std::vector NodesToRegister; 188 | 189 | RegisterNodesRequest(); 190 | }; 191 | 192 | struct RegisterNodesResponse 193 | { 194 | OpcUa::NodeId TypeId; 195 | OpcUa::ResponseHeader Header; 196 | std::vector Result; 197 | 198 | RegisterNodesResponse(); 199 | }; 200 | 201 | struct UnregisterNodesRequest 202 | { 203 | OpcUa::NodeId TypeId; 204 | OpcUa::RequestHeader Header; 205 | std::vector NodesToUnregister; 206 | 207 | UnregisterNodesRequest(); 208 | }; 209 | 210 | struct UnregisterNodesResponse 211 | { 212 | OpcUa::NodeId TypeId; 213 | OpcUa::ResponseHeader Header; 214 | 215 | UnregisterNodesResponse(); 216 | }; 217 | 218 | } // namespace OpcUa 219 | 220 | #endif // __OPC_UA_BINARY_VIEW_H__ 221 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/addons/address_space.h: -------------------------------------------------------------------------------- 1 | /// @author Olivier Roulet-Dubonnet 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief OPC UA Address space part. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | namespace OpcUa 17 | { 18 | namespace Server 19 | { 20 | 21 | const char AddressSpaceRegistryAddonId[] = "address_space_registry"; 22 | 23 | class AddressSpaceAddonFactory : public Common::AddonFactory 24 | { 25 | public: 26 | DEFINE_CLASS_POINTERS(AddressSpaceAddonFactory); 27 | 28 | public: 29 | virtual Common::Addon::UniquePtr CreateAddon(); 30 | }; 31 | 32 | } // namespace UaServer 33 | } // namespace OpcUa 34 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/addons/asio_addon.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (C) 2013-2014 by Alexander Rykovanov * 3 | * rykovanov.as@gmail.com * 4 | * * 5 | * This library is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU Lesser General Public License as * 7 | * published by the Free Software Foundation; version 3 of the License. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesser General Public License for more details. * 13 | * * 14 | * You should have received a copy of the GNU Lesser General Public License * 15 | * along with this library; if not, write to the * 16 | * Free Software Foundation, Inc., * 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 | ******************************************************************************/ 19 | 20 | #pragma once 21 | 22 | 23 | #include 24 | 25 | 26 | namespace boost 27 | { 28 | namespace asio 29 | { 30 | 31 | class io_service; 32 | 33 | } 34 | } 35 | 36 | namespace OpcUa 37 | { 38 | namespace Server 39 | { 40 | 41 | const char AsioAddonId[] = "async"; 42 | 43 | 44 | class AsioAddon : public Common::Addon 45 | { 46 | public: 47 | DEFINE_CLASS_POINTERS(AsioAddon); 48 | 49 | public: 50 | virtual boost::asio::io_service& GetIoService() = 0; 51 | }; 52 | 53 | 54 | class AsioAddonFactory : public Common::AddonFactory 55 | { 56 | public: 57 | Common::Addon::UniquePtr CreateAddon() override; 58 | }; 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/addons/common_addons.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (C) 2013-2014 by Alexander Rykovanov * 3 | * rykovanov.as@gmail.com * 4 | * * 5 | * This library is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU Lesser General Public License as * 7 | * published by the Free Software Foundation; version 3 of the License. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesser General Public License for more details. * 13 | * * 14 | * You should have received a copy of the GNU Lesser General Public License * 15 | * along with this library; if not, write to the * 16 | * Free Software Foundation, Inc., * 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 | ******************************************************************************/ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace OpcUa 27 | { 28 | namespace Server 29 | { 30 | 31 | struct Parameters 32 | { 33 | /// @Endpoint configuration. 34 | /// listen parameters will be taked from EndpointUrl. 35 | /// Example: 36 | /// opc.tcp://localhost:4841 37 | /// opc.tcp://10.250.1.1:4841 38 | /// opc.tcp://opcua.server.com:4841 39 | EndpointDescription Endpoint; 40 | unsigned ThreadsCount = 1; 41 | bool Debug = false; 42 | }; 43 | 44 | /// @brief parameters of server. 45 | /// can be used at embedded. 46 | void RegisterCommonAddons(const Parameters& params, Common::AddonsManager& addons); 47 | 48 | /// @brief Load parameters from configuration files. 49 | /// This function will enumerate '*.config' files in the directory. 50 | /// configuration file can load third party dynamic addons. 51 | void LoadConfiguration(const std::string& configDirectoryPath, Common::AddonsManager& addons); 52 | 53 | Common::AddonInformation CreateServicesRegistryAddon(); 54 | Common::AddonInformation CreateAddressSpaceAddon(); 55 | Common::AddonInformation CreateStandardNamespaceAddon(); 56 | Common::AddonInformation CreateEndpointsRegistryAddon(); 57 | Common::AddonInformation CreateBinaryServerAddon(); 58 | Common::AddonInformation CreateOpcTcpAsyncAddon(); 59 | Common::AddonInformation CreateServerObjectAddon(); 60 | Common::AddonInformation CreateAsioAddon(); 61 | Common::AddonInformation CreateSubscriptionServiceAddon(); 62 | 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/addons/endpoints_services.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Endpoints addon. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace OpcUa 18 | { 19 | namespace Server 20 | { 21 | 22 | const char EndpointsRegistryAddonId[] = "endpoints_services"; 23 | 24 | 25 | class EndpointsRegistryAddonFactory : public Common::AddonFactory 26 | { 27 | public: 28 | DEFINE_CLASS_POINTERS(EndpointsRegistryAddonFactory); 29 | 30 | public: 31 | virtual Common::Addon::UniquePtr CreateAddon() override; 32 | }; 33 | 34 | } // namespace UaServer 35 | } // nmespace OpcUa 36 | 37 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/addons/opc_tcp_async.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (C) 2013-2014 by Alexander Rykovanov * 3 | * rykovanov.as@gmail.com * 4 | * * 5 | * This library is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU Lesser General Public License as * 7 | * published by the Free Software Foundation; version 3 of the License. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesser General Public License for more details. * 13 | * * 14 | * You should have received a copy of the GNU Lesser General Public License * 15 | * along with this library; if not, write to the * 16 | * Free Software Foundation, Inc., * 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 | ******************************************************************************/ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace OpcUa 27 | { 28 | namespace Server 29 | { 30 | 31 | const char AsyncOpcTcpAddonId[] = "opc_tcp_async"; 32 | 33 | class AsyncOpcTcpAddonFactory : public Common::AddonFactory 34 | { 35 | public: 36 | DEFINE_CLASS_POINTERS(AsyncOpcTcpAddonFactory); 37 | 38 | public: 39 | virtual Common::Addon::UniquePtr CreateAddon() override; 40 | }; 41 | 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/addons/opcua_protocol.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Endpoints addon. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | 17 | 18 | namespace OpcUa 19 | { 20 | namespace Server 21 | { 22 | 23 | const char OpcUaProtocolAddonId[] = "opcua_protocol"; 24 | 25 | class OpcUaProtocolAddonFactory : public Common::AddonFactory 26 | { 27 | public: 28 | DEFINE_CLASS_POINTERS(OpcUaProtocolAddonFactory); 29 | 30 | public: 31 | virtual Common::Addon::UniquePtr CreateAddon() override; 32 | }; 33 | 34 | } // namespace UaServer 35 | } // nmespace OpcUa 36 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/addons/services_registry.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Internal Server wich is used by addons. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | 16 | namespace OpcUa 17 | { 18 | namespace Server 19 | { 20 | 21 | const char ServicesRegistryAddonId[] = "services_registry"; 22 | 23 | class ServicesRegistryFactory : public Common::AddonFactory 24 | { 25 | public: 26 | DEFINE_CLASS_POINTERS(ServicesRegistryFactory); 27 | 28 | public: 29 | virtual Common::Addon::UniquePtr CreateAddon(); 30 | }; 31 | 32 | } // namespace UaServer 33 | } // namespace OpcUa 34 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/addons/standard_address_space.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Function which fill standard opcua address space. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | 16 | namespace OpcUa 17 | { 18 | namespace Server 19 | { 20 | 21 | class StandardNamespaceAddonFactory : public Common::AddonFactory 22 | { 23 | public: 24 | virtual Common::Addon::UniquePtr CreateAddon(); 25 | }; 26 | 27 | const char StandardNamespaceAddonId[] = "standard_namespace"; 28 | 29 | } // namespace UaServer 30 | } // namespace OpcUa 31 | 32 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/addons/subscription_service.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2014 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Subscription service addon. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | namespace OpcUa 16 | { 17 | namespace Server 18 | { 19 | 20 | const char SubscriptionServiceAddonId[] = "subscriptions"; 21 | 22 | class SubscriptionServiceAddonFactory : public Common::AddonFactory 23 | { 24 | public: 25 | virtual Common::Addon::UniquePtr CreateAddon(); 26 | }; 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/addons/xml_ns.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief OPC UA Address space part. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | namespace OpcUa 17 | { 18 | namespace Server 19 | { 20 | 21 | const char XmlAddressSpaceAddonId[] = "xml_address_space"; 22 | 23 | class XmlAddressSpace : public Common::Addon 24 | { 25 | public: 26 | virtual void Load(const char* path) = 0; 27 | }; 28 | 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/address_space.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief View services addon. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | namespace OpcUa 21 | { 22 | namespace Server 23 | { 24 | 25 | typedef void DataChangeCallback(const NodeId& node, AttributeId attribute, DataValue); 26 | 27 | class AddressSpace 28 | : public ViewServices 29 | , public AttributeServices 30 | , public NodeManagementServices 31 | { 32 | public: 33 | DEFINE_CLASS_POINTERS(AddressSpace); 34 | 35 | //Server side methods 36 | virtual uint32_t AddDataChangeCallback(const NodeId& node, AttributeId attribute, std::function callback) = 0; 37 | virtual void DeleteDataChangeCallback(uint32_t clienthandle) = 0; 38 | virtual StatusCode SetValueCallback(const NodeId& node, AttributeId attribute, std::function callback) = 0; 39 | //FIXME : SHould we also expose SetValue and GetValue on server side? then we need to lock them ... 40 | }; 41 | 42 | AddressSpace::UniquePtr CreateAddressSpace(bool debug); 43 | 44 | } // namespace UaServer 45 | } // nmespace OpcUa 46 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/endpoints_services.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Endpoints addon. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | 16 | namespace OpcUa 17 | { 18 | namespace Server 19 | { 20 | 21 | struct ApplicationData 22 | { 23 | ApplicationDescription Application; 24 | std::vector Endpoints; 25 | }; 26 | 27 | class EndpointsRegistry : public OpcUa::EndpointServices 28 | { 29 | public: 30 | DEFINE_CLASS_POINTERS(EndpointsRegistry); 31 | 32 | public: 33 | virtual void AddEndpoints(const std::vector& endpoints) = 0; 34 | virtual void AddApplications(const std::vector& application) = 0; 35 | }; 36 | 37 | EndpointsRegistry::UniquePtr CreateEndpointsRegistry(); 38 | 39 | } // namespace UaServer 40 | } // namespace OpcUa 41 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/opc_tcp_async.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (C) 2013-2014 by Alexander Rykovanov * 3 | * rykovanov.as@gmail.com * 4 | * * 5 | * This library is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU Lesser General Public License as * 7 | * published by the Free Software Foundation; version 3 of the License. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesser General Public License for more details. * 13 | * * 14 | * You should have received a copy of the GNU Lesser General Public License * 15 | * along with this library; if not, write to the * 16 | * Free Software Foundation, Inc., * 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 | ******************************************************************************/ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | namespace boost 26 | { 27 | namespace asio 28 | { 29 | class io_service; 30 | } 31 | } 32 | 33 | namespace OpcUa 34 | { 35 | namespace Server 36 | { 37 | 38 | class AsyncOpcTcp : private Common::Interface 39 | { 40 | public: 41 | DEFINE_CLASS_POINTERS(AsyncOpcTcp); 42 | 43 | public: 44 | struct Parameters 45 | { 46 | std::string Host; 47 | unsigned Port = 4840; 48 | bool DebugMode = false; 49 | }; 50 | 51 | public: 52 | virtual void Listen() = 0; 53 | virtual void Shutdown() = 0; 54 | }; 55 | 56 | AsyncOpcTcp::UniquePtr CreateAsyncOpcTcp(const AsyncOpcTcp::Parameters& params, Services::SharedPtr server, boost::asio::io_service& io); 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/server.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace OpcUa 14 | { 15 | class UaServer 16 | { 17 | public: 18 | /// @brief create high level server 19 | // this class is meant to be used to quickly/easily add OPCUA interface to an application 20 | // it may not offer absolutely all features available in protocol 21 | // you may want to look at code and implement your own server if you need 22 | // debug argument will make freeopcua write A LOT to stdout 23 | UaServer(); 24 | explicit UaServer(bool debug); 25 | 26 | /// @brief set endpoint uri on wich server will listen. 27 | /// opc.tcp://localhost:4841/opcua/server 28 | /// opc.tcp://192.168.1.1:4840/opcua/server 29 | /// opc.tcp://server.freeopca.org:4841/opcua/server 30 | void SetEndpoint(const std::string& endpoint); 31 | 32 | /// @brief setup server description 33 | void SetProductURI(const std::string& uri); 34 | void SetServerURI(const std::string& uri); 35 | void SetServerName(const std::string& name); 36 | 37 | /// @brief load xml addressspace. This is not implemented yet!!! 38 | void AddAddressSpace(const std::string& path); 39 | 40 | /// @brief Enable event notification on Server node 41 | /// this is necessary if you want to be able to send custom events 42 | // (Not for datachange events!) 43 | void EnableEventNotification(); 44 | 45 | /// @brief Register your application namespace 46 | // Every application will probably have its own namespace 47 | // example: urn:mydomain:myfancyapplication 48 | // the returned index will then be used 49 | uint32_t RegisterNamespace(std::string uri); 50 | uint32_t GetNamespaceIndex(std::string uri); 51 | 52 | /// @brief Start and Stop server 53 | // if you do not stop server you may get into trouble! 54 | // we have several threads running 55 | void Start(); 56 | void Stop(); 57 | 58 | /// @brief Get a specific node by nodeid 59 | // you can also access a standard node from addressspace using 60 | // ObjectId, for example: 61 | // Node mynode = GetNode(ObjectId::Server); 62 | // using a string is also possible: 63 | // Node mynode = GetNode("ns=3;i=55"); 64 | Node GetNode(const NodeId& nodeid) const; 65 | Node GetNode(const std::string& nodeid) const; 66 | 67 | /// @brief helper methods for node you will probably want to access 68 | Node GetRootNode() const; 69 | Node GetObjectsNode() const; 70 | Node GetServerNode() const; 71 | 72 | /// @brief Get a node using its browsepath 73 | Node GetNodeFromPath(const std::vector& path) const; 74 | Node GetNodeFromPath(const std::vector& path) const; 75 | 76 | /// @brief Trigger and event 77 | // Event will be send from Server node. 78 | // It is possible to send events from arbitrarily nodes but it looks like 79 | // most servers only send events from Server node 80 | void TriggerEvent(Event event); 81 | 82 | /// @brief Create a subscription objects 83 | // returned object can then be used to subscribe to 84 | // datachange or custom events on server side 85 | std::unique_ptr CreateSubscription(unsigned int period, SubscriptionHandler& callback); 86 | 87 | /// @brief Create a server operations object 88 | ServerOperations CreateServerOperations(); 89 | 90 | protected: 91 | std::vector XmlAddressSpaces; 92 | // defined some sensible defaults that should let most clients connects 93 | std::string Endpoint; 94 | std::string ServerUri = "urn:freeopcua:server"; 95 | std::string ProductUri = "urn:freeopcua.github.no:server"; 96 | std::string Name = "FreeOpcUa Server"; 97 | bool Debug = false; 98 | bool LoadCppAddressSpace = true; 99 | OpcUa::MessageSecurityMode SecurityMode = OpcUa::MessageSecurityMode::None; 100 | void CheckStarted() const; 101 | 102 | Common::AddonsManager::SharedPtr Addons; 103 | Server::ServicesRegistry::SharedPtr Registry; 104 | Server::SubscriptionService::SharedPtr SubscriptionService; 105 | }; 106 | 107 | } 108 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/services_registry.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Internal Server wich is used by addons. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | namespace OpcUa 16 | { 17 | namespace Server 18 | { 19 | 20 | class ServicesRegistry : private Common::Interface 21 | { 22 | public: 23 | DEFINE_CLASS_POINTERS(ServicesRegistry); 24 | 25 | public: 26 | virtual std::shared_ptr GetServer() const = 0; 27 | 28 | virtual void RegisterEndpointsServices(OpcUa::EndpointServices::SharedPtr endpoints) = 0; 29 | virtual void UnregisterEndpointsServices() = 0; 30 | 31 | virtual void RegisterViewServices(OpcUa::ViewServices::SharedPtr views) = 0; 32 | virtual void UnregisterViewServices() = 0; 33 | 34 | virtual void RegisterAttributeServices(OpcUa::AttributeServices::SharedPtr attributes) = 0; 35 | virtual void UnregisterAttributeServices() = 0; 36 | 37 | virtual void RegisterMethodServices(MethodServices::SharedPtr method) = 0; 38 | virtual void UnregisterMethodServices() = 0; 39 | 40 | virtual void RegisterNodeManagementServices(OpcUa::NodeManagementServices::SharedPtr attributes) = 0; 41 | virtual void UnregisterNodeManagementServices() = 0; 42 | 43 | virtual void RegisterSubscriptionServices(OpcUa::SubscriptionServices::SharedPtr attributes) = 0; 44 | virtual void UnregisterSubscriptionServices() = 0; 45 | }; 46 | 47 | ServicesRegistry::UniquePtr CreateServicesRegistry(); 48 | 49 | } 50 | } // namespace OpcUa 51 | 52 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/standard_address_space.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Function which fill standard opcua address space. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | namespace OpcUa 16 | { 17 | namespace Server 18 | { 19 | 20 | void FillStandardNamespace(OpcUa::NodeManagementServices& registry, bool debug); 21 | 22 | } // namespace UaServer 23 | } // namespace OpcUa 24 | 25 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server/subscription_service.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief View services addon. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | namespace boost 19 | { 20 | namespace asio 21 | { 22 | class io_service; 23 | } 24 | } 25 | 26 | namespace OpcUa 27 | { 28 | namespace Server 29 | { 30 | 31 | class SubscriptionService : public SubscriptionServices 32 | { 33 | public: 34 | DEFINE_CLASS_POINTERS(SubscriptionService); 35 | 36 | virtual void TriggerEvent(NodeId node, Event event) = 0; 37 | }; 38 | 39 | SubscriptionService::UniquePtr CreateSubscriptionService(std::shared_ptr addressspace, boost::asio::io_service& io, bool debug); 40 | 41 | } // namespace UaServer 42 | } // nmespace OpcUa 43 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/server_operations.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "opc/ua/services/services.h" 4 | #include "opc/ua/node.h" 5 | 6 | #include 7 | 8 | namespace OpcUa{ 9 | class UaClient; 10 | class UaServer; 11 | 12 | class ServerOperations { 13 | friend UaClient; 14 | friend UaServer; 15 | 16 | Services::SharedPtr Server; 17 | protected: 18 | ServerOperations(Services::SharedPtr Server); 19 | 20 | public: 21 | void WriteAttributes(std::vector&); 22 | std::vector ReadAttributes(std::vector& attributes); 23 | std::vector ReadAttributes(std::vector& nodes, AttributeId attr); 24 | std::vector RegisterNodes(std::vector&); 25 | //NB This makes the given nodes invalid 26 | void UnregisterNodes(std::vector&); 27 | }; 28 | } -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/services/attributes.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief View services interface. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef OPC_UA_Client_ATTRIBUTES_H 12 | #define OPC_UA_Client_ATTRIBUTES_H 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | namespace OpcUa 23 | { 24 | 25 | class AttributeServices : private Common::Interface 26 | { 27 | public: 28 | DEFINE_CLASS_POINTERS(AttributeServices); 29 | 30 | public: 31 | virtual std::vector Read(const OpcUa::ReadParameters& filter) const = 0; 32 | virtual std::vector Write(const std::vector& filter) = 0; 33 | }; 34 | 35 | } // namespace OpcUa 36 | 37 | #endif // OPC_UA_Client_ATTRIBUTES_H 38 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/services/endpoints.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Opc endpoints interface. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef OPC_UA_Client_ENDPOINTS_H 12 | #define OPC_UA_Client_ENDPOINTS_H 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace OpcUa 21 | { 22 | 23 | struct ApplicationFilter 24 | { 25 | }; 26 | struct ServerParameters 27 | { 28 | }; 29 | 30 | class EndpointServices : private Common::Interface 31 | { 32 | public: 33 | DEFINE_CLASS_POINTERS(EndpointServices); 34 | 35 | public: 36 | virtual std::vector FindServers(const FindServersParameters& params) const = 0; 37 | // TODO Here all structuresmust be in one namespace. 38 | virtual std::vector GetEndpoints(const GetEndpointsParameters& filter) const = 0; 39 | virtual void RegisterServer(const ServerParameters& parameters) = 0; 40 | }; 41 | 42 | } // namespace OpcUa 43 | 44 | #endif // OPC_UA_Client_ENDPOINTS_H 45 | 46 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/services/method.h: -------------------------------------------------------------------------------- 1 | /// @author Denis Štogl 2015 2 | /// @email denis.stogl@mailbox.org 3 | /// @brief Method services interface. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef OPC_UA_Client_METHOD_H 12 | #define OPC_UA_Client_METHOD_H 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | namespace OpcUa 21 | { 22 | 23 | class MethodServices : private Common::Interface 24 | { 25 | public: 26 | DEFINE_CLASS_POINTERS(MethodServices); 27 | 28 | public: 29 | virtual std::vector Call(const std::vector& methodsToCall) = 0; 30 | }; 31 | 32 | } // namespace OpcUa 33 | 34 | #endif // OPC_UA_Client_METHOD_H 35 | 36 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/services/node_management.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief View services interface. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef OPC_UA_Client_ADDRESSSPACE_H 12 | #define OPC_UA_Client_ADDRESSSPACE_H 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | namespace OpcUa 23 | { 24 | 25 | class NodeManagementServices : private Common::Interface 26 | { 27 | public: 28 | DEFINE_CLASS_POINTERS(NodeManagementServices); 29 | 30 | public: 31 | virtual std::vector AddNodes(const std::vector& items) = 0; 32 | virtual std::vector AddReferences(const std::vector& items) = 0; 33 | }; 34 | 35 | } // namespace OpcUa 36 | 37 | #endif // OPC_UA_Client_ADDRESSSPACE_H 38 | 39 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/services/services.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Opc Ua computer interface. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | namespace OpcUa 29 | { 30 | 31 | struct RemoteSessionParameters 32 | { 33 | ApplicationDescription ClientDescription; 34 | std::vector ClientCertificate; 35 | std::string SessionName; 36 | std::string ServerURI; 37 | std::string EndpointUrl; 38 | Duration Timeout; 39 | }; 40 | 41 | class Services : private Common::Interface 42 | { 43 | public: 44 | DEFINE_CLASS_POINTERS(Services); 45 | 46 | public: 47 | virtual OpenSecureChannelResponse OpenSecureChannel(const OpenSecureChannelParameters& parameters) = 0; 48 | virtual void CloseSecureChannel(uint32_t channelId) = 0; 49 | virtual CreateSessionResponse CreateSession(const RemoteSessionParameters& parameters) = 0; 50 | virtual ActivateSessionResponse ActivateSession(const ActivateSessionParameters &session_parameters) = 0; 51 | virtual CloseSessionResponse CloseSession() = 0; 52 | virtual void AbortSession() = 0; 53 | 54 | virtual AttributeServices::SharedPtr Attributes() = 0; 55 | virtual EndpointServices::SharedPtr Endpoints() = 0; 56 | virtual MethodServices::SharedPtr Method() = 0; 57 | virtual NodeManagementServices::SharedPtr NodeManagement() = 0; 58 | virtual SubscriptionServices::SharedPtr Subscriptions() = 0; 59 | virtual ViewServices::SharedPtr Views() = 0; 60 | }; 61 | 62 | } 63 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/services/subscriptions.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Subscription services interface. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef __OPC_UA_Client_SUBSCRIPTIONS_H 12 | #define __OPC_UA_Client_SUBSCRIPTIONS_H 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | namespace OpcUa 21 | { 22 | 23 | class SubscriptionServices : private Common::Interface 24 | { 25 | public: 26 | DEFINE_CLASS_POINTERS(SubscriptionServices); 27 | 28 | public: 29 | virtual SubscriptionData CreateSubscription(const CreateSubscriptionRequest&, std::function callbackPublish) = 0; 30 | virtual std::vector DeleteSubscriptions(const std::vector& subscriptions) = 0; 31 | virtual void Publish(const PublishRequest& request) = 0; 32 | virtual RepublishResponse Republish(const RepublishParameters& params) = 0; 33 | 34 | //FIXME: Spec says MonitoredItems methods should be in their own service 35 | virtual std::vector CreateMonitoredItems(const MonitoredItemsParameters& parameters) = 0; 36 | virtual std::vector DeleteMonitoredItems(const DeleteMonitoredItemsParameters& params) = 0; 37 | }; 38 | 39 | } 40 | 41 | #endif // __OPC_UA_Client_SUBSCRIPTIONS_H 42 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/services/view.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2013 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief View services interface. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef OPC_UA_Client_VIEW_H 12 | #define OPC_UA_Client_VIEW_H 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | namespace OpcUa 22 | { 23 | 24 | class ViewServices : private Common::Interface 25 | { 26 | public: 27 | DEFINE_CLASS_POINTERS(ViewServices); 28 | 29 | public: 30 | virtual std::vector Browse(const OpcUa::NodesQuery& query) const = 0; 31 | virtual std::vector BrowseNext() const = 0; 32 | virtual std::vector TranslateBrowsePathsToNodeIds(const TranslateBrowsePathsParameters& params) const = 0; 33 | virtual std::vector RegisterNodes(const std::vector& params) const = 0; 34 | virtual void UnregisterNodes(const std::vector& params) const = 0; 35 | }; 36 | 37 | } // namespace OpcUa 38 | 39 | #endif // OPC_UA_Client_VIEW_H 40 | 41 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/socket_channel.h: -------------------------------------------------------------------------------- 1 | /// @author Alexander Rykovanov 2012 2 | /// @email rykovanov.as@gmail.com 3 | /// @brief Opc binary cnnection channel. 4 | /// @license GNU LGPL 5 | /// 6 | /// Distributed under the GNU LGPL License 7 | /// (See accompanying file LICENSE or copy at 8 | /// http://www.gnu.org/licenses/lgpl.html) 9 | /// 10 | 11 | #ifndef OPC_UA_Client_SOCKET_CHANNEL_H 12 | #define OPC_UA_Client_SOCKET_CHANNEL_H 13 | 14 | #include 15 | 16 | namespace OpcUa 17 | { 18 | 19 | class SocketChannel : public OpcUa::IOChannel 20 | { 21 | public: 22 | SocketChannel(int sock); 23 | virtual ~SocketChannel(); 24 | 25 | virtual std::size_t Receive(char* data, std::size_t size); 26 | virtual void Send(const char* message, std::size_t size); 27 | 28 | virtual void Stop(); 29 | 30 | private: 31 | int Socket; 32 | }; 33 | 34 | } 35 | 36 | #endif // OPC_UA_Client_SOCKET_CHANNEL_H 37 | 38 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_include/opc/ua/subscription.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (C) 2014-2014 Olivier Roulet-Dubonnet * 3 | * olivier.roulet@gmail.com * 4 | * * 5 | * This library is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU Lesser General Public License as * 7 | * published by the Free Software Foundation; version 3 of the License. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesser General Public License for more details. * 13 | * * 14 | * You should have received a copy of the GNU Lesser General Public License * 15 | * along with this library; if not, write to the * 16 | * Free Software Foundation, Inc., * 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 | ******************************************************************************/ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include //debug 32 | 33 | namespace OpcUa 34 | { 35 | // the better void pointer 36 | struct UserData 37 | { 38 | }; 39 | 40 | struct MonitoredItemData 41 | { 42 | IntegerId MonitoredItemId; 43 | Node TargetNode; 44 | AttributeId Attribute; 45 | MonitoringFilter Filter; 46 | UserData *usrVar; 47 | }; 48 | 49 | typedef std::map AttValMap; 50 | typedef std::map SimpleAttOpMap; 51 | 52 | class SubscriptionHandler 53 | { 54 | public: 55 | virtual ~SubscriptionHandler() {} 56 | //Called for each datachange events 57 | virtual void DataChange(uint32_t handle, const Node& node, const Variant& val, AttributeId attribute) 58 | { 59 | OPCUA_UNUSED(handle); 60 | OPCUA_UNUSED(node); 61 | OPCUA_UNUSED(val); 62 | OPCUA_UNUSED(attribute); 63 | std::cout << "default dc" << std::endl; 64 | } 65 | //Called for each datachange events 66 | // Same as DataChange(), but it provides whole DataValue type with aditional fields like time stamps 67 | virtual void DataValueChange(uint32_t handle, const Node& node, const DataValue& val, AttributeId attribute) 68 | { 69 | OPCUA_UNUSED(handle); 70 | OPCUA_UNUSED(node); 71 | OPCUA_UNUSED(val); 72 | OPCUA_UNUSED(attribute); 73 | } 74 | //Called for every events receive from server 75 | virtual void Event(uint32_t handle, const Event& event) 76 | { 77 | OPCUA_UNUSED(handle); 78 | OPCUA_UNUSED(event); 79 | std::cout << "default c++ event callback has been called" << std::endl; 80 | } 81 | //Called at server state changed 82 | virtual void StatusChange(StatusCode status) 83 | { 84 | OPCUA_UNUSED(status); 85 | } 86 | }; 87 | 88 | 89 | class Subscription 90 | { 91 | public: 92 | //Create a new subscription on server 93 | //methods of callback object will be called everytime an event is received from the server 94 | //FIXME: should we use interface or std::function for callback???? std::function syntax is ugly but is more flexible 95 | //Alternative could be 96 | //AddDataChangeCallback(std::function callback); 97 | //AddEventCallback(std::function> callback); 98 | Subscription(Services::SharedPtr server, const CreateSubscriptionParameters& params, SubscriptionHandler& callback, bool debug=false); 99 | virtual ~Subscription() {} 100 | 101 | //Delete the subscription from server 102 | void Delete(); 103 | 104 | //Get information about the subscription 105 | SubscriptionData GetData() {return Data; } 106 | uint32_t GetId() const { return Data.SubscriptionId; } 107 | double GetPeriode() const { return Data.RevisedPublishingInterval; } 108 | 109 | //Subscribe to a Node attribute for its value to change 110 | // Subscribe to nodes for specified attribute change 111 | uint32_t SubscribeDataChange(const Node& node, AttributeId attr=AttributeId::Value); 112 | std::vector SubscribeDataChange(const std::vector& attributes); 113 | 114 | // UserData pointer to have acces to user data in callback functions DataChange(),DataValueChange() 115 | void setUsrPtr(uint32_t handle,UserData *usr); 116 | UserData* getUsrPtr(uint32_t handle); 117 | 118 | //Unsubscribe to datachange or events 119 | void UnSubscribe(uint32_t handle); 120 | void UnSubscribe(std::vector handles); 121 | 122 | //Subscribe to Events for given node 123 | //As far as I remember the only allowed node is Server in most SDKs 124 | uint32_t SubscribeEvents(const Node& node, const EventFilter& eventfilter); 125 | uint32_t SubscribeEvents(const Node& node, const Node& eventType); //subscribe to all variables og given event type 126 | uint32_t SubscribeEvents(); //subscribe to variables of baseEventTypes and ServerNode 127 | 128 | // Subscribe using a MonitoredItemCreateRequest 129 | // This method allow to fully customize the subscription 130 | std::vector Subscribe(std::vector request); 131 | 132 | // Override this method if you want raw publish results from server 133 | // for example if you want to make sure you do not miss any packets, etc, ... 134 | virtual void PublishCallback( Services::SharedPtr serverLocalPtr, const PublishResult result); 135 | 136 | //Request republish of a notification from server 137 | //SequenceNumber are send by server in PublishResult struct 138 | RepublishResponse Republish(uint32_t sequenceNumber); 139 | 140 | 141 | 142 | private: 143 | void CallDataChangeCallback(const NotificationData& data); 144 | void CallEventCallback(const NotificationData& data); 145 | void CallStatusChangeCallback(const NotificationData& data); 146 | 147 | Services::SharedPtr Server; 148 | SubscriptionData Data; 149 | SubscriptionHandler& Client; 150 | uint32_t LastMonitoredItemHandle = 1; 151 | AttValMap AttributeValueMap; 152 | SimpleAttOpMap SimpleAttributeOperandMap; //Not used currently 153 | std::mutex Mutex; 154 | bool Debug; 155 | }; 156 | } 157 | 158 | 159 | -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_libs_mingw32/libopcuaclient.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Harha/OPC-UA-to-MQTT-Gateway/7afa2157c3ae79bd1272da1d4efdfa4f7a24f05c/libraries/freeopcua/freeopcua_libs_mingw32/libopcuaclient.dll -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_libs_mingw32/libopcuaclient.dll.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Harha/OPC-UA-to-MQTT-Gateway/7afa2157c3ae79bd1272da1d4efdfa4f7a24f05c/libraries/freeopcua/freeopcua_libs_mingw32/libopcuaclient.dll.a -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_libs_mingw32/libopcuacore.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Harha/OPC-UA-to-MQTT-Gateway/7afa2157c3ae79bd1272da1d4efdfa4f7a24f05c/libraries/freeopcua/freeopcua_libs_mingw32/libopcuacore.dll -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_libs_mingw32/libopcuacore.dll.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Harha/OPC-UA-to-MQTT-Gateway/7afa2157c3ae79bd1272da1d4efdfa4f7a24f05c/libraries/freeopcua/freeopcua_libs_mingw32/libopcuacore.dll.a -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_libs_mingw32/libopcuaprotocol.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Harha/OPC-UA-to-MQTT-Gateway/7afa2157c3ae79bd1272da1d4efdfa4f7a24f05c/libraries/freeopcua/freeopcua_libs_mingw32/libopcuaprotocol.dll -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_libs_mingw32/libopcuaprotocol.dll.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Harha/OPC-UA-to-MQTT-Gateway/7afa2157c3ae79bd1272da1d4efdfa4f7a24f05c/libraries/freeopcua/freeopcua_libs_mingw32/libopcuaprotocol.dll.a -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_libs_mingw32/libopcuaserver.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Harha/OPC-UA-to-MQTT-Gateway/7afa2157c3ae79bd1272da1d4efdfa4f7a24f05c/libraries/freeopcua/freeopcua_libs_mingw32/libopcuaserver.dll -------------------------------------------------------------------------------- /libraries/freeopcua/freeopcua_libs_mingw32/libopcuaserver.dll.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Harha/OPC-UA-to-MQTT-Gateway/7afa2157c3ae79bd1272da1d4efdfa4f7a24f05c/libraries/freeopcua/freeopcua_libs_mingw32/libopcuaserver.dll.a -------------------------------------------------------------------------------- /libraries/mosquitto/LICENSE.md: -------------------------------------------------------------------------------- 1 | This project is dual licensed under the Eclipse Public License 1.0 and the 2 | Eclipse Distribution License 1.0 as described in the epl-v10 and edl-v10 files. -------------------------------------------------------------------------------- /libraries/mosquitto/README.md: -------------------------------------------------------------------------------- 1 | # Mosquitto C/C++ library 2 | 3 | http://mosquitto.org/ -------------------------------------------------------------------------------- /libraries/mosquitto/mosquitto_include/cpp/mosquittopp.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2013 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef _MOSQUITTOPP_H_ 18 | #define _MOSQUITTOPP_H_ 19 | 20 | #ifdef _WIN32 21 | # ifdef mosquittopp_EXPORTS 22 | # define mosqpp_EXPORT __declspec(dllexport) 23 | # else 24 | # define mosqpp_EXPORT __declspec(dllimport) 25 | # endif 26 | #else 27 | # define mosqpp_EXPORT 28 | #endif 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | namespace mosqpp { 35 | 36 | mosqpp_EXPORT const char *strerror(int mosq_errno); 37 | mosqpp_EXPORT const char *connack_string(int connack_code); 38 | mosqpp_EXPORT int sub_topic_tokenise(const char *subtopic, char ***topics, int *count); 39 | mosqpp_EXPORT int sub_topic_tokens_free(char ***topics, int count); 40 | mosqpp_EXPORT int lib_version(int *major, int *minor, int *revision); 41 | mosqpp_EXPORT int lib_init(); 42 | mosqpp_EXPORT int lib_cleanup(); 43 | mosqpp_EXPORT int topic_matches_sub(const char *sub, const char *topic, bool *result); 44 | 45 | /* 46 | * Class: mosquittopp 47 | * 48 | * A mosquitto client class. This is a C++ wrapper class for the mosquitto C 49 | * library. Please see mosquitto.h for details of the functions. 50 | */ 51 | class mosqpp_EXPORT mosquittopp { 52 | private: 53 | struct mosquitto *m_mosq; 54 | public: 55 | mosquittopp(const char *id=NULL, bool clean_session=true); 56 | virtual ~mosquittopp(); 57 | 58 | int reinitialise(const char *id, bool clean_session); 59 | int socket(); 60 | int will_set(const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false); 61 | int will_clear(); 62 | int username_pw_set(const char *username, const char *password=NULL); 63 | int connect(const char *host, int port=1883, int keepalive=60); 64 | int connect_async(const char *host, int port=1883, int keepalive=60); 65 | int connect(const char *host, int port, int keepalive, const char *bind_address); 66 | int connect_async(const char *host, int port, int keepalive, const char *bind_address); 67 | int reconnect(); 68 | int reconnect_async(); 69 | int disconnect(); 70 | int publish(int *mid, const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false); 71 | int subscribe(int *mid, const char *sub, int qos=0); 72 | int unsubscribe(int *mid, const char *sub); 73 | void reconnect_delay_set(unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff); 74 | int max_inflight_messages_set(unsigned int max_inflight_messages); 75 | void message_retry_set(unsigned int message_retry); 76 | void user_data_set(void *userdata); 77 | int tls_set(const char *cafile, const char *capath=NULL, const char *certfile=NULL, const char *keyfile=NULL, int (*pw_callback)(char *buf, int size, int rwflag, void *userdata)=NULL); 78 | int tls_opts_set(int cert_reqs, const char *tls_version=NULL, const char *ciphers=NULL); 79 | int tls_insecure_set(bool value); 80 | int tls_psk_set(const char *psk, const char *identity, const char *ciphers=NULL); 81 | int opts_set(enum mosq_opt_t option, void *value); 82 | 83 | int loop(int timeout=-1, int max_packets=1); 84 | int loop_misc(); 85 | int loop_read(int max_packets=1); 86 | int loop_write(int max_packets=1); 87 | int loop_forever(int timeout=-1, int max_packets=1); 88 | int loop_start(); 89 | int loop_stop(bool force=false); 90 | bool want_write(); 91 | int threaded_set(bool threaded=true); 92 | int socks5_set(const char *host, int port=1080, const char *username=NULL, const char *password=NULL); 93 | 94 | /* <-- We don't need C++ API. 95 | virtual void on_connect(int rc) {return;}; 96 | virtual void on_disconnect(int rc) {return;}; 97 | virtual void on_publish(int mid) {return;}; 98 | virtual void on_message(const struct mosquitto_message *message) {return;}; 99 | virtual void on_subscribe(int mid, int qos_count, const int *granted_qos) {return;}; 100 | virtual void on_unsubscribe(int mid) {return;}; 101 | virtual void on_log(int level, const char *str) {return;}; 102 | virtual void on_error() {return;}; 103 | */ 104 | }; 105 | 106 | } 107 | #endif 108 | -------------------------------------------------------------------------------- /libraries/mosquitto/mosquitto_libs_mingw32/libmosquitto.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Harha/OPC-UA-to-MQTT-Gateway/7afa2157c3ae79bd1272da1d4efdfa4f7a24f05c/libraries/mosquitto/mosquitto_libs_mingw32/libmosquitto.dll -------------------------------------------------------------------------------- /libraries/mosquitto/mosquitto_libs_mingw32/libmosquitto.dll.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Harha/OPC-UA-to-MQTT-Gateway/7afa2157c3ae79bd1272da1d4efdfa4f7a24f05c/libraries/mosquitto/mosquitto_libs_mingw32/libmosquitto.dll.a -------------------------------------------------------------------------------- /libraries/mosquitto/mosquitto_libs_mingw32/libmosquittopp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Harha/OPC-UA-to-MQTT-Gateway/7afa2157c3ae79bd1272da1d4efdfa4f7a24f05c/libraries/mosquitto/mosquitto_libs_mingw32/libmosquittopp.dll -------------------------------------------------------------------------------- /libraries/mosquitto/mosquitto_libs_mingw32/libmosquittopp.dll.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Harha/OPC-UA-to-MQTT-Gateway/7afa2157c3ae79bd1272da1d4efdfa4f7a24f05c/libraries/mosquitto/mosquitto_libs_mingw32/libmosquittopp.dll.a --------------------------------------------------------------------------------