binary_session.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #include "binary_serialization.h"
00012 
00013 #include <opc/ua/protocol/binary/stream.h>
00014 #include <opc/ua/protocol/session.h>
00015 #include <opc/ua/protocol/types.h>
00016 #include <opc/ua/protocol/extension_identifiers.h>
00017 
00018 #include <algorithm>
00019 #include <memory>
00020 #include <string>
00021 
00022 namespace OpcUa
00023 {
00024   CloseSessionResponse::CloseSessionResponse()
00025     : TypeId(CLOSE_SESSION_RESPONSE)
00026   {
00027   }
00028 
00029   UserIdentifyToken::UserIdentifyToken()
00030     : Header(USER_IdENTIFY_TOKEN_ANONYMOUS, HAS_BINARY_BODY)
00031   {
00032   }
00033 
00034   UserTokenType UserIdentifyToken::type() const
00035   {
00036     UserTokenType type = UserTokenType::Anonymous;
00037     if(Header.TypeId.FourByteData.Identifier == USER_IdENTIFY_TOKEN_USERNAME)
00038       type = UserTokenType::UserName;
00039     return type;
00040   }
00041 
00042   void UserIdentifyToken::setUser(const std::string &user, const std::string &password)
00043   {
00044     Header.TypeId.FourByteData.Identifier = USER_IdENTIFY_TOKEN_USERNAME;
00045     UserName.UserName = user;
00046     UserName.Password = password;
00047     //UserName.EncryptionAlgorithm = "http://www.w3.org/2001/04/xmlenc#rsa-oaep";
00048   }
00049 
00050   void UserIdentifyToken::setPolicyId(const std::string &id)
00051   {
00052     int sz = id.length();
00053     PolicyId.resize(sz);
00054     for(int i=0; i<sz; i++) {
00055       PolicyId[i] = id[i];
00056     }
00057   }
00058 
00059   CloseSessionRequest::CloseSessionRequest()
00060     : TypeId(CLOSE_SESSION_REQUEST)
00061     , DeleteSubscriptions(true)
00062   {
00063   }
00064 
00065   ServiceFaultResponse::ServiceFaultResponse()
00066     : TypeId(SERVICE_FAULT)
00067   {
00068   }
00069 
00070   namespace Binary
00071   {
00072     //---------------------------------------------------
00073     // UserIdentifyToken
00074     //---------------------------------------------------
00075 
00076     template<>
00077     std::size_t RawSize<UserIdentifyToken::UserNameStruct>(const UserIdentifyToken::UserNameStruct& uname)
00078     {
00079       return RawSize(uname.UserName) + RawSize(uname.Password) + RawSize(uname.EncryptionAlgorithm);
00080     }
00081 
00082     template<>
00083     void DataSerializer::Serialize<UserIdentifyToken::UserNameStruct>(const UserIdentifyToken::UserNameStruct& uname)
00084     {
00085       *this << uname.UserName;
00086       *this << uname.Password;
00087       *this << uname.EncryptionAlgorithm;
00088     }
00089 
00090     template<>
00091     void DataDeserializer::Deserialize<UserIdentifyToken::UserNameStruct>(UserIdentifyToken::UserNameStruct& uname)
00092     {
00093       *this >> uname.UserName;
00094       *this >> uname.Password;
00095       *this >> uname.EncryptionAlgorithm;
00096     }
00097 
00098     template<>
00099     std::size_t RawSize<UserIdentifyToken>(const UserIdentifyToken& token)
00100     {
00101       std::size_t ret = RawSize(token.Header) + RawSize(token.PolicyId) + RawSize(( uint32_t)0);
00102       if(token.type() == UserTokenType::UserName)
00103         ret += RawSize(token.UserName);
00104       return ret;
00105     }
00106 
00107     template<>
00108     void DataSerializer::Serialize<UserIdentifyToken>(const UserIdentifyToken& token)
00109     {
00110       *this << token.Header;
00111       *this << int32_t(RawSize(token)-RawSize(token.Header)-RawSize(( uint32_t)0));
00112       *this << token.PolicyId;
00113       if(token.type() == UserTokenType::UserName)
00114         *this << token.UserName;
00115     }
00116 
00117     template<>
00118     void DataDeserializer::Deserialize<UserIdentifyToken>(UserIdentifyToken& token)
00119     {
00120       *this >> token.Header;
00121       int32_t tmp;
00122       *this >> tmp;
00123       *this >> token.PolicyId;
00124       if(token.type() == UserTokenType::UserName)
00125         *this >> token.UserName;
00126     }
00127 
00128     //---------------------------------------------------
00129     // CloseSessionRequest
00130     //---------------------------------------------------
00131 
00132     template<>
00133     std::size_t RawSize<CloseSessionRequest>(const CloseSessionRequest& request)
00134     {
00135       return RawSize(request.TypeId) + RawSize(request.Header) +
00136         RawSize(request.DeleteSubscriptions);
00137     }
00138 
00139     template<>
00140     void DataSerializer::Serialize<CloseSessionRequest>(const CloseSessionRequest& request)
00141     {
00142       *this << request.TypeId;
00143       *this << request.Header;
00144 
00145       *this << request.DeleteSubscriptions;
00146     }
00147 
00148     template<>
00149     void DataDeserializer::Deserialize<CloseSessionRequest>(CloseSessionRequest& request)
00150     {
00151       *this >> request.TypeId;
00152       *this >> request.Header;
00153 
00154       *this >> request.DeleteSubscriptions;
00155     }
00156 
00157     //---------------------------------------------------
00158     // CloseSessionResponse
00159     //---------------------------------------------------
00160 
00161     template<>
00162     std::size_t RawSize<CloseSessionResponse>(const CloseSessionResponse& response)
00163     {
00164       return RawSize(response.TypeId) + RawSize(response.Header);
00165     }
00166 
00167     template<>
00168     void DataSerializer::Serialize<CloseSessionResponse>(const CloseSessionResponse& response)
00169     {
00170       *this << response.TypeId;
00171       *this << response.Header;
00172     }
00173 
00174     template<>
00175     void DataDeserializer::Deserialize<CloseSessionResponse>(CloseSessionResponse& response)
00176     {
00177       *this >> response.TypeId;
00178       *this >> response.Header;
00179     }
00180 
00181     //---------------------------------------------------
00182     // ServiceFaultResponse
00183     //---------------------------------------------------
00184 
00185     template<>
00186     std::size_t RawSize<ServiceFaultResponse>(const ServiceFaultResponse& request)
00187     {
00188       return RawSize(request.TypeId) + RawSize(request.Header);
00189     }
00190 
00191     template<>
00192     void DataSerializer::Serialize<ServiceFaultResponse>(const ServiceFaultResponse& request)
00193     {
00194       *this << request.TypeId;
00195       *this << request.Header;
00196     }
00197 
00198     template<>
00199     void DataDeserializer::Deserialize<ServiceFaultResponse>(ServiceFaultResponse& request)
00200     {
00201       *this >> request.TypeId;
00202       *this >> request.Header;
00203     }
00204 
00205 
00206   } // namespace Binary
00207 } // namespace OpcUa
00208 


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