AGHAF  4.5.1
Annecy electronique Generic Hardware Access Framework
DeviceManagement/main.cpp
#include <vector>
#include <unordered_map>
#include <iostream>
#include <string>
#include <algorithm>
#include <array>
#define AGHAF_DYNAMIC_LIBRARY_INIT
#include <aghaf.h>
struct pair_hash
{
template <class T1, class T2>
std::size_t operator() (const std::pair<T1, T2> &pair) const
{
return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
}
};
std::unordered_map<std::pair<std::string, std::string>, AGHAF_Device, pair_hash> devices; // key: productNumber, serialNumber
void deviceEvent_callback(void * event, void *userContext)
{
(void) userContext;
AGHAF_Event_getInfo(event, &info);
switch (info.type) {
break;
std::string productName(AGHAF_DeviceEvent_getProductName(event));
std::string productNumber(AGHAF_DeviceEvent_getProductNumber(event));
std::string serialNumber(AGHAF_DeviceEvent_getSerialNumber(event));
std::pair<std::string, std::string> key(productNumber, serialNumber);
switch (static_cast<AGHAF_DeviceEvent>(info.event)) {
break;
AGHAF_Device device = AGHAF_getDeviceBySN(productNumber.c_str(),
serialNumber.c_str());
devices.insert(std::pair<std::pair<std::string, std::string>, AGHAF_Device>(key, device));
}
break;
auto it = devices.find(key);
if (it != devices.end()) {
devices.erase(it);
}
}
break;
break;
}
}
break;
}
}
int main()
{
#ifdef _WIN32
AGHAF_loadLibrary(AGHAF_DEFAULT_FILENAME);
#endif
AGHAF_registerCallback(&deviceEvent_callback, nullptr);
std::string input;
while (input != "exit") {
std::cin >> input;
}
AGHAF_deregisterCallback(&deviceEvent_callback);
#ifdef _WIN32
AGHAF_unloadLibrary();
#endif
return 0;
}
@ AGHAF_TypeCanEvent
Event from CAN.
Definition: aghaf_global.h:174
@ AGHAF_TypeEthernetEvent
Event from Ethernet.
Definition: aghaf_global.h:173
@ AGHAF_TypeDoCanEvent
Event from DOCAN.
Definition: aghaf_global.h:175
@ AGHAF_TypeNoEvent
No event. Event is invalid.
Definition: aghaf_global.h:171
@ AGHAF_TypeDeviceEvent
Event from Device.
Definition: aghaf_global.h:172
@ AGHAF_Device_Present
A device was present.
Definition: aghaf_global.h:165
@ AGHAF_Device_Leave
A device was disconnected from this PC.
Definition: aghaf_global.h:164
@ AGHAF_Device_Arrival
A device was connected to this PC.
Definition: aghaf_global.h:163
@ AGHAF_Device_noEvent
No event. Event is invalid.
Definition: aghaf_global.h:162
char const * AGHAF_DeviceEvent_getProductName(AGHAF_Event event)
return the product name from the device which emitted the device event
Definition: aghaf_global.cpp:68
void AGHAF_deregisterCallback(AGHAF_Callback callback)
Deregister a callback.
Definition: aghaf_global.cpp:311
AGHAF_Device AGHAF_getDeviceBySN(const char *productNumber, const char *serialNumber)
Return the handle on the specified device.
Definition: aghaf_global.cpp:156
AGHAF_DeviceEvent
device event fot hotplug management
Definition: aghaf_global.h:161
void * AGHAF_Device
handle on an exxotest device
Definition: aghaf_global.h:145
void AGHAF_registerCallback(AGHAF_Callback callback, void *userContext)
Register a callback for the device event.
Definition: aghaf_global.cpp:302
char const * AGHAF_DeviceEvent_getSerialNumber(AGHAF_Event event)
return the serial number from the device which emitted the device event
Definition: aghaf_global.cpp:90
AGHAF_Status AGHAF_Event_getInfo(AGHAF_Event event, AGHAF_EventInfo *info)
AGHAF_Event_getInfo.
Definition: aghaf_global.cpp:290
char const * AGHAF_DeviceEvent_getProductNumber(AGHAF_Event event)
return the product number from the device which emitted the device event
Definition: aghaf_global.cpp:79
generic stucture to read an event in a callback
Definition: aghaf_global.h:201
AGHAF_TypeEvent type
Type information. Provide information about origin (device, can, ethernet...).
Definition: aghaf_global.h:202
uint32_t event
Event information. Provide information about event type ( event tx, event rx, device connected....
Definition: aghaf_global.h:203