Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 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 | |
| 17 | #define LOG_TAG "RpcServer" |
| 18 | |
| 19 | #include <sys/socket.h> |
| 20 | #include <sys/un.h> |
| 21 | |
| 22 | #include <vector> |
| 23 | |
| 24 | #include <binder/Parcel.h> |
| 25 | #include <binder/RpcServer.h> |
| 26 | #include <log/log.h> |
| 27 | #include "RpcState.h" |
| 28 | |
| 29 | #include "RpcWireFormat.h" |
| 30 | |
| 31 | namespace android { |
| 32 | |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 33 | RpcServer::RpcServer() {} |
| 34 | RpcServer::~RpcServer() {} |
| 35 | |
| 36 | sp<RpcServer> RpcServer::make() { |
Steven Moreland | 1a3a8ef | 2021-04-02 02:52:46 +0000 | [diff] [blame] | 37 | return sp<RpcServer>::make(); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void RpcServer::iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction() { |
| 41 | mAgreedExperimental = true; |
| 42 | } |
| 43 | |
| 44 | sp<RpcConnection> RpcServer::addClientConnection() { |
| 45 | LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!"); |
| 46 | |
| 47 | auto connection = RpcConnection::make(); |
Steven Moreland | 1a3a8ef | 2021-04-02 02:52:46 +0000 | [diff] [blame] | 48 | connection->setForServer(sp<RpcServer>::fromExisting(this)); |
Steven Moreland | ebafe33 | 2021-04-24 00:24:35 +0000 | [diff] [blame] | 49 | { |
| 50 | std::lock_guard<std::mutex> _l(mLock); |
| 51 | mConnections.push_back(connection); |
| 52 | } |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 53 | return connection; |
| 54 | } |
| 55 | |
| 56 | void RpcServer::setRootObject(const sp<IBinder>& binder) { |
Steven Moreland | ebafe33 | 2021-04-24 00:24:35 +0000 | [diff] [blame] | 57 | std::lock_guard<std::mutex> _l(mLock); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 58 | mRootObject = binder; |
| 59 | } |
| 60 | |
| 61 | sp<IBinder> RpcServer::getRootObject() { |
Steven Moreland | ebafe33 | 2021-04-24 00:24:35 +0000 | [diff] [blame] | 62 | std::lock_guard<std::mutex> _l(mLock); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 63 | return mRootObject; |
| 64 | } |
| 65 | |
| 66 | } // namespace android |