的boost ::绑定的sigaction函数引用一个实例 [英] Boost::bind a sigaction function reference to a instance
问题描述
我想用Linux内核信号异步从模块进行通信的事件的发生,一个用户空间应用程序。在C I有这方面的工作以下列方式:
I would like to use a Linux kernel signal to asynchronously communicate the occurrence of an event from a module to a user-space application. I have this working in C in the following way:
void rcv_signal(int n, siginfo_t *info, void *unused)
{
// Do something interesting with the signal
}
// Register for updates from the kernel
int main(int argc, char *argv[])
{
struct sigaction sig;
sig.sa_sigaction = rcv_signal; // Function pointer
sig.sa_flags = SA_SIGINFO;
sigaction(SOME_CUSTOM_SIGNAL, &sig, NULL);
// Code to wait() then return
}
现在,我想移动到C ++实现。更具体地讲,我想使用boost ::功能/升压::绑定到sa_sigaction结合的方法 InputCapture ::收到
。不过,我努力获得正确的函数签名。
Now, I would like to move to C++ implementation. More specifically, I would like to use boost::function / boost::bind to bind the sa_sigaction to a method InputCapture::receive
. However, I am struggling to get the correct function signature.
下面是InputCapture类的定义:
Here is the definition of the InputCapture Class:
class InputCapture
{
public: InputCapture(uint8_t intimer) : timer(_timer) {}
public: ~InputCapture() {}
private: void receive(int n, siginfo_t *info, void *unused) {}
private: uint8_t timer;
};
这里是修改sa_sigaction:
And here is the modified sa_sigaction:
// Register for updates from the kernel
struct sigaction sig;
sig.sa_sigaction = boost::function<void (int n, siginfo_t *info, void *unused)> (
boost::bind(&InputCapture::receive, this, _1));
sig.sa_flags = SA_SIGINFO;
sigaction(SOME_CUSTOM_SIGNAL, &sig, NULL);
不过,我得到以下编译错误:
However, I get the following compilation error:
在文件从/home/asymingt/export/rootfs/usr/include/boost/bind.hpp:22:0包括,
从/home/asymingt/Workspace/Source/roseline/timesync/src/stamp/LogicalStamp.hpp:12,
从/home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.hpp:4,
从/home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:1:
/home/asymingt/export/rootfs/usr/include/boost/bind/bind.hpp:在结构的boost :: _双:: result_traits'实例:
/home/asymingt/export/rootfs/usr/include/boost/bind/bind_template.hpp:15:48:从类boost :: _双:: bind_t)(INT,SIGINFO,无效*)要求,提振:: _双::列表2,升压:: ARG&LT; 1>>>
/home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:41:57:从这里需要
/home/asymingt/export/rootfs/usr/include/boost/bind/bind.hpp:69:37:错误:无效(时间同步:: InputCapture :: )(INT,SIGINFO 的,无效的*)'不是一个类,结构或联合类型
的typedef typename的˚F:: result_type的类型;
^
/home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:在构造函数中时间同步:: InputCapture :: InputCapture(uint8_t有):
/home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:40:19:错误:无法转换'的boost ::函数到无效()(INT,siginfo_t ,无效*){又名无效()(INT,SIGINFO 的,无效*)}'赋值
sig.sa_sigaction =的boost ::功能(
^
从/home/asymingt/export/rootfs/usr/include/boost/function/detail/maybe_include.hpp:28:0包含在文件中,
从/home/asymingt/export/rootfs/usr/include/boost/function/detail/function_iterate.hpp:14,
从/home/asymingt/export/rootfs/usr/include/boost/$p$pprocessor/iteration/detail/iter/forward1.hpp:62,
从/home/asymingt/export/rootfs/usr/include/boost/function.hpp:64,
从/home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:3:
/home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:在静态无效的实例boost::detail::function::void_function_obj_invoker3::invoke(boost::detail::function::function_buffer&, T0,T1,T2)与FunctionObj =提振:: _双:: bind_t)(INT,SIGINFO,无效*),提振:: _双::列表2,提振:: ARG&LT; 1>>>; R =无效; T0 = INT; T1 = SIGINFO *; T2 =无效*]':
/home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:907:38:从'无效的boost :: function3 :: assign_to(函子)需要[用函子=提振:: _双向:: bind_t )(INT,SIGINFO,无效*),提振:: _双::列表2,提振:: ARG&LT; 1>>>; R =无效; T0 = INT; T1 = SIGINFO *; T2 =无效*]
/home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:722:7:从'助推:: function3 :: function3(函子需要,类型名的boost :: enable_if_c ::值> ::值,int>的::类型)与函子=提振:: _双:: bind_t)(INT,SIGINFO,无效*),提振:: _双::列表2,提振:: ARG&LT; 1>>>; R =无效; T0 = INT; T1 = SIGINFO *; T2 =无效*;类型名的boost :: enable_if_c ::值> ::价值,诠释> ::类型= INT]'
/home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:1042:16:从'的boost ::功能::功能(需要的函数对象,类型名的boost :: enable_if_c ::值> ::值,int>的::类型)与函子=提振:: _双:: bind_t)(INT,SIGINFO,无效*),提振:: _双::列表2,提振:: ARG&LT; 1>>>; R =无效; T0 = INT; T1 = SIGINFO *; T2 =无效*;类型名的boost :: enable_if_c ::值> ::价值,诠释> ::类型= INT]'
/home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:41:58:从这里需要
/home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:153:57:错误:不对应的呼叫'(提高:: _双:: bind_t)(INT,SIGINFO,无效*) ,提振:: _双::列表2,提振:: ARG&LT; 1>>>)(INT和放大器;,SIGINFO *放大器;,无效*放大器;)
BOOST_FUNCTION_RETURN((* F)(BOOST_FUNCTION_ARGS));
^
/home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:75:36:注:宏'BOOST_FUNCTION_RETURN的定义
#定义BOOST_FUNCTION_RETURN(X)X
In file included from /home/asymingt/export/rootfs/usr/include/boost/bind.hpp:22:0, from /home/asymingt/Workspace/Source/roseline/timesync/src/stamp/LogicalStamp.hpp:12, from /home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.hpp:4, from /home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:1: /home/asymingt/export/rootfs/usr/include/boost/bind/bind.hpp: In instantiation of ‘struct boost::_bi::result_traits’: /home/asymingt/export/rootfs/usr/include/boost/bind/bind_template.hpp:15:48: required from ‘class boost::_bi::bind_t)(int, siginfo, void*), boost::_bi::list2, boost::arg<1> > >’ /home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:41:57: required from here /home/asymingt/export/rootfs/usr/include/boost/bind/bind.hpp:69:37: error: ‘void (timesync::InputCapture::)(int, siginfo, void*)’ is not a class, struct, or union type typedef typename F::result_type type; ^ /home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp: In constructor ‘timesync::InputCapture::InputCapture(uint8_t)’: /home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:40:19: error: cannot convert ‘boost::function’ to ‘void ()(int, siginfo_t, void*) {aka void ()(int, siginfo, void*)}’ in assignment sig.sa_sigaction = boost::function ( ^ In file included from /home/asymingt/export/rootfs/usr/include/boost/function/detail/maybe_include.hpp:28:0, from /home/asymingt/export/rootfs/usr/include/boost/function/detail/function_iterate.hpp:14, from /home/asymingt/export/rootfs/usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:62, from /home/asymingt/export/rootfs/usr/include/boost/function.hpp:64, from /home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:3: /home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp: In instantiation of ‘static void boost::detail::function::void_function_obj_invoker3::invoke(boost::detail::function::function_buffer&, T0, T1, T2) [with FunctionObj = boost::_bi::bind_t)(int, siginfo, void*), boost::_bi::list2, boost::arg<1> > >; R = void; T0 = int; T1 = siginfo*; T2 = void*]’: /home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:907:38: required from ‘void boost::function3::assign_to(Functor) [with Functor = boost::_bi::bind_t)(int, siginfo, void*), boost::_bi::list2, boost::arg<1> > >; R = void; T0 = int; T1 = siginfo*; T2 = void*]’ /home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:722:7: required from ‘boost::function3::function3(Functor, typename boost::enable_if_c::value>::value, int>::type) [with Functor = boost::_bi::bind_t)(int, siginfo, void*), boost::_bi::list2, boost::arg<1> > >; R = void; T0 = int; T1 = siginfo*; T2 = void*; typename boost::enable_if_c::value>::value, int>::type = int]’ /home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:1042:16: required from ‘boost::function::function(Functor, typename boost::enable_if_c::value>::value, int>::type) [with Functor = boost::_bi::bind_t)(int, siginfo, void*), boost::_bi::list2, boost::arg<1> > >; R = void; T0 = int; T1 = siginfo*; T2 = void*; typename boost::enable_if_c::value>::value, int>::type = int]’ /home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:41:58: required from here /home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:153:57: error: no match for call to ‘(boost::_bi::bind_t)(int, siginfo, void*), boost::_bi::list2, boost::arg<1> > >) (int&, siginfo*&, void*&)’ BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS)); ^ /home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:75:36: note: in definition of macro ‘BOOST_FUNCTION_RETURN’ # define BOOST_FUNCTION_RETURN(X) X
就是我想实现可能,如果是这样,我在哪里出了错?
Is what I am trying to achieve possible, and if so, where have I gone wrong?
推荐答案
您不能做到这一点。
注意的sigaction :: sa_sigaction
是函数的指针。无论是的boost ::功能
,也不的boost ::绑定
的返回值可以转化为函数指针!
Note that sigaction::sa_sigaction
is a pointer to function. Neither boost::function
, nor the return value of boost::bind
are convertible to a function pointer!
这篇关于的boost ::绑定的sigaction函数引用一个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!