• 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_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 named Nugget device
36      *
37      * An empty device name causes the default device to be selected.
38      * An empty config uses default configurations.
39      */
40     NuggetClient(const std::string& name);
41     NuggetClient(const char* name = 0, uint32_t config = 0);
42 
43     ~NuggetClient() override;
44 
45     /**
46      * Opens a connection to the default Nugget device.
47      *
48      * If this fails, isOpen() will return false.
49      */
50     void Open() override;
51 
52     /**
53      * Closes the connection to Nugget.
54      */
55     void Close() override;
56 
57     /**
58      * Checked whether a connection is open to Nugget.
59      */
60     bool IsOpen() const override;
61 
62     /**
63      * Call into and app running on Nugget.
64      *
65      * @param app_id   The ID of the app to call.
66      * @param arg      Argument to pass to the app.
67      * @param request  Data to send to the app.
68      * @param response Buffer to receive data from the app.
69      * @return         Status code from the app.
70      */
71     uint32_t CallApp(uint32_t appId, uint16_t arg,
72                      const std::vector<uint8_t>& request,
73                      std::vector<uint8_t>* response) override;
74 
75     /**
76      * Reset the device. Use with caution; context may be lost.
77      */
78     uint32_t Reset() const override;
79 
80     /**
81      * Access the underlying device.
82      *
83      * NULL is returned if the connection to the device is not open.
84      *
85      * This can be used by subclasses or to use to use the C API directly.
86      */
87     nos_device* Device();
88     const nos_device* Device() const;
89 
90     /**
91      * Access the name of the device this is a client for.
92      */
93     const std::string& DeviceName() const;
94 
95 protected:
96     std::string device_name_;
97     nos_device device_;
98     bool open_;
99 };
100 
101 } // namespace nos
102 
103 #endif // NOS_NUGGET_CLIENT_H
104