WSF
WsfXIO_Request.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFXIO_REQUEST_HPP
13#define WSFXIO_REQUEST_HPP
14
15#include "wsf_export.h"
16
17#include <map>
18
19#include "UtCallbackHolder.hpp"
22class WsfXIO_Request;
28
31{
32public:
34 virtual ~WsfXIO_RequestManager();
35
38 void AddRequest(WsfXIO_Request* aRequestPtr);
39
42 void RemoveRequest(WsfXIO_Request* aRequestPtr);
43
46 bool RemoveRequest(int aRequestId);
47
48 WsfXIO_Request* FindRequest(int aRequestId);
49
50 void AddSession(WsfXIO_ServiceSession* aSessionPtr);
51
52 void RemoveSession(WsfXIO_ServiceSession* aSessionPtr);
53
54 using RequestMap = std::map<int, WsfXIO_Request*>;
55 using SessionMap = std::map<WsfXIO_SubscriptionId, WsfXIO_ServiceSession*>;
56
57 const SessionMap& GetSessions() const { return mSessions; }
58 const RequestMap& GetRequests() const { return mRequests; }
59
60protected:
61 virtual void RequestCancelled(WsfXIO_Request* aRequestPtr);
62
63 void HandleRequestResponse(WsfXIO_ResponsePkt& aPkt);
64
65 void HandleCancel(WsfXIO_SubscriptionCancelPkt& aPkt);
66
67 void HandleDisconnect(WsfXIO_Connection* aConnectionPtr);
68
69 UtCallbackHolder mCallbacks;
71
72private:
73 SessionMap mSessions;
74 RequestMap mRequests;
75 static unsigned int mNextRequestId;
76};
77
81{
82public:
84
85 WsfXIO_Request(WsfXIO_Connection* aConnectionPtr, bool aIsReliable = true);
86
87 virtual void HandleResponse(WsfXIO_ResponsePkt& aPkt) {}
88
89 void SendRequest(WsfXIO_RequestDataPkt& aPkt);
90
92 WsfXIO_Connection* GetConnection() const { return mConnectionPtr; }
93
95 bool IsReliable() const { return mIsReliable; }
96
98 int GetRequestId() const { return mRequestId; }
99
101 void SetRequestManager(WsfXIO_RequestManager* aRequestManagerPtr) { mRequestManagerPtr = aRequestManagerPtr; }
102
103 void SendResponse(WsfXIO_ResponsePkt& aPkt);
104
105protected:
106 // Destructor should only be called by WsfXIO_RequestManager
107 virtual ~WsfXIO_Request();
108
111 virtual void Initialized() = 0;
112
113 void SetRequestId(unsigned int aRequestId) { mRequestId = aRequestId; }
114
115 void SetRemotelyDestroyed() { mRemotelyDestroyed = true; }
116
117 bool IsRemotelyDestroyed() const { return mRemotelyDestroyed; }
118
119 void SetIsReliable(bool aIsReliable) { mIsReliable = aIsReliable; }
120
121private:
122 WsfXIO_RequestManager* mRequestManagerPtr;
123 WsfXIO_Connection* mConnectionPtr;
124 bool mIsReliable;
125 bool mRemotelyDestroyed;
126 unsigned int mRequestId;
127};
128
129#endif
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
Definition WsfXIO_Connection.hpp:37
Definition WsfXIO_Interface.hpp:54
Basic information required for subscription requests.
Definition WsfXIO_PacketRegistry.hpp:137
Maintains a group of WsfXIO_Requests.
Definition WsfXIO_Request.hpp:31
WsfXIO_RequestManager(WsfXIO_Interface *aInterfacePtr)
Definition WsfXIO_Request.cpp:23
std::map< int, WsfXIO_Request * > RequestMap
Definition WsfXIO_Request.hpp:54
void AddRequest(WsfXIO_Request *aRequestPtr)
Definition WsfXIO_Request.cpp:62
WsfXIO_Interface * mInterfacePtr
Definition WsfXIO_Request.hpp:70
void RemoveSession(WsfXIO_ServiceSession *aSessionPtr)
Removes the session from the request manager.
Definition WsfXIO_Request.cpp:94
void AddSession(WsfXIO_ServiceSession *aSessionPtr)
Adds a session to the request manager for the primary goal of routing WsfXIO_ResponsePkt to the sessi...
Definition WsfXIO_Request.cpp:88
const SessionMap & GetSessions() const
Definition WsfXIO_Request.hpp:57
UtCallbackHolder mCallbacks
Definition WsfXIO_Request.hpp:69
std::map< WsfXIO_SubscriptionId, WsfXIO_ServiceSession * > SessionMap
Definition WsfXIO_Request.hpp:55
const RequestMap & GetRequests() const
Definition WsfXIO_Request.hpp:58
WsfXIO_Request * FindRequest(int aRequestId)
Returns the request with the given request ID if it exists.
Definition WsfXIO_Request.cpp:135
void RemoveRequest(WsfXIO_Request *aRequestPtr)
Definition WsfXIO_Request.cpp:70
Definition WsfXIO_Request.hpp:81
virtual void HandleResponse(WsfXIO_ResponsePkt &aPkt)
Definition WsfXIO_Request.hpp:87
int GetRequestId() const
Returns the request's locally unique ID.
Definition WsfXIO_Request.hpp:98
bool IsReliable() const
Returns 'true' if data for this request is to be sent reliably.
Definition WsfXIO_Request.hpp:95
virtual void Initialized()=0
friend class WsfXIO_RequestManager
Definition WsfXIO_Request.hpp:83
void SetRequestId(unsigned int aRequestId)
Definition WsfXIO_Request.hpp:113
WsfXIO_Connection * GetConnection() const
Returns the connection to the application from which data is requested.
Definition WsfXIO_Request.hpp:92
void SetIsReliable(bool aIsReliable)
Definition WsfXIO_Request.hpp:119
void SetRequestManager(WsfXIO_RequestManager *aRequestManagerPtr)
Sets the owner of this request.
Definition WsfXIO_Request.hpp:101
bool IsRemotelyDestroyed() const
Definition WsfXIO_Request.hpp:117
WsfXIO_Request(WsfXIO_Connection *aConnectionPtr, bool aIsReliable=true)
Definition WsfXIO_Request.cpp:160
void SetRemotelyDestroyed()
Definition WsfXIO_Request.hpp:115
Definition WsfXIO_PacketRegistry.hpp:171
Definition WsfXIO_Service.hpp:133
Definition WsfXIO_PacketRegistry.hpp:128
Copyrights Multiple, All Rights Reserved