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_NUGGET_CLIENT_H 18 #define NOS_NUGGET_CLIENT_H 19 20 #include <cstdint> 21 #include <string> 22 #include <vector> 23 24 #include <nos/device.h> 25 #include <nos/NuggetClientInterface.h> 26 27 namespace nos { 28 29 /** 30 * Client to communicate with a Nugget device via the transport API. 31 */ 32 class NuggetClient : public NuggetClientInterface { 33 public: 34 /** 35 * Create a client for the default Nugget device. 36 */ 37 NuggetClient(); 38 39 /** 40 * Create a client for the named Nugget device. 41 * 42 * Passing an empty device name causes the default device to be selected. 43 */ 44 NuggetClient(const std::string& device_name); 45 46 ~NuggetClient() override; 47 48 /** 49 * Opens a connection to the default Nugget device. 50 * 51 * If this fails, isOpen() will return false. 52 */ 53 void Open() override; 54 55 /** 56 * Closes the connection to Nugget. 57 */ 58 void Close() override; 59 60 /** 61 * Checked whether a connection is open to Nugget. 62 */ 63 bool IsOpen() const override; 64 65 /** 66 * Call into and app running on Nugget. 67 * 68 * @param app_id The ID of the app to call. 69 * @param arg Argument to pass to the app. 70 * @param request Data to send to the app. 71 * @param response Buffer to receive data from the app. 72 * @return Status code from the app. 73 */ 74 uint32_t CallApp(uint32_t appId, uint16_t arg, 75 const std::vector<uint8_t>& request, 76 std::vector<uint8_t>* response) override; 77 78 /** 79 * Access the underlying device. 80 * 81 * NULL is returned if the connection to the device is not open. 82 * 83 * This can be used by subclasses or to use to use the C API directly. 84 */ 85 nos_device* Device(); 86 const nos_device* Device() const; 87 88 /** 89 * Access the name of the device this is a client for. 90 */ 91 const std::string& DeviceName() const; 92 93 private: 94 std::string device_name_; 95 nos_device device_; 96 bool open_; 97 }; 98 99 } // namespace nos 100 101 #endif // NOS_NUGGET_CLIENT_H 102