00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 #include <opc/ua/protocol/binary/common.h> 00012 #include <opc/ua/protocol/binary/stream.h> 00013 #include <opc/ua/services/services.h> 00014 00015 #include <boost/thread/shared_mutex.hpp> 00016 #include <chrono> 00017 #include <list> 00018 #include <mutex> 00019 #include <queue> 00020 00021 namespace OpcUa 00022 { 00023 namespace Server 00024 { 00025 00026 class OpcTcpMessages 00027 { 00028 public: 00029 OpcTcpMessages(std::shared_ptr<OpcUa::Services> computer, OpcUa::OutputChannel& outputChannel, bool debug); 00030 ~OpcTcpMessages(); 00031 00032 bool ProcessMessage(Binary::MessageType msgType, Binary::IStreamBinary& iStream); 00033 00034 private: 00035 void HelloClient(Binary::IStreamBinary& istream, Binary::OStreamBinary& ostream); 00036 void OpenChannel(Binary::IStreamBinary& istream, Binary::OStreamBinary& ostream); 00037 void CloseChannel(Binary::IStreamBinary& istream); 00038 void ProcessRequest(Binary::IStreamBinary& istream, Binary::OStreamBinary& ostream); 00039 void FillResponseHeader(const RequestHeader& requestHeader, ResponseHeader& responseHeader); 00040 void DeleteSubscriptions(const std::vector<uint32_t>& ids); 00041 void DeleteAllSubscriptions(); 00042 void ForwardPublishResponse(const PublishResult response); 00043 00044 private: 00045 boost::shared_mutex ProcessMutex; 00046 std::shared_ptr<OpcUa::Services> Server; 00047 OpcUa::Binary::OStreamBinary OutputStream; 00048 bool Debug; 00049 uint32_t ChannelId; 00050 uint32_t TokenId; 00051 ExpandedNodeId SessionId; 00052 //ExpandedNodeId AuthenticationToken; 00053 uint32_t SequenceNb; 00054 00055 struct PublishRequestElement 00056 { 00057 Binary::SequenceHeader sequence; 00058 RequestHeader requestHeader; 00059 Binary::SymmetricAlgorithmHeader algorithmHeader; 00060 }; 00061 00062 std::list<uint32_t> Subscriptions; //Keep a list of subscriptions to query internal server at correct rate 00063 std::mutex PublishRequestQueueMutex; 00064 std::queue<PublishRequestElement> PublishRequestQueue; //Keep track of request data to answer them when we have data and 00065 }; 00066 00067 00068 } // namespace UaServer 00069 } // namespace OpcUa