00001 #pragma once 00002 00003 00004 #include <opc/common/addons_core/addon_manager.h> 00005 #include <opc/ua/event.h> 00006 #include <opc/ua/node.h> 00007 #include <opc/ua/server/services_registry.h> 00008 #include <opc/ua/server/subscription_service.h> 00009 #include <opc/ua/services/services.h> 00010 #include <opc/ua/subscription.h> 00011 #include <opc/ua/server_operations.h> 00012 00013 namespace OpcUa 00014 { 00015 class UaServer 00016 { 00017 public: 00019 // this class is meant to be used to quickly/easily add OPCUA interface to an application 00020 // it may not offer absolutely all features available in protocol 00021 // you may want to look at code and implement your own server if you need 00022 // debug argument will make freeopcua write A LOT to stdout 00023 UaServer(); 00024 explicit UaServer(bool debug); 00025 00030 void SetEndpoint(const std::string& endpoint); 00031 00033 void SetProductURI(const std::string& uri); 00034 void SetServerURI(const std::string& uri); 00035 void SetServerName(const std::string& name); 00036 00038 void AddAddressSpace(const std::string& path); 00039 00042 // (Not for datachange events!) 00043 void EnableEventNotification(); 00044 00046 // Every application will probably have its own namespace 00047 // example: urn:mydomain:myfancyapplication 00048 // the returned index will then be used 00049 uint32_t RegisterNamespace(std::string uri); 00050 uint32_t GetNamespaceIndex(std::string uri); 00051 00053 // if you do not stop server you may get into trouble! 00054 // we have several threads running 00055 void Start(); 00056 void Stop(); 00057 00059 // you can also access a standard node from addressspace using 00060 // ObjectId, for example: 00061 // Node mynode = GetNode(ObjectId::Server); 00062 // using a string is also possible: 00063 // Node mynode = GetNode("ns=3;i=55"); 00064 Node GetNode(const NodeId& nodeid) const; 00065 Node GetNode(const std::string& nodeid) const; 00066 00068 Node GetRootNode() const; 00069 Node GetObjectsNode() const; 00070 Node GetServerNode() const; 00071 00073 Node GetNodeFromPath(const std::vector<QualifiedName>& path) const; 00074 Node GetNodeFromPath(const std::vector<std::string>& path) const; 00075 00077 // Event will be send from Server node. 00078 // It is possible to send events from arbitrarily nodes but it looks like 00079 // most servers only send events from Server node 00080 void TriggerEvent(Event event); 00081 00083 // returned object can then be used to subscribe to 00084 // datachange or custom events on server side 00085 std::unique_ptr<Subscription> CreateSubscription(unsigned int period, SubscriptionHandler& callback); 00086 00088 ServerOperations CreateServerOperations(); 00089 00090 protected: 00091 std::vector<std::string> XmlAddressSpaces; 00092 // defined some sensible defaults that should let most clients connects 00093 std::string Endpoint; 00094 std::string ServerUri = "urn:freeopcua:server"; 00095 std::string ProductUri = "urn:freeopcua.github.no:server"; 00096 std::string Name = "FreeOpcUa Server"; 00097 bool Debug = false; 00098 bool LoadCppAddressSpace = true; 00099 OpcUa::MessageSecurityMode SecurityMode = OpcUa::MessageSecurityMode::None; 00100 void CheckStarted() const; 00101 00102 Common::AddonsManager::SharedPtr Addons; 00103 Server::ServicesRegistry::SharedPtr Registry; 00104 Server::SubscriptionService::SharedPtr SubscriptionService; 00105 }; 00106 00107 }