PLCnext API Documentation 23.0.2.9
RscClient.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Rsc/Services/Rsc.h"
9#include "Arp/System/Security/SecurityToken.hpp"
10
11// forwards
12namespace CommonRemoting
13{
14class RemotingClient;
15class RemotingSession;
16}
17
18// forwards
19namespace Arp { namespace System { namespace Rsc { namespace Client
20{
21class RemoteServiceManager;
22}}}}
23
24namespace Arp { namespace System { namespace Rsc { namespace Services
25{
26
27// forwards
28class IRscServiceProxy;
29
31class RscClient
32{
33public: // forwards/friends
34 class ITransaction;
35
36private: // forwards/friends
37 class IpcTransaction;
38 friend class IpcTransaction;
39 friend class Arp::System::Rsc::Client::RemoteServiceManager;
40
41public: // usings
42 using Ptr = std::shared_ptr<RscClient>;
43 using RemotingClient = CommonRemoting::RemotingClient;
44 using RemotingSession = CommonRemoting::RemotingSession;
45 using RemotingClientPtr = std::shared_ptr<RemotingClient>;
46 using ITransactionPtr = std::shared_ptr<ITransaction>;
47 using SecurityToken = Arp::System::Security::SecurityToken;
48
49public: // nested class TransactionGuard
51 {
52 public:
53 TransactionGuard(RscClient& client, IRscServiceProxy& proxy);
54 TransactionGuard(const TransactionGuard&) = delete;
56 TransactionGuard& operator=(const TransactionGuard&) = delete;
57 TransactionGuard& operator=(TransactionGuard&&) = delete;
59
60 private:
61 RscClient& client;
62 IRscServiceProxy& proxy;
63 };
64
65public: // nested interface ITransaction
67 {
68 public:
69 virtual ~ITransaction(void) = default;
70 virtual void Begin(IRscServiceProxy& proxy) = 0;
71 virtual void End(IRscServiceProxy& proxy) = 0;
72 };
73
74public: // construction/destruction
76 RscClient(const String& appName, RemotingClientPtr remotingClientPtr);
78 RscClient(const String& url, RemotingClientPtr remotingClientPtr, ITransactionPtr transactionPtr);
80 RscClient(const RscClient& arg) = delete;
82 RscClient(RscClient&& arg)noexcept = default;
84 RscClient& operator=(const RscClient& arg) = delete;
86 RscClient& operator=(RscClient&& arg)noexcept = default;
88 ~RscClient(void);
89
90public: // setter/getter operations
91 bool IsConnected(void)const;
92 RemotingSession& GetSession(void) const;
93
94public: // operations
95 void Authenticate(SecurityToken securityToken);
96 RscHandle GetServiceProviderHandle(const char* serviceProviderName);
97 RscHandle GetServiceHandle(RscHandle serviceProviderHandle, const char* serviceName);
98 RscHandle GetServiceHandle(const char* serviceProviderName, const char* serviceName);
99 void GetServiceHandles(const char* serviceProviderName, const char* serviceName, RscHandle& serviceProviderHandle, RscHandle& serviceHandle);
100 void Close(bool disconnectRemoting = true); // same as Disconnect
101
102private: // methods
103 void BeginTransaction(IRscServiceProxy& proxy);
104 void EndTransaction(IRscServiceProxy& proxy);
105 void BeginRemotingTransaction(void);
106 void EndRemotingTransaction(void);
107
108private: // fields
109 String url;
110 RemotingClientPtr remotingClientPtr;
111 ITransactionPtr transactionPtr;
112};
113
115// inline methods of class RemotingClient::TransactionGuard
116inline RscClient::TransactionGuard::TransactionGuard(RscClient& client, IRscServiceProxy& proxy)
117 : client(client)
118 , proxy(proxy)
119{
120 this->client.BeginTransaction(this->proxy);
121}
122
123inline RscClient::TransactionGuard::~TransactionGuard()
124{
125 this->client.EndTransaction(this->proxy);
126}
127
128}}}} // end of namespace Arp::System::Rsc::Services
Definition: SecurityToken.hpp:12
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API