iceoryx_posh  2.0.2
base_server.hpp
1 // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
2 // Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 // SPDX-License-Identifier: Apache-2.0
17 
18 #ifndef IOX_POSH_POPO_BASE_SERVER_HPP
19 #define IOX_POSH_POPO_BASE_SERVER_HPP
20 
21 #include "iceoryx_hoofs/cxx/expected.hpp"
22 #include "iceoryx_posh/capro/service_description.hpp"
23 #include "iceoryx_posh/internal/popo/ports/server_port_user.hpp"
24 #include "iceoryx_posh/popo/server_options.hpp"
25 #include "iceoryx_posh/popo/trigger_handle.hpp"
26 #include "iceoryx_posh/runtime/posh_runtime.hpp"
27 
28 namespace iox
29 {
30 namespace popo
31 {
32 using uid_t = UniquePortId;
33 
38 template <typename PortT = ServerPortUser, typename TriggerHandleT = TriggerHandle>
40 {
41  public:
42  virtual ~BaseServer() noexcept;
43 
44  BaseServer(const BaseServer& other) = delete;
45  BaseServer& operator=(const BaseServer&) = delete;
46  BaseServer(BaseServer&& rhs) = delete;
47  BaseServer& operator=(BaseServer&& rhs) = delete;
48 
53  uid_t getUid() const noexcept;
54 
59  const capro::ServiceDescription& getServiceDescription() const noexcept;
60 
64  void offer() noexcept;
65 
69  void stopOffer() noexcept;
70 
75  bool isOffered() const noexcept;
76 
81  bool hasClients() const noexcept;
82 
87  bool hasRequests() const noexcept;
88 
94  bool hasMissedRequests() noexcept;
95 
97  void releaseQueuedRequests() noexcept;
98 
99  friend class NotificationAttorney;
100 
101  protected:
102  using SelfType = BaseServer<PortT, TriggerHandleT>;
103  using PortType = PortT;
104 
105  BaseServer(const capro::ServiceDescription& service, const ServerOptions& serverOptions) noexcept;
106 
109  void invalidateTrigger(const uint64_t uniqueTriggerId) noexcept;
110 
115  void enableState(TriggerHandleT&& triggerHandle, const ServerState serverState) noexcept;
116 
120  WaitSetIsConditionSatisfiedCallback
121  getCallbackForIsStateConditionSatisfied(const ServerState serverState) const noexcept;
122 
125  void disableState(const ServerState serverState) noexcept;
126 
131  void enableEvent(TriggerHandleT&& triggerHandle, const ServerEvent serverEvent) noexcept;
132 
135  void disableEvent(const ServerEvent serverEvent) noexcept;
136 
141  const PortT& port() const noexcept;
142 
147  PortT& port() noexcept;
148 
149  PortT m_port; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes)
150  TriggerHandleT m_trigger; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes)
151 };
152 
153 } // namespace popo
154 } // namespace iox
155 
156 #include "iceoryx_posh/internal/popo/base_server.inl"
157 
158 #endif // IOX_POSH_POPO_BASE_SERVER_HPP
The BaseServer class contains the common implementation for the different server.
Definition: base_server.hpp:40
bool hasClients() const noexcept
Check if the server has clients.
WaitSetIsConditionSatisfiedCallback getCallbackForIsStateConditionSatisfied(const ServerState serverState) const noexcept
Only usable by the WaitSet/Listener, not for public use. Returns method pointer to the event correspo...
bool hasRequests() const noexcept
Check if requests are available.
void releaseQueuedRequests() noexcept
Releases any unread queued requests.
void stopOffer() noexcept
Stop offering the service when already offering, otherwise nothing.
void disableState(const ServerState serverState) noexcept
Only usable by the WaitSet/Listener, not for public use. Resets the internal triggerHandle.
void disableEvent(const ServerEvent serverEvent) noexcept
Only usable by the WaitSet/Listener, not for public use. Resets the internal triggerHandle.
bool hasMissedRequests() noexcept
Check if requests has been missed since the last call of this method.
bool isOffered() const noexcept
Check if the server is offering.
void enableEvent(TriggerHandleT &&triggerHandle, const ServerEvent serverEvent) noexcept
Only usable by the WaitSet/Listener, not for public use. Attaches the triggerHandle to the internal t...
void enableState(TriggerHandleT &&triggerHandle, const ServerState serverState) noexcept
Only usable by the WaitSet/Listener, not for public use. Attaches the triggerHandle to the internal t...
const PortT & port() const noexcept
port
void invalidateTrigger(const uint64_t uniqueTriggerId) noexcept
Only usable by the WaitSet/Listener, not for public use. Invalidates the internal triggerHandle.
void offer() noexcept
Offer the service to be connected to when not already offering, otherwise nothing.
const capro::ServiceDescription & getServiceDescription() const noexcept
Get the service description of the server.
uid_t getUid() const noexcept
Get the UID of the server.
Class which allows accessing private methods to friends of NotificationAttorney. Used for example by ...
Definition: notification_attorney.hpp:33
This struct is used to configure the server.
Definition: server_options.hpp:33