blob: 0a35d827f15d6a4f0013e5aea49ce874bff9c9b6 [file] [log] [blame]
Andrew Scull599e7912017-09-14 14:00:36 +01001/*
2 * Copyright (C) 2017 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#ifndef NOS_APP_CLIENT_H
18#define NOS_APP_CLIENT_H
19
20#include <cstdint>
21#include <vector>
22
Andrew Scull96517d82017-10-09 12:53:19 +010023#include <nos/NuggetClientInterface.h>
Andrew Scull599e7912017-09-14 14:00:36 +010024
25namespace nos {
26
27/**
28 * Client to communicate with an app running on Nugget.
29 */
30class AppClient {
31public:
32 /**
33 * Create a client for an app with the given ID that communicates with
34 * Nugget through the given NuggetClient.
35 *
36 * @param client Client for Nugget.
37 * @param appId ID of the target app.
38 */
Andrew Scull96517d82017-10-09 12:53:19 +010039 AppClient(NuggetClientInterface& client, uint32_t appId)
Allen Webbc8802fb2017-09-18 15:49:02 -070040 : _client(client), _appId(appId) {}
Andrew Scull599e7912017-09-14 14:00:36 +010041
42 /**
43 * Call the app.
44 *
45 * @param arg Argument to pass to the app.
46 * @param request Data to send to the app.
47 * @param response Buffer to receive data from the app.
48 */
Andrew Scull58eaf392017-09-29 13:45:58 +010049 uint32_t Call(uint16_t arg, const std::vector<uint8_t>& request,
50 std::vector<uint8_t>* response) {
51 return _client.CallApp(_appId, arg, request, response);
Andrew Scull599e7912017-09-14 14:00:36 +010052 }
53
54
55private:
Andrew Scull96517d82017-10-09 12:53:19 +010056 NuggetClientInterface& _client;
Andrew Scull599e7912017-09-14 14:00:36 +010057 uint32_t _appId;
58};
59
60} // namespace nos
61
62#endif // NOS_APP_CLIENT_H