server.h
Go to the documentation of this file.
1 #pragma once
2 
3 
5 #include <opc/ua/event.h>
6 #include <opc/ua/node.h>
10 #include <opc/ua/subscription.h>
12 
13 namespace OpcUa
14 {
15 class UaServer
16 {
17 public:
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  explicit UaServer(const Common::Logger::SharedPtr & logger);
26 
31  void SetEndpoint(const std::string & endpoint);
32 
34  void SetProductURI(const std::string & uri);
35  void SetServerURI(const std::string & uri);
36  void SetServerName(const std::string & name);
37 
39  void AddAddressSpace(const std::string & path);
40 
43  // (Not for datachange events!)
45 
47  // Every application will probably have its own namespace
48  // example: urn:mydomain:myfancyapplication
49  // the returned index will then be used
50  uint32_t RegisterNamespace(std::string uri);
51  uint32_t GetNamespaceIndex(std::string uri);
52 
54  // if you do not stop server you may get into trouble!
55  // we have several threads running
56  void Start();
57  void Stop();
58 
60  // you can also access a standard node from addressspace using
61  // ObjectId, for example:
62  // Node mynode = GetNode(ObjectId::Server);
63  // using a string is also possible:
64  // Node mynode = GetNode("ns=3;i=55");
65  Node GetNode(const NodeId & nodeid) const;
66  Node GetNode(const std::string & nodeid) const;
67 
69  Node GetRootNode() const;
70  Node GetObjectsNode() const;
71  Node GetServerNode() const;
72 
74  Node GetNodeFromPath(const std::vector<QualifiedName> & path) const;
75  Node GetNodeFromPath(const std::vector<std::string> & path) const;
76 
78  // Event will be send from Server node.
79  // It is possible to send events from arbitrarily nodes but it looks like
80  // most servers only send events from Server node
81  void TriggerEvent(Event event);
82 
84  // returned object can then be used to subscribe to
85  // datachange or custom events on server side
86  Subscription::SharedPtr CreateSubscription(unsigned int period, SubscriptionHandler & callback);
87 
90 
91 protected:
92  std::vector<std::string> XmlAddressSpaces;
93  // defined some sensible defaults that should let most clients connects
95  std::string ServerUri = "urn:freeopcua:server";
96  std::string ProductUri = "urn:freeopcua.github.no:server";
97  std::string Name = "FreeOpcUa Server";
98  Common::Logger::SharedPtr Logger;
99  bool LoadCppAddressSpace = true;
101  void CheckStarted() const;
102 
103  Common::AddonsManager::SharedPtr Addons;
104  Server::ServicesRegistry::SharedPtr Registry;
105  Server::SubscriptionService::SharedPtr SubscriptionService;
106 };
107 
108 }
OpcUa::MessageSecurityMode SecurityMode
Definition: server.h:100
void SetEndpoint(const std::string &endpoint)
set endpoint uri on wich server will listen. opc.tcp://localhost:4841/opcua/server opc...
Definition: server.cpp:56
Node GetRootNode() const
helper methods for node you will probably want to access
Definition: server.cpp:179
Common::AddonsManager::SharedPtr Addons
Definition: server.h:103
std::string Name
Definition: server.h:97
Server::ServicesRegistry::SharedPtr Registry
Definition: server.h:104
void SetServerURI(const std::string &uri)
Definition: server.cpp:66
void EnableEventNotification()
Enable event notification on Server node this is necessary if you want to be able to send custom even...
Definition: server.cpp:194
Server::SubscriptionService::SharedPtr SubscriptionService
Definition: server.h:105
Node GetNodeFromPath(const std::vector< QualifiedName > &path) const
Get a node using its browsepath.
Definition: server.cpp:162
Node GetServerNode() const
Definition: server.cpp:189
name
Definition: setup.py:38
Node GetNode(const NodeId &nodeid) const
Get a specific node by nodeid.
Definition: server.cpp:156
uint32_t RegisterNamespace(std::string uri)
Register your application namespace.
Definition: server.cpp:89
void Start()
Start and Stop server.
Definition: server.cpp:118
void TriggerEvent(Event event)
Trigger and event.
Definition: server.cpp:220
std::string ServerUri
Definition: server.h:95
MessageSecurityMode
Definition: enums.h:68
void SetProductURI(const std::string &uri)
setup server description
Definition: server.cpp:61
UaServer()
create high level server
Definition: server.cpp:30
OPC UA Address space part. GNU LGPL.
std::string Endpoint
Definition: server.h:94
string uri
Definition: client.py:31
std::string ProductUri
Definition: server.h:96
ServerOperations CreateServerOperations()
Create a server operations object.
Definition: server.cpp:215
A Node object represent an OPC-UA node. It is high level object intended for developper who want to e...
Definition: node.h:42
Node GetObjectsNode() const
Definition: server.cpp:184
Common::Logger::SharedPtr Logger
Definition: server.h:98
uint32_t GetNamespaceIndex(std::string uri)
Definition: server.cpp:100
bool LoadCppAddressSpace
Definition: server.h:99
std::vector< std::string > XmlAddressSpaces
Definition: server.h:92
void AddAddressSpace(const std::string &path)
load xml addressspace. This is not implemented yet!!!
Definition: server.cpp:76
void SetServerName(const std::string &name)
Definition: server.cpp:71
void CheckStarted() const
Definition: server.cpp:81
Subscription::SharedPtr CreateSubscription(unsigned int period, SubscriptionHandler &callback)
Create a subscription objects.
Definition: server.cpp:207


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:07