• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 #include <nos/NuggetClientInterface.h>
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      */
AppClient(NuggetClientInterface & client,uint32_t appId)39     AppClient(NuggetClientInterface& client, uint32_t appId)
40             : _client(client), _appId(appId) {}
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      */
Call(uint16_t arg,const std::vector<uint8_t> & request,std::vector<uint8_t> * response)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);
52     }
53 
54 
55 private:
56     NuggetClientInterface& _client;
57     uint32_t _appId;
58 };
59 
60 } // namespace nos
61 
62 #endif // NOS_APP_CLIENT_H
63