Andrew Scull | 599e791 | 2017-09-14 14:00:36 +0100 | [diff] [blame] | 1 | /* |
| 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 Scull | 96517d8 | 2017-10-09 12:53:19 +0100 | [diff] [blame] | 23 | #include <nos/NuggetClientInterface.h> |
Andrew Scull | 599e791 | 2017-09-14 14:00:36 +0100 | [diff] [blame] | 24 | |
| 25 | namespace nos { |
| 26 | |
| 27 | /** |
| 28 | * Client to communicate with an app running on Nugget. |
| 29 | */ |
| 30 | class AppClient { |
| 31 | public: |
| 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 Scull | 96517d8 | 2017-10-09 12:53:19 +0100 | [diff] [blame] | 39 | AppClient(NuggetClientInterface& client, uint32_t appId) |
Allen Webb | c8802fb | 2017-09-18 15:49:02 -0700 | [diff] [blame] | 40 | : _client(client), _appId(appId) {} |
Andrew Scull | 599e791 | 2017-09-14 14:00:36 +0100 | [diff] [blame] | 41 | |
| 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 Scull | 58eaf39 | 2017-09-29 13:45:58 +0100 | [diff] [blame] | 49 | 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 Scull | 599e791 | 2017-09-14 14:00:36 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | |
| 55 | private: |
Andrew Scull | 96517d8 | 2017-10-09 12:53:19 +0100 | [diff] [blame] | 56 | NuggetClientInterface& _client; |
Andrew Scull | 599e791 | 2017-09-14 14:00:36 +0100 | [diff] [blame] | 57 | uint32_t _appId; |
| 58 | }; |
| 59 | |
| 60 | } // namespace nos |
| 61 | |
| 62 | #endif // NOS_APP_CLIENT_H |