diff options
author | Bill Richardson <wfrichar@google.com> | 2021-02-09 19:35:27 -0600 |
---|---|---|
committer | Bill Richardson <wfrichar@google.com> | 2021-02-19 02:22:40 +0000 |
commit | 3b471109f617e01bcfb8c58db8df6cfd5c609575 (patch) | |
tree | 3badf8ce83652dfdd0168f33558aa3fce2f7c3dc | |
parent | d46aa03337996b6bb838e1e51157ed0bf566bf77 (diff) | |
download | generic-3b471109f617e01bcfb8c58db8df6cfd5c609575.tar.gz |
Refactor NuggetClient a bit
The NuggetClientInterface class should provide all we need for
both Android and Linux desktop tools. Instead it's sort of an
idealized view with ugly details left to two separate child
classes to figure out.
This cleans things up (some) to make building tests for both
enviroments a little simpler.
Bug: None
Test: build everything, test everything
Change-Id: I38d5af2de47625d1e8d3d2b929f9157b12bbd09d
Signed-off-by: Bill Richardson <wfrichar@google.com>
Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/40224
Reviewed-by: Randall Spangler <rspangler@google.com>
Presubmit-Verified: TreeHugger Robot
-rw-r--r-- | libnos/NuggetClient.cpp | 20 | ||||
-rw-r--r-- | libnos/NuggetClientDebuggable.cpp | 15 | ||||
-rw-r--r-- | libnos/include/nos/NuggetClient.h | 19 | ||||
-rw-r--r-- | libnos/include/nos/NuggetClientDebuggable.h | 5 | ||||
-rw-r--r-- | libnos/include/nos/NuggetClientInterface.h | 4 | ||||
-rw-r--r-- | libnos_datagram/include/nos/device.h | 13 |
6 files changed, 34 insertions, 42 deletions
diff --git a/libnos/NuggetClient.cpp b/libnos/NuggetClient.cpp index 72a9e9f..c361463 100644 --- a/libnos/NuggetClient.cpp +++ b/libnos/NuggetClient.cpp @@ -21,17 +21,15 @@ namespace nos { -NuggetClient::NuggetClient() - : NuggetClient("") { +NuggetClient::NuggetClient(const std::string& name) + : device_name_(name), open_(false) { } -NuggetClient::NuggetClient(const std::string& device_name) - : device_name_(device_name), open_(false) { +NuggetClient::NuggetClient(const char* name, uint32_t config) + : device_name_(name ? name : ""), open_(false) { + device_ = { .config = config }; } -NuggetClient::NuggetClient(const char* device_name) - : device_name_(device_name ? device_name : ""), open_(false) {} - NuggetClient::~NuggetClient() { Close(); } @@ -86,6 +84,14 @@ uint32_t NuggetClient::CallApp(uint32_t appId, uint16_t arg, return status_code; } +uint32_t NuggetClient::Reset() const { + + if (!open_) + return APP_ERROR_NOT_READY; + + return device_.ops.reset(device_.ctx); +} + nos_device* NuggetClient::Device() { return open_ ? &device_ : nullptr; } diff --git a/libnos/NuggetClientDebuggable.cpp b/libnos/NuggetClientDebuggable.cpp index 5ee86e9..e4a087d 100644 --- a/libnos/NuggetClientDebuggable.cpp +++ b/libnos/NuggetClientDebuggable.cpp @@ -21,16 +21,11 @@ namespace nos { -NuggetClientDebuggable::NuggetClientDebuggable(request_cb_t req_fn, response_cb_t resp_fn) - : request_cb_(req_fn), response_cb_(resp_fn) {} - -NuggetClientDebuggable::NuggetClientDebuggable(const std::string& device_name, - request_cb_t req_fn, response_cb_t resp_fn) - : NuggetClient(device_name), request_cb_(req_fn), response_cb_(resp_fn) {} - -NuggetClientDebuggable::NuggetClientDebuggable(const char* device_name, - request_cb_t req_fn, response_cb_t resp_fn) - : NuggetClient(device_name), request_cb_(req_fn), response_cb_(resp_fn) {} +NuggetClientDebuggable::NuggetClientDebuggable( + const char* name, uint32_t config, + request_cb_t req_fn, response_cb_t resp_fn) + : NuggetClient(name, config), + request_cb_(req_fn), response_cb_(resp_fn) {} uint32_t NuggetClientDebuggable::CallApp(uint32_t appId, uint16_t arg, const std::vector<uint8_t>& request, diff --git a/libnos/include/nos/NuggetClient.h b/libnos/include/nos/NuggetClient.h index 563f532..9484bd8 100644 --- a/libnos/include/nos/NuggetClient.h +++ b/libnos/include/nos/NuggetClient.h @@ -32,17 +32,13 @@ namespace nos { class NuggetClient : public NuggetClientInterface { public: /** - * Create a client for the default Nugget device. - */ - NuggetClient(); - - /** - * Create a client for the named Nugget device. + * Create a client for the named Nugget device * - * Passing an empty device name causes the default device to be selected. + * An empty device name causes the default device to be selected. + * An empty config uses default configurations. */ - NuggetClient(const std::string& device_name); - NuggetClient(const char* device_name); + NuggetClient(const std::string& name); + NuggetClient(const char* name = 0, uint32_t config = 0); ~NuggetClient() override; @@ -77,6 +73,11 @@ public: std::vector<uint8_t>* response) override; /** + * Reset the device. Use with caution; context may be lost. + */ + uint32_t Reset() const override; + + /** * Access the underlying device. * * NULL is returned if the connection to the device is not open. diff --git a/libnos/include/nos/NuggetClientDebuggable.h b/libnos/include/nos/NuggetClientDebuggable.h index 507eb15..ff1f080 100644 --- a/libnos/include/nos/NuggetClientDebuggable.h +++ b/libnos/include/nos/NuggetClientDebuggable.h @@ -36,10 +36,7 @@ public: using response_cb_t = std::function<void(uint32_t, const std::vector<uint8_t>&)>; /* Need to pass the base constructor params up */ - NuggetClientDebuggable(request_cb_t req_cb_ = 0, response_cb_t resp_cb_ = 0); - NuggetClientDebuggable(const std::string& device_name, - request_cb_t req_cb_ = 0, response_cb_t resp_cb_ = 0); - NuggetClientDebuggable(const char* device_name, + NuggetClientDebuggable(const char* name = 0, uint32_t config = 0, request_cb_t req_cb_ = 0, response_cb_t resp_cb_ = 0); /* We'll override this */ diff --git a/libnos/include/nos/NuggetClientInterface.h b/libnos/include/nos/NuggetClientInterface.h index da47e50..8d78185 100644 --- a/libnos/include/nos/NuggetClientInterface.h +++ b/libnos/include/nos/NuggetClientInterface.h @@ -58,6 +58,10 @@ public: virtual uint32_t CallApp(uint32_t appId, uint16_t arg, const std::vector<uint8_t>& request, std::vector<uint8_t>* response) = 0; + /** + * Reset the device. Use with caution; context may be lost. + */ + virtual uint32_t Reset() const = 0; }; } // namespace nos diff --git a/libnos_datagram/include/nos/device.h b/libnos_datagram/include/nos/device.h index 5472156..2ba57e0 100644 --- a/libnos_datagram/include/nos/device.h +++ b/libnos_datagram/include/nos/device.h @@ -69,23 +69,12 @@ struct nos_device_ops { * The device must not be used after closing. */ void (*close)(void *ctx); - -#ifndef ANDROID - /** - * Get or Set a configuration value. These are opaque, implementation-specific - * values useful only for bringup and development. The defaults should be - * optimal for production use. - * - * Return 0 on success and a negative value on failure. - */ - int (*get_config)(void *ctx, uint32_t config_id, void *value); - int (*set_config)(void *ctx, uint32_t config_id, void *value); -#endif }; struct nos_device { void *ctx; struct nos_device_ops ops; + uint32_t config; }; /* |