Log error and return if no devices

This commit is contained in:
John Zhao
2018-05-15 22:01:15 +08:00
parent 276406dd1e
commit de0f0d0639
26 changed files with 92 additions and 4 deletions

View File

@@ -41,17 +41,24 @@ std::shared_ptr<API> API::Create() {
}
std::shared_ptr<API> API::Create(std::shared_ptr<Device> device) {
if (!device)
return nullptr;
return std::make_shared<API>(device);
}
std::shared_ptr<API> API::Create(int argc, char *argv[]) {
static glog_init _(argc, argv);
return std::make_shared<API>(device::select());
auto &&device = device::select();
if (!device)
return nullptr;
return std::make_shared<API>(device);
}
std::shared_ptr<API> API::Create(
int argc, char *argv[], std::shared_ptr<Device> device) {
static glog_init _(argc, argv);
if (!device)
return nullptr;
return std::make_shared<API>(device);
}

View File

@@ -51,9 +51,35 @@ class MYNTEYE_API API {
explicit API(std::shared_ptr<Device> device);
/*virtual*/ ~API();
/**
* Create the API instance.
* @return the API instance.
* @note This will call device::select() to select a device.
*/
static std::shared_ptr<API> Create();
/**
* Create the API instance.
* @param device the selected device.
* @return the API instance.
*/
static std::shared_ptr<API> Create(std::shared_ptr<Device> device);
/**
* Create the API instance.
* @param argc the arg count.
* @param argv the arg values.
* @return the API instance.
* @note This will init glog with args and call device::select() to select a
* device.
*/
static std::shared_ptr<API> Create(int argc, char *argv[]);
/**
* Create the API instance.
* @param argc the arg count.
* @param argv the arg values.
* @param device the selected device.
* @return the API instance.
* @note This will init glog with args.
*/
static std::shared_ptr<API> Create(
int argc, char *argv[], std::shared_ptr<Device> device);

View File

@@ -28,7 +28,10 @@ std::shared_ptr<Device> select() {
auto &&devices = context.devices();
size_t n = devices.size();
LOG_IF(FATAL, n <= 0) << "No MYNT EYE devices :(";
if (n <= 0) {
LOG(ERROR) << "No MYNT EYE devices :(";
return nullptr;
}
LOG(INFO) << "MYNT EYE devices:";
for (size_t i = 0; i < n; i++) {