blob: 1266a6f876ccf985b1b7b95f6e0b1e39b6c426a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
/* Copyright (C) 2014 BMW Group
* Author: Manfred Bathelt (manfred.bathelt@bmw.de)
* Author: Juergen Gehring (juergen.gehring@bmw.de)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef WIN32
#include <unistd.h>
#endif
#include <iostream>
#include <CommonAPI/CommonAPI.hpp>
#include <v1/commonapi/examples/E05ManagerProxy.hpp>
using namespace v1_0::commonapi::examples;
void newDeviceAvailable(const std::string address, const CommonAPI::AvailabilityStatus status) {
if (status == CommonAPI::AvailabilityStatus::AVAILABLE) {
std::cout << "New device available: " << address << std::endl;
}
if (status == CommonAPI::AvailabilityStatus::NOT_AVAILABLE) {
std::cout << "Device removed: " << address << std::endl;
}
}
int main() {
CommonAPI::Runtime::setProperty("LogContext", "E05C");
CommonAPI::Runtime::setProperty("LibraryBase", "E05Manager");
std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::get();
const std::string &domain = "local";
const std::string &instance = "commonapi.examples.Manager";
const std::string connectionIdClient = "client-sample";
std::shared_ptr<E05ManagerProxy<>> myProxy = runtime->buildProxy<E05ManagerProxy>(domain, instance, connectionIdClient);
while (!myProxy->isAvailable()) {
usleep(10);
}
std::cout << "Proxy available." << std::endl;
CommonAPI::ProxyManager::InstanceAvailabilityStatusChangedEvent& deviceEvent =
myProxy->getProxyManagerE05Device().getInstanceAvailabilityStatusChangedEvent();
CommonAPI::ProxyManager::InstanceAvailabilityStatusChangedEvent& specialDeviceEvent =
myProxy->getProxyManagerE05SpecialDevice().getInstanceAvailabilityStatusChangedEvent();
std::function<void(const std::string, const CommonAPI::AvailabilityStatus)> newDeviceAvailableFunc = newDeviceAvailable;
deviceEvent.subscribe(newDeviceAvailableFunc);
specialDeviceEvent.subscribe(newDeviceAvailableFunc);
while (true) {
std::this_thread::sleep_for(std::chrono::seconds(5));
}
return 0;
}
|