Skip to content

Commit 2a4aef1

Browse files
committed
WebViewer: add single-device connect overload and out-of-band USB metadata for Android
1 parent 31181d9 commit 2a4aef1

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

Source/Application/WebViewer.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,47 @@ void WebViewer::connect(const std::vector<std::unique_ptr<Receiver>> &receivers)
900900
raw_counter.setFilter(filter);
901901
}
902902

903+
void WebViewer::setDeviceDescription(const std::string &product, const std::string &vendor, const std::string &serial)
904+
{
905+
pending_product = product;
906+
pending_vendor = vendor;
907+
pending_serial = serial;
908+
909+
if (!states.empty())
910+
{
911+
if (!product.empty())
912+
states[0]->product = product;
913+
if (!vendor.empty())
914+
states[0]->vendor = vendor;
915+
if (!serial.empty())
916+
states[0]->serial = serial;
917+
}
918+
}
919+
920+
void WebViewer::connect(AIS::Model &model, Connection<JSON::JSON> &json, Device::Device &device)
921+
{
922+
if (states.empty())
923+
states.push_back(std::unique_ptr<ReceiverTracker>(new ReceiverTracker()));
924+
925+
states[0]->label = "All";
926+
states[0]->appendDevice(&device, "<br>");
927+
states[0]->model_name += model.getName() + "<br>";
928+
929+
// Android supplies USB product/vendor/serial out-of-band via setDeviceDescription().
930+
if (!pending_product.empty())
931+
states[0]->product = pending_product;
932+
if (!pending_vendor.empty())
933+
states[0]->vendor = pending_vendor;
934+
if (!pending_serial.empty())
935+
states[0]->serial = pending_serial;
936+
937+
states[0]->connectJSON(json);
938+
device >> raw_counter;
939+
940+
states[0]->applyConfig(tracking, filter);
941+
raw_counter.setFilter(filter);
942+
}
943+
903944
void WebViewer::Reset()
904945
{
905946
for (auto &s : states)

Source/Application/WebViewer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ class WebViewer : public IO::HTTPServer, public Setting
311311

312312
AIS::Filter filter;
313313

314+
std::string pending_product, pending_vendor, pending_serial;
315+
314316
std::vector<std::string> parsePath(const std::string &url);
315317
bool parseMBTilesURL(const std::string &url, std::string &layerID, int &z, int &x, int &y);
316318
void addMBTilesSource(const std::string &filepath, bool overlay);
@@ -360,6 +362,8 @@ class WebViewer : public IO::HTTPServer, public Setting
360362

361363
bool &active() { return run; }
362364
void connect(const std::vector<std::unique_ptr<Receiver>> &receivers);
365+
void connect(AIS::Model &model, Connection<JSON::JSON> &json, Device::Device &device);
366+
void setDeviceDescription(const std::string &product, const std::string &vendor, const std::string &serial);
363367
void start();
364368
void close();
365369
void Reset();

0 commit comments

Comments
 (0)