2 * Copyright (c) 2017 - 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef PORT_INTERNAL_HH_
18 #define PORT_INTERNAL_HH_
35 class Port : public std::enable_shared_from_this<Port> {
37 Port(int fd, std::string id, std::string instance);
38 Port(int fd, std::string id);
42 int SetPrivateSharing(const char* paths[], unsigned int size);
43 int SetPrivateSharing(const char* path);
44 int UnsetPrivateSharing();
46 int Read(void* buf, unsigned int size);
47 int Write(const void* buf, unsigned int size);
48 int Write(const void* buf, unsigned int size, int* sent_bytes);
53 const std::string& GetId() const {
57 std::recursive_mutex& GetMutex() const {
61 const std::string& GetInstance() const {
71 int SetReceiveTimeout(int timeout);
78 DelayMessage(const char* msg, int start_index, int size);
79 ~DelayMessage() = default;
80 void SetIndex(int index);
82 int GetOriginalSize();
86 std::vector<unsigned char> message_;
92 PORT_STATUS_ERROR_NONE,
93 PORT_STATUS_ERROR_IO_ERROR,
94 PORT_STATUS_ERROR_RESOURCE_UNAVAILABLE
97 int PushDelayedMessage(std::shared_ptr<DelayMessage> dm);
98 int PopDelayedMessage();
99 static gboolean OnEventReceived(GIOChannel* io,
100 GIOCondition condition, gpointer data);
106 std::string instance_;
107 std::atomic<uint32_t> seq_;
108 mutable std::recursive_mutex mutex_;
109 mutable std::recursive_mutex rw_mutex_;
110 std::queue<std::shared_ptr<DelayMessage>> queue_;
111 int delayed_message_size_ = 0;
112 GIOChannel* channel_ = nullptr;
113 guint source_id_ = 0;
116 } // namespace internal
117 } // namespace rpc_port
119 #endif // PORT_INTERNAL_HH_