Added message callback functionality in c and canceled error downgrading on user callbacks in communication as well
parent
5a98bac8a6
commit
c10224002a
|
|
@ -10,6 +10,7 @@
|
|||
#include "icsneo/api/eventmanager.h"
|
||||
#include "icsneo/device/devicefinder.h"
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
|
|
@ -242,14 +243,23 @@ bool icsneo_setPollingMessageLimit(const neodevice_t* device, size_t newLimit) {
|
|||
return true;
|
||||
}
|
||||
|
||||
int icsneo_addMessageCallback(const neodevice_t* device, void (*callback) (neomessage_t*)) {
|
||||
int icsneo_addMessageCallback(const neodevice_t* device, void (*callback)(neomessage_t)) {
|
||||
if(!icsneo_isValidNeoDevice(device))
|
||||
return -1;
|
||||
|
||||
return device->device->addMessageCallback(
|
||||
MessageCallback(
|
||||
[=](std::shared_ptr<icsneo::Message> msg) {
|
||||
return callback(CreateNeoMessage(msg));
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
bool icsneo_removeMessageCallback(const neodevice_t* device, int id) {
|
||||
if(!icsneo_isValidNeoDevice(device))
|
||||
return false;
|
||||
return device->device->removeMessageCallback(id);
|
||||
}
|
||||
|
||||
bool icsneo_getProductName(const neodevice_t* device, char* str, size_t* maxLength) {
|
||||
|
|
@ -451,7 +461,7 @@ void icsneo_setWriteBlocks(const neodevice_t* device, bool blocks) {
|
|||
if(!icsneo_isValidNeoDevice(device))
|
||||
return;
|
||||
|
||||
device->device->com->setWriteBlocks(blocks);
|
||||
device->device->setWriteBlocks(blocks);
|
||||
}
|
||||
|
||||
bool icsneo_describeDevice(const neodevice_t* device, char* str, size_t* maxLength) {
|
||||
|
|
|
|||
|
|
@ -156,11 +156,14 @@ void Communication::readTask() {
|
|||
|
||||
std::lock_guard<std::mutex> lk(messageCallbacksLock);
|
||||
|
||||
// We want callbacks to be able to access errors
|
||||
EventManager::GetInstance().cancelErrorDowngradingOnCurrentThread();
|
||||
for(auto& cb : messageCallbacks) {
|
||||
if(!closing) { // We might have closed while reading or processing
|
||||
cb.second.callIfMatch(msg);
|
||||
}
|
||||
}
|
||||
EventManager::GetInstance().downgradeErrorsOnCurrentThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -284,7 +284,7 @@ extern size_t DLLExport icsneo_getPollingMessageLimit(const neodevice_t* device)
|
|||
*/
|
||||
extern bool DLLExport icsneo_setPollingMessageLimit(const neodevice_t* device, size_t newLimit);
|
||||
|
||||
extern int DLLExport icsneo_addMessageCallback(const neodevice_t* device, void (*callback) (neomessage_t*));
|
||||
extern int DLLExport icsneo_addMessageCallback(const neodevice_t* device, void (*callback)(neomessage_t));
|
||||
|
||||
extern bool DLLExport icsneo_removeMessageCallback(const neodevice_t* device, int id);
|
||||
|
||||
|
|
@ -743,7 +743,7 @@ fn_icsneo_getPollingMessageLimit icsneo_getPollingMessageLimit;
|
|||
typedef bool(*fn_icsneo_setPollingMessageLimit)(const neodevice_t* device, size_t newLimit);
|
||||
fn_icsneo_setPollingMessageLimit icsneo_setPollingMessageLimit;
|
||||
|
||||
typedef int(*fn_icsneo_addMessageCallback)(const neodevice_t* device, void (*callback) (neomessage_t*);
|
||||
typedef int(*fn_icsneo_addMessageCallback)(const neodevice_t* device, void (*callback)(neomessage_t));
|
||||
fn_icsneo_addMessageCallback icsneo_addMessageCallback;
|
||||
|
||||
typedef bool(*fn_icsneo_removeMessageCallback)(const neodevice_t* device, int id);
|
||||
|
|
|
|||
Loading…
Reference in New Issue