copperspice / cs_signal Goto Github PK
View Code? Open in Web Editor NEWThread aware Signal/Slot library
Home Page: https://www.copperspice.com/
License: Other
Thread aware Signal/Slot library
Home Page: https://www.copperspice.com/
License: Other
Are there any samples demonstrating the usage of the API?
I intend to use it in my project and I found very little documentation on how to use or any samples demonstrating the core functionality. I tried using it and found that there are subtle differences in how it can be used with Qt application.
Some examples would help!!
The following will not compile due to the 'noexcept' specifier on the activate() function:
class Receiver: public CsSignal::SlotBase
{
public:
Receiver ();
void activate () noexcept;
};
class Sender: public CsSignal::SignalBase
{
public:
Sender ();
SIGNAL_1 (void send ());
SIGNAL_2 (send);
};
int main(int argc, char *argv[])
{
Sender transmitter;
Receiver radio;
connect (transmitter, &Sender::send, radio, &Receiver::activate);
return 0;
}
with the following error:
cs_internal.h(432): error C2825: 'T': must be a class or namespace when followed by '::'
cs_signal.h(341): note: see reference to class template instantiation 'CsSignal::Internal::Bento<void (__cdecl Receiver::* )(void) noexcept>' being compiled
main.cpp(12): note: see reference to function template instantiation 'bool CsSignal::connect<Sender,Sender,,Receiver,void(__cdecl Receiver::* )(void) noexcept>(const Sender &,void (__cdecl Sender::* )(void),const Receiver &,T,CsSignal::ConnectionKind,bool)' being compiled
with
[
Sender=Sender,
Receiver=Receiver,
T=void (__cdecl Receiver::* )(void) noexcept
]
cs_internal.h(432): error C2653: 'T': is not a class or namespace name
cs_internal.h(432): error C2269: cannot create a pointer or reference to a qualified function type (requires pointer-to-member)
cs_internal.h(435): error C2825: 'T': must be a class or namespace when followed by '::'
cs_internal.h(435): error C2653: 'T': is not a class or namespace name
cs_internal.h(435): error C2535: 'void CsSignal::Internal::Bento<void (__cdecl Receiver::* )(void) noexcept>::invoke_internal(const CsSignal::Internal::TeaCupAbstract *,MethodReturn (__cdecl *)(MethodArgs...)) const': member function already defined or declared
cs_internal.h(432): note: see declaration of 'CsSignal::Internal::Bento<void (__cdecl Receiver::* )(void) noexcept>::invoke_internal'
This is with CsSignal 1.2.3 and Visual Studio CE 2022.
Making the send() function noexcept does not help.
I am not sure if there is an easy solution. The 'noexcept' specification is part of the function type but I don't know if it is used for scope resolution (e.g. matching function type to function by the compiler, like const vs. non-const). Adding a copy of invoke_internal() with a noexcept specifier did not help...
Current cmake file indicates 1.2.2 but there is no tag on this repository.
Do you expect to release a new version of signal at some point ?
I'm using visual studio 2019 with it's clang-cl:
[1/4] C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\Llvm\bin\clang-cl.exe /nologo -TP -DBUILDING_LIB_CS_SIGNAL -DCsSignal_EXPORTS -I. -I..\..\..\ -I..\..\..\src -m32 -fdiagnostics-absolute-paths /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MD /Zi /O2 /Ob1 /DNDEBUG -std:c++17 /showIncludes /FoCMakeFiles\CsSignal.dir\src\cs_signal.cpp.obj /FdCMakeFiles\CsSignal.dir\ -c ..\..\..\src\cs_signal.cpp FAILED: CMakeFiles/CsSignal.dir/src/cs_signal.cpp.obj C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\Llvm\bin\clang-cl.exe /nologo -TP -DBUILDING_LIB_CS_SIGNAL -DCsSignal_EXPORTS -I. -I..\..\..\ -I..\..\..\src -m32 -fdiagnostics-absolute-paths /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MD /Zi /O2 /Ob1 /DNDEBUG -std:c++17 /showIncludes /FoCMakeFiles\CsSignal.dir\src\cs_signal.cpp.obj /FdCMakeFiles\CsSignal.dir\ -c ..\..\..\src\cs_signal.cpp In file included from ..\..\..\src\cs_signal.cpp:19: In file included from ..\..\..\src/cs_signal.h:33: In file included from ..\..\..\src/cs_slot.h:29: C:\Users\fradd\Downloads\cs_signal-master\src\rcu_guarded.hpp(143,7): error : no matching constructor for initialization of 'libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> >' : m_obj(std::forward<Us>(data)...) ^ ~~~~~~~~~~~~~~~~~~~~~~ C:\Users\fradd\Downloads\cs_signal-master\src\cs_signal.h(83,22): note: in instantiation of function template specialization 'libguarded::rcu_guarded<libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> > >::rcu_guarded<libguarded::rcu_guarded<libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> > > &>' requested here class LIB_SIG_EXPORT SignalBase ^ C:\Users\fradd\Downloads\cs_signal-master\src\rcu_list.hpp(75,16): note: candidate constructor not viable: no known conversion from 'libguarded::rcu_guarded<libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> > >' to 'const std::allocator<CsSignal::SignalBase::ConnectStruct>' for 1st argument explicit rcu_list(const Alloc &alloc); ^ C:\Users\fradd\Downloads\cs_signal-master\src\rcu_list.hpp(77,7): note: candidate constructor not viable: no known conversion from 'libguarded::rcu_guarded<libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> > >' to 'const libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> >' for 1st argument rcu_list(const rcu_list &) = delete; ^ C:\Users\fradd\Downloads\cs_signal-master\src\rcu_list.hpp(78,7): note: candidate constructor not viable: no known conversion from 'libguarded::rcu_guarded<libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> > >' to 'libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> >' for 1st argument rcu_list(rcu_list &&) = delete; ^ C:\Users\fradd\Downloads\cs_signal-master\src\rcu_list.hpp(74,7): note: candidate constructor not viable: requires 0 arguments, but 1 was provided rcu_list(); ^ 1 error generated. [2/4] C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\Llvm\bin\clang-cl.exe /nologo -TP -DBUILDING_LIB_CS_SIGNAL -DCsSignal_EXPORTS -I. -I..\..\..\ -I..\..\..\src -m32 -fdiagnostics-absolute-paths /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MD /Zi /O2 /Ob1 /DNDEBUG -std:c++17 /showIncludes /FoCMakeFiles\CsSignal.dir\src\cs_slot.cpp.obj /FdCMakeFiles\CsSignal.dir\ -c ..\..\..\src\cs_slot.cpp FAILED: CMakeFiles/CsSignal.dir/src/cs_slot.cpp.obj C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\Llvm\bin\clang-cl.exe /nologo -TP -DBUILDING_LIB_CS_SIGNAL -DCsSignal_EXPORTS -I. -I..\..\..\ -I..\..\..\src -m32 -fdiagnostics-absolute-paths /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MD /Zi /O2 /Ob1 /DNDEBUG -std:c++17 /showIncludes /FoCMakeFiles\CsSignal.dir\src\cs_slot.cpp.obj /FdCMakeFiles\CsSignal.dir\ -c ..\..\..\src\cs_slot.cpp In file included from ..\..\..\src\cs_slot.cpp:19: In file included from ..\..\..\src/cs_signal.h:33: In file included from ..\..\..\src/cs_slot.h:29: C:\Users\fradd\Downloads\cs_signal-master\src\rcu_guarded.hpp(143,7): error : no matching constructor for initialization of 'libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> >' : m_obj(std::forward<Us>(data)...) ^ ~~~~~~~~~~~~~~~~~~~~~~ C:\Users\fradd\Downloads\cs_signal-master\src\cs_signal.h(83,22): note: in instantiation of function template specialization 'libguarded::rcu_guarded<libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> > >::rcu_guarded<libguarded::rcu_guarded<libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> > > &>' requested here class LIB_SIG_EXPORT SignalBase ^ C:\Users\fradd\Downloads\cs_signal-master\src\rcu_list.hpp(75,16): note: candidate constructor not viable: no known conversion from 'libguarded::rcu_guarded<libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> > >' to 'const std::allocator<CsSignal::SignalBase::ConnectStruct>' for 1st argument explicit rcu_list(const Alloc &alloc); ^ C:\Users\fradd\Downloads\cs_signal-master\src\rcu_list.hpp(77,7): note: candidate constructor not viable: no known conversion from 'libguarded::rcu_guarded<libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> > >' to 'const libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> >' for 1st argument rcu_list(const rcu_list &) = delete; ^ C:\Users\fradd\Downloads\cs_signal-master\src\rcu_list.hpp(78,7): note: candidate constructor not viable: no known conversion from 'libguarded::rcu_guarded<libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> > >' to 'libguarded::rcu_list<CsSignal::SignalBase::ConnectStruct, std::mutex, std::allocator<CsSignal::SignalBase::ConnectStruct> >' for 1st argument rcu_list(rcu_list &&) = delete; ^ C:\Users\fradd\Downloads\cs_signal-master\src\rcu_list.hpp(74,7): note: candidate constructor not viable: requires 0 arguments, but 1 was provided rcu_list(); ^ 1 error generated. ninja: build stopped: subcommand failed.
Currently the syntax is quite ugly:
SIGNAL_1(void someSignal(int arg1, int arg2))
SIGNAL_2(someSignal, arg1, arg2)
Duplication of the signal name and argument names can't be avoided without complicated macro and even more strange syntax (like Boost::Fusion).
But the following alternative seems equivalent, but looks a bit cleaner to me:
void someSignal(int arg1, int arg2) { ACTIVATE(someSignal, arg1, arg2); }
or
void someSignal(int arg1, int arg2) ACTIVATE(someSignal, arg1, arg2)
As mentionned in #14 (comment), this project does not uses tags. It does use some kind of versionning though, as can be seen on 6add822#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20a
There is currently no documented way to download a given version of this library. This is a problem because it prevents reliable use of this library.
Some possibilities:
These repos have the same problem, but I'm not duplicating the issue: https://github.com/copperspice/cs_string, https://github.com/copperspice/cs_libguarded, https://github.com/copperspice/cs_paint
Hello, I added cs_signal to my signal-slot-benchmarks project and have encountered issues trying to run the threaded portion of the benchmark. I'm not sure if the issue is solely in cs_signal or due to a bad integration on my part.
Please refer to the rework branch of signal-slot-benchmarks including my integration of cs_signal.
For reference here is the location of the sometimes encountered exception:
Edit: The file is cs_signal.h
I tried to create a new project and dragging cs_signal.cpp, main.cpp and peach.cpp in.
1>cs_signal.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) const CsSignal::SignalBase::`vftable'" (__imp_??_7SignalBase@CsSignal@@6B@) referenced in function "public: virtual __cdecl CsSignal::SignalBase::~SignalBase(void)" (??1SignalBase@CsSignal@@UEAA@XZ)
1>cs_slot.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl CsSignal::PendingSlot::~PendingSlot(void)" (__imp_??1PendingSlot@CsSignal@@QEAA@XZ) referenced in function "private: virtual void __cdecl CsSignal::SlotBase::queueSlot(class CsSignal::PendingSlot,enum CsSignal::ConnectionKind)" (?queueSlot@SlotBase@CsSignal@@EEAAXVPendingSlot@2@W4ConnectionKind@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl CsSignal::PendingSlot::~PendingSlot(void)" (__imp_??1PendingSlot@CsSignal@@QEAA@XZ)
1>peach.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl CsSignal::PendingSlot::~PendingSlot(void)" (__imp_??1PendingSlot@CsSignal@@QEAA@XZ)
1>cs_slot.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) const CsSignal::SlotBase::`vftable'" (__imp_??_7SlotBase@CsSignal@@6B@) referenced in function "public: __cdecl CsSignal::SlotBase::SlotBase(class CsSignal::SlotBase const &)" (??0SlotBase@CsSignal@@QEAA@AEBV01@@Z)
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl CsSignal::PendingSlot::PendingSlot(class CsSignal::PendingSlot &&)" (__imp_??0PendingSlot@CsSignal@@QEAA@$$QEAV01@@Z) referenced in function "void __cdecl CsSignal::activate<class TestPushButton,class TestPushButton>(class TestPushButton &,void (__cdecl TestPushButton::*)(void))" (??$activate@VTestPushButton@@V1@$$V$$Z$$V@CsSignal@@YAXAEAVTestPushButton@@P81@EAAXXZ@Z)
1>peach.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl CsSignal::PendingSlot::PendingSlot(class CsSignal::PendingSlot &&)" (__imp_??0PendingSlot@CsSignal@@QEAA@$$QEAV01@@Z)
1> Hint on symbols that are defined and could potentially match:
1> "__declspec(dllimport) public: __cdecl CsSignal::PendingSlot::PendingSlot(class CsSignal::SignalBase *,class std::unique_ptr<class CsSignal::Internal::BentoAbstract,struct std::default_delete<class CsSignal::Internal::BentoAbstract> >,class CsSignal::SlotBase *,class std::unique_ptr<class CsSignal::Internal::BentoAbstract,struct std::default_delete<class CsSignal::Internal::BentoAbstract> >,class std::unique_ptr<class CsSignal::Internal::TeaCupAbstract,struct std::default_delete<class CsSignal::Internal::TeaCupAbstract> >)" (__imp_??0PendingSlot@CsSignal@@QEAA@PEAVSignalBase@1@V?$unique_ptr@VBentoAbstract@Internal@CsSignal@@U?$default_delete@VBentoAbstract@Internal@CsSignal@@@std@@@std@@PEAVSlotBase@1@1V?$unique_ptr@VTeaCupAbstract@Internal@CsSignal@@U?$default_delete@VTeaCupAbstract@Internal@CsSignal@@@std@@@4@@Z)
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl CsSignal::SignalBase::SignalBase(void)" (__imp_??0SignalBase@CsSignal@@QEAA@XZ) referenced in function "public: __cdecl TestPushButton::TestPushButton(void)" (??0TestPushButton@@QEAA@XZ)
1>peach.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class CsSignal::SlotBase * __cdecl CsSignal::PendingSlot::receiver(void)const " (__imp_?receiver@PendingSlot@CsSignal@@QEBAPEAVSlotBase@2@XZ) referenced in function "private: virtual void __cdecl Peach::queueSlot(class CsSignal::PendingSlot,enum CsSignal::ConnectionKind)" (?queueSlot@Peach@@EEAAXVPendingSlot@CsSignal@@W4ConnectionKind@3@@Z)
1>D:\project2\cs_signal\vs2019\x64\Debug\cs_signal.exe : fatal error LNK1120: 6 unresolved externals
1>Done building project "cs_signal.vcxproj" -- FAILED.
I think I've found a serious bug in CsSignal. I had several program crashes before I figured out what was going on.
If we have two objects assigned to two different threads (so these two threads decide when to destroy those objects), and one object gets destroyed by its associated thread while another object emits a signal, this line of code will crash the entire program:
Line 183 in f20001a
Copperspice has the macros that allows overloaded functions to be used as signals but cs_signal is missing those functions.
Following code throws compile error in cs_signal but works as expected (with alternative macros) in copperspice.
SIGNAL_1(void added(ClassA *a)
SIGNAL_2(added, a)
SIGNAL_1(void added(ClassB *b)
SIGNAL_2(added, b)
There are some discussions (#2) that talk about supporting overloaded signals but I can't seem to find any examples of how to use it.
Can you provide a CMake build script for building cs_signal? I tried building them with autotool and it did succeed but I couldn't find any generated lib to link against. The only output files I got were the following -
bin/libCsSignal-0.dll
lib/licCsSignal.dll.a // This looks like the library but has the wrong extension?
lib/libCsSignal.la
Also, install should have created a "include" directory with necessary public headers which was also missing. The included autoconf doesn't have an option to build debug and release configurations.
Optionally, additional instructions/documentation on how to build these libraries for different platforms would help.
Hi.
Thanks for making this project and your YouTube videos available! I appreciate your efforts!!!
I am hitting a problem with cs_signal compiled with vs2019. Everything works as expected in Debug mode. But in Release mode when signals/slots have the same signature the incorrect slot can be called. . My guess is this is due to some compiler optimization.
I made a minimalist version of my project that demonstrates the problem
https://github.com/Hurleyworks/MVC
Running in Debug you can see that each signal generated by a button press goes to the correct slot. But in Release mode, if you press the Send 1 button, for example, all 4 slots with the same signature in Model get called
-Steve
While compilingCsSignal on Windows, CMake complained about this:
Cannot specify link options for target "CsCore" which is not built by this
project.
On line 40 in src/signal.cmake it says "target_link_options(CsCore ...", not CsSignal.
Hi,
I would love some documention and examples in Wiki or in a readme. Maybe a minimal effort would be to link to this documention?: http://www.copperspice.com/docs/cs_signal/lib-overview.html
Thanks
Kjell Hedstrom
Both CsSignal and CsLibGuarded provide the class template rcu_guarded
in the namespace libguarded
: https://github.com/copperspice/cs_signal/blob/master/src/cs_rcu_guarded.h https://github.com/copperspice/cs_libguarded/blob/master/src/cs_rcu_guarded.h
This has a very high likelihood of producing ODR violation per
https://eel.is/c++draft/basic.def.odr#10.sentence-1
https://eel.is/c++draft/basic.def.odr#13.sentence-1
https://eel.is/c++draft/basic.def.odr#13.8
https://eel.is/c++draft/basic.def.odr#15
because there is no way a user of both these libraries can know if these two definitions consist of the same sequence of tokens, without brute-forcing the comparison of sources.
some possibilities:
The same situation happens with https://github.com/copperspice/copperspice which embeds CsSignal, CsLibGuarded and CsString
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.