event.cpp
Go to the documentation of this file.
00001 
00002 #include <iostream> //Debug
00003 
00004 #include <opc/ua/event.h>
00005 #include <opc/ua/protocol/string_utils.h>
00006 
00007 namespace OpcUa
00008 {
00009 
00010   Event::Event() : EventType(ObjectId::BaseEventType) 
00011   {
00012   }
00013 
00014   Event::Event(const NodeId& type) : EventType(type) {}
00015 
00016   Event::Event(const Node& type) : EventType(type.GetId()) {}
00017 
00018   std::vector<std::vector<QualifiedName>> Event::GetValueKeys()
00019   {
00020     std::vector<std::vector<QualifiedName>> qns;
00021     for (auto qn : PathValues)
00022     {
00023       qns.push_back(qn.first);
00024     }
00025     return qns;
00026   }
00027 
00028   void Event::SetValue(const QualifiedName& path, Variant value)
00029   {
00030     SetValue(std::vector<QualifiedName>({path}), value);
00031   }
00032 
00033   void Event::SetValue(const std::vector<QualifiedName>& path, Variant value)
00034   {
00035     PathValues[path] = value;
00036   }
00037 
00038   void Event::SetValue(AttributeId attribute, Variant value)
00039   {
00040     AttributeValues[attribute] = value;
00041   }
00042 
00043   void Event::SetValue(const std::string& name, Variant value)
00044   {
00045     std::vector<QualifiedName> path;
00046     path.push_back(ToQualifiedName(name));
00047     return SetValue(path, value);
00048   }
00049 
00050   Variant Event::GetValue(const QualifiedName& path) const
00051   {
00052     return GetValue(std::vector<QualifiedName>({path}));
00053   }
00054 
00055   Variant Event::GetValue(const std::vector<QualifiedName>& path) const
00056   {
00057     PathMap::const_iterator it = PathValues.find(path);
00058       std::cout << "Looking for Event value: ";
00059       for ( auto qn : path ){
00060         std::cout << qn ;
00061       }
00062       std::cout << std::endl;
00063     if ( it == PathValues.end() )
00064     {
00065       std::cout << "Bad Not found " << std::endl;
00066       return Variant();
00067     }
00068     else
00069     {
00070       std::cout << "ok" << std::endl;
00071       return it->second;
00072     }
00073   }
00074 
00075   Variant Event::GetValue(const std::string& qualifiedname) const
00076   {
00077     std::vector<QualifiedName> path;
00078     path.push_back(ToQualifiedName(qualifiedname));
00079     return GetValue(path);
00080   }
00081 
00082   Variant Event::GetValue(AttributeId attribute) const
00083   {
00084     AttributeMap::const_iterator it = AttributeValues.find(attribute);
00085     if ( it == AttributeValues.end() )
00086     {
00087       return Variant();
00088     }
00089     else
00090     {
00091       return it->second;
00092     }
00093   }
00094 
00095   std::string ToString(const Event& event)
00096   {
00097     std::stringstream stream;
00098     stream << "Event(type:" << event.EventType << ", time:" << event.Time << ", source:" << event.SourceNode << ", severity:" << event.Severity << ", message:" << event.Message << ")" ;
00099     return stream.str();
00100   }
00101 }


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:40