blob: 9a0be921a7e63814f9ea9f102de38323bad66e1d [file] [log] [blame]
Steven Moreland5553ac42020-11-11 02:14:45 +00001/*
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
31namespace android {
32
Steven Moreland5553ac42020-11-11 02:14:45 +000033RpcServer::RpcServer() {}
34RpcServer::~RpcServer() {}
35
36sp<RpcServer> RpcServer::make() {
Steven Moreland1a3a8ef2021-04-02 02:52:46 +000037 return sp<RpcServer>::make();
Steven Moreland5553ac42020-11-11 02:14:45 +000038}
39
40void RpcServer::iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction() {
41 mAgreedExperimental = true;
42}
43
44sp<RpcConnection> RpcServer::addClientConnection() {
45 LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
46
47 auto connection = RpcConnection::make();
Steven Moreland1a3a8ef2021-04-02 02:52:46 +000048 connection->setForServer(sp<RpcServer>::fromExisting(this));
Steven Morelandebafe332021-04-24 00:24:35 +000049 {
50 std::lock_guard<std::mutex> _l(mLock);
51 mConnections.push_back(connection);
52 }
Steven Moreland5553ac42020-11-11 02:14:45 +000053 return connection;
54}
55
56void RpcServer::setRootObject(const sp<IBinder>& binder) {
Steven Morelandebafe332021-04-24 00:24:35 +000057 std::lock_guard<std::mutex> _l(mLock);
Steven Moreland5553ac42020-11-11 02:14:45 +000058 mRootObject = binder;
59}
60
61sp<IBinder> RpcServer::getRootObject() {
Steven Morelandebafe332021-04-24 00:24:35 +000062 std::lock_guard<std::mutex> _l(mLock);
Steven Moreland5553ac42020-11-11 02:14:45 +000063 return mRootObject;
64}
65
66} // namespace android