00001 00002 #pragma once 00003 00004 #include <opc/ua/node.h> 00005 #include <opc/ua/protocol/nodeid.h> 00006 #include <opc/ua/protocol/types.h> 00007 #include <opc/ua/protocol/variant.h> 00008 #include <opc/ua/protocol/protocol.h> 00009 00010 #include <map> 00011 00012 00013 00014 namespace OpcUa 00015 { 00016 typedef std::map<std::vector<QualifiedName>, Variant> PathMap; 00017 typedef std::map<AttributeId, Variant> AttributeMap; 00018 00019 class Event 00020 { 00021 00022 public: 00023 //Instanciate a new event object 00024 //The optional argument is the type of the event 00025 //If not set BaseEventType is used 00026 //If you want to send custom data, you need custom event type on server 00027 //The attributes of BaseEventType are accesible as class member, 00028 //Other attributes must be set using SetValue and accessed using GetValue 00029 // This API is a draft, it WILL change 00030 Event(const Node& type); 00031 Event(const NodeId& type); 00032 Event(); 00033 00034 //Attributes of an BaseEventType 00035 ByteString EventId; //unique id 00036 NodeId EventType; //The type of event, defines attribues, connections, ... 00037 DateTime LocalTime; //Time zone information 00038 DateTime ReceiveTime; //Time at which the server received the event 00039 DateTime Time; //Time at which the event occured, should come from underlying system 00040 LocalizedText Message; //human readable event description 00041 uint16_t Severity = 1; //Priority, from 1 to 1000. 1 is lowest priority 00042 NodeId SourceNode; //The node that has generated the event 00043 std::string SourceName; //Description of the source 00044 00045 00046 //Set value of a variable(or object) 00047 //This value will be used when the event is fired 00048 //You can set arbitrary data, but clients will not be able to discover them thus subscribe to them 00049 void SetValue(const std::vector<QualifiedName>& path, Variant value); 00050 void SetValue(AttributeId attribute, Variant value); 00051 void SetValue(const QualifiedName& path, Variant value); 00052 void SetValue(const std::string& qualifiedname, Variant value); //helper method for the most common case 00053 00054 //Return value og variable identified by its relative path 00055 //or value of attribute identified by its Id 00056 //returns null variant if no match 00057 Variant GetValue(const std::vector<QualifiedName>& path) const; 00058 Variant GetValue(AttributeId attribute) const; 00059 Variant GetValue(const QualifiedName& path) const; 00060 Variant GetValue(const std::string& qualifiedname) const; //helper method for the most common case 00061 00062 //Get the list of available values in this event 00063 std::vector<std::vector<QualifiedName>> GetValueKeys(); 00064 00065 protected: 00066 PathMap PathValues; 00067 AttributeMap AttributeValues; 00068 }; 00069 00070 std::string ToString(const Event& event); 00071 00072 inline std::ostream& operator<<(std::ostream& os, const Event& event) 00073 { 00074 os << "{" << ToString(event) << "}"; 00075 return os; 00076 } 00077 00078 }