blob: 1fea479cddbccefd796b111a42bbb997d86e9058 [file] [log] [blame]
Ronghua Wu231c3d12015-03-11 15:10:32 -07001/*
2**
3** Copyright 2015, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include <utils/RefBase.h>
19#include <binder/IInterface.h>
20#include <binder/Parcel.h>
21
22#include <media/IResourceManagerClient.h>
23
24namespace android {
25
26enum {
27 RECLAIM_RESOURCE = IBinder::FIRST_CALL_TRANSACTION,
Ronghua Wu8f9dd872015-04-23 15:24:25 -070028 GET_NAME,
Ronghua Wu231c3d12015-03-11 15:10:32 -070029};
30
31class BpResourceManagerClient: public BpInterface<IResourceManagerClient>
32{
33public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070034 explicit BpResourceManagerClient(const sp<IBinder> &impl)
Ronghua Wu231c3d12015-03-11 15:10:32 -070035 : BpInterface<IResourceManagerClient>(impl)
36 {
37 }
38
39 virtual bool reclaimResource() {
40 Parcel data, reply;
41 data.writeInterfaceToken(IResourceManagerClient::getInterfaceDescriptor());
42
43 bool ret = false;
44 status_t status = remote()->transact(RECLAIM_RESOURCE, data, &reply);
45 if (status == NO_ERROR) {
46 ret = (bool)reply.readInt32();
47 }
48 return ret;
49 }
Ronghua Wu8f9dd872015-04-23 15:24:25 -070050
51 virtual String8 getName() {
52 Parcel data, reply;
53 data.writeInterfaceToken(IResourceManagerClient::getInterfaceDescriptor());
54
55 String8 ret;
56 status_t status = remote()->transact(GET_NAME, data, &reply);
57 if (status == NO_ERROR) {
58 ret = reply.readString8();
59 }
60 return ret;
61 }
62
Ronghua Wu231c3d12015-03-11 15:10:32 -070063};
64
65IMPLEMENT_META_INTERFACE(ResourceManagerClient, "android.media.IResourceManagerClient");
66
67// ----------------------------------------------------------------------
68
69status_t BnResourceManagerClient::onTransact(
70 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags)
71{
72 switch (code) {
73 case RECLAIM_RESOURCE: {
74 CHECK_INTERFACE(IResourceManagerClient, data, reply);
75 bool ret = reclaimResource();
76 reply->writeInt32(ret);
77 return NO_ERROR;
78 } break;
Ronghua Wu8f9dd872015-04-23 15:24:25 -070079 case GET_NAME: {
80 CHECK_INTERFACE(IResourceManagerClient, data, reply);
81 String8 ret = getName();
82 reply->writeString8(ret);
83 return NO_ERROR;
84 } break;
Ronghua Wu231c3d12015-03-11 15:10:32 -070085 default:
86 return BBinder::onTransact(code, data, reply, flags);
87 }
88}
89
90}; // namespace android