Line data Source code
1 : /*
2 : * If not stated otherwise in this file or this component's LICENSE file the
3 : * following copyright and licenses apply:
4 : *
5 : * Copyright 2022 Sky UK
6 : *
7 : * Licensed under the Apache License, Version 2.0 (the "License");
8 : * you may not use this file except in compliance with the License.
9 : * You may obtain a copy of the License at
10 : *
11 : * http://www.apache.org/licenses/LICENSE-2.0
12 : *
13 : * Unless required by applicable law or agreed to in writing, software
14 : * distributed under the License is distributed on an "AS IS" BASIS,
15 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 : * See the License for the specific language governing permissions and
17 : * limitations under the License.
18 : */
19 :
20 : #include "IpcClientImpl.h"
21 : #include "IpcServerImpl.h"
22 : #include <memory>
23 :
24 : namespace firebolt::rialto::ipc
25 : {
26 23 : ClientImpl::ClientImpl(const std::shared_ptr<ServerImpl> &server, uint64_t clientId, const struct ucred &creds)
27 23 : : m_kServer(server), m_kClientId(clientId), m_kCredentials(creds)
28 : {
29 : }
30 :
31 32 : pid_t ClientImpl::getClientPid() const
32 : {
33 32 : return m_kCredentials.pid;
34 : }
35 :
36 32 : uid_t ClientImpl::getClientUserId() const
37 : {
38 32 : return m_kCredentials.uid;
39 : }
40 :
41 32 : gid_t ClientImpl::getClientGroupId() const
42 : {
43 32 : return m_kCredentials.gid;
44 : }
45 :
46 1 : void ClientImpl::disconnect()
47 : {
48 1 : auto server = m_kServer.lock();
49 1 : if (server)
50 : {
51 1 : server->disconnectClient(m_kClientId);
52 : }
53 : }
54 :
55 23 : void ClientImpl::exportService(const std::shared_ptr<google::protobuf::Service> &service)
56 : {
57 23 : auto descriptor = service->GetDescriptor();
58 23 : m_services.emplace(descriptor->full_name(), service);
59 : }
60 :
61 4 : bool ClientImpl::sendEvent(const std::shared_ptr<google::protobuf::Message> &message)
62 : {
63 4 : auto server = m_kServer.lock();
64 4 : if (server)
65 4 : return server->sendEvent(m_kClientId, message);
66 : else
67 0 : return false;
68 4 : }
69 :
70 53 : bool ClientImpl::isConnected() const
71 : {
72 53 : auto server = m_kServer.lock();
73 53 : if (server)
74 53 : return server->isClientConnected(m_kClientId);
75 : else
76 0 : return false;
77 53 : }
78 :
79 : } // namespace firebolt::rialto::ipc
|