| 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 |  | 
|  | 33 | using base::unique_fd; | 
|  | 34 |  | 
|  | 35 | RpcServer::RpcServer() {} | 
|  | 36 | RpcServer::~RpcServer() {} | 
|  | 37 |  | 
|  | 38 | sp<RpcServer> RpcServer::make() { | 
| Steven Moreland | 1a3a8ef | 2021-04-02 02:52:46 +0000 | [diff] [blame] | 39 | return sp<RpcServer>::make(); | 
| Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 40 | } | 
|  | 41 |  | 
|  | 42 | void RpcServer::iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction() { | 
|  | 43 | mAgreedExperimental = true; | 
|  | 44 | } | 
|  | 45 |  | 
|  | 46 | sp<RpcConnection> RpcServer::addClientConnection() { | 
|  | 47 | LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!"); | 
|  | 48 |  | 
|  | 49 | auto connection = RpcConnection::make(); | 
| Steven Moreland | 1a3a8ef | 2021-04-02 02:52:46 +0000 | [diff] [blame] | 50 | connection->setForServer(sp<RpcServer>::fromExisting(this)); | 
| Steven Moreland | ebafe33 | 2021-04-24 00:24:35 +0000 | [diff] [blame] | 51 | { | 
|  | 52 | std::lock_guard<std::mutex> _l(mLock); | 
|  | 53 | mConnections.push_back(connection); | 
|  | 54 | } | 
| Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 55 | return connection; | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | void RpcServer::setRootObject(const sp<IBinder>& binder) { | 
| Steven Moreland | ebafe33 | 2021-04-24 00:24:35 +0000 | [diff] [blame] | 59 | std::lock_guard<std::mutex> _l(mLock); | 
| Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 60 | mRootObject = binder; | 
|  | 61 | } | 
|  | 62 |  | 
|  | 63 | sp<IBinder> RpcServer::getRootObject() { | 
| Steven Moreland | ebafe33 | 2021-04-24 00:24:35 +0000 | [diff] [blame] | 64 | std::lock_guard<std::mutex> _l(mLock); | 
| Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 65 | return mRootObject; | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | } // namespace android |