所有人
尝试为动态库编写第一个节点扩展("/usr/local/lib/libkdriveExpress.so")
这个扩展应该连接到设备并接收数据。对于接收到的数据,它应该从javascript调用back函数。我已经找到了如何存储持久函数,所以从cpp调用js函数不是问题。
在本例中,我只使用简单的c++函数来排除js的问题。
///
void test(const uint8_t *telegram, uint32_t telegram_len, void *user_data){
kdrive_logger_ex(KDRIVE_LOGGER_ERROR, "kdrive: event callback");
};
void ap_open_ip(const FunctionCallbackInfo <Value> &args) {
/// ...
/// now register
kdrive_ap_register_telegram_callback(ap, &test, NULL, &key);
/// ...
}当我从js调用它时,它工作得很好。
if (kdrive.ap_open_ip(ap, "192.168.3.201") == 0) {
console.log("great success", ap);
setTimeout(function () {
console.log(kdrive.whoami());
}, 2000)
}但是当我从扩展调用任何函数时,它都不能工作。在上面的代码中,我调用whoami函数,它不使用动态库,只返回字符串。
这是日志:
great success 1
11:42:45:518 [kdrive.express] kdrive: event callback
11:42:45:590 [kdrive.express] kdrive: event callback
11:42:45:692 [kdrive.express] kdrive: event callback
11:42:45:735 [kdrive.express] kdrive: event callback
11:42:45:831 [kdrive.express] kdrive: event callback
11:42:45:900 [kdrive.express] kdrive: event callback
11:42:46:167 [kdrive.express] kdrive: event callback
11:42:46:717 [kdrive.express] kdrive: event callback
>>> whoami call
11:42:47:525 [kdrive.connector.ConnectorNotificationHandler] onSignal: System exception: cannot lock mutex
11:42:48:067 [kdrive.connector.ConnectorNotificationHandler] onSignal: System exception: cannot lock mutex
11:42:48:420 [kdrive.connector.ConnectorNotificationHandler] onSignal: System exception: cannot lock mutex下面是对kdrive_ap_register_telegram_callback函数的描述:
注册回调函数。 当访问端口收到电报时,将调用此回调函数。通知线程在内部使用,因此此回调将位于通知线程的上下文中(而不是主线程)。也就是说,当从回调中发出呼叫时,应该小心。此函数生成一个唯一的键来表示回调。此键可用于在以后的状态下删除回调。
所以,我想问题在于线程。我是cpp扩展和cpp的新手,以前用js写的。因此,我想,我需要了解cpp中的线程是如何工作的,以及v8引擎如何处理它。
希望有任何建议和建议。
发布于 2017-06-09 13:00:51
这个问题与线程无关。这是因为js破坏了kdrive对象。
https://stackoverflow.com/questions/44453758
复制相似问题