C Signal Slot Library
Project page |
Wheel of Wishes is the latest addition to Signal Slot C Library the jackpot family of casino online and mobile slots. With 5 reels and 10 paylines, this game features Power Spins, a Signal Slot C Library Scatter and a Wild, as Signal Slot C Library well as a Wheel of Wishes Jackpot Bonus, with 4 different progressive jackpots that can be won at any time. Which should result in a few thousand signal per sec. Which is far form 'I clicked a button'. All my object will also signal them self on a timer about every 100ms so they can do some processing. What would be the fastest C Signal/Slot implementation which would be small and not require other library such as boost. Why Yet Another Signal-Slot Library? This library is optimized for video games (and probably other low-latency applications as well). Interestingly, even though the observer pattern is generally useful, it has never been standardized in C, which leads to the never-ending attempts at improvements by curious people.
What ?
When programming in C, it's usual to use callback functions(moreover when you do GUI stuffs). In C++, we prefer to encapsulate thingsinto classes, and usually we want a rather type-safety. This small libraryattempt to provide an easy-to-use, type-safe, C++-friendly solution to theproblem. The idea is to define slots, either as global functions ormember methods, that will be called when some signals areemitted The signals and slots do not need to really know about eachother, only a pointer and a compatible signature is required. Inconsistentconnections (when return type or parameters do not match) should be detectedat compile-time.
But what all this is about ?
I'm glad you ask, probably you're not familiar with the signal/slotparadigm. So here's a small explaination.
Imagine you're writing a program with a graphical user interface (GUI).The purpose of this program is to compute some nice image, for example somecomplex fractal, then display it. Most probably, you'll have at least twographical components : an area where to display the image, and a buttoncalled 'start'. When the user clicks the button, the image is computed insome other part of the program, then displayed when it's finished.
All of this can be accomplished using callbacks, and it's the method usedby many GUI toolkits. Forget a little bit the code. The simple structurepresented above can be illustrated like this :
When clicked, the button 'emits' some kind of signal, which will launchthe image computation. When this is finished, some other kind of signal is'emitted', to tell 'the image is ready'. So the display method can displayit. Again, all of this can be done using callbacks.
But generic callbacks often imply passing parameters as void*
pointers, which is, say, not nice. Also, what is you want to add somefunction to store the image in a file ? You need to call at leasttwo functions when the image is computed, which means givingtwo callbacks. So you have to create some 'callbacks-management'code.
In the signals/slots paradigm, this is not a problem. The computing parthave a slot, used to launch the image computation. Any number of signals canbe connected to this slot, so more than one event can cause the imagecomputation. In the same way, this code part has a signal telling others thatthe image is ready. Any number of slots can be connected to this signal : oneslot to display the image, one to save it, for example.
This library attempts to provide a generic signals/slots framework usingthe C++ language, avoiding the need to do nasty casts by insuring signals andslots can be connected. They can be connected if they have the same completesignature, that is, the same return type, and the same number and types ofarguments.
Why ?
If you've heard about the Qt, libsigc++, Sigslot or boost libraries, or any other I'm not awareof (if this is the case, let me know !), maybe you wonder why yet anothersignals lib. Here are the main reasons :
Qt's system needs a preprocessor (called
moc
, for Meta-Object Compiler) that will produce additionnal code to enable the connections and handle the signal emitting ; it's quite simple to use, but you can't use templates on signal/slot-enabled classes, and inconsistencies are not detected at compile time but at runtime ;I found libsig++ a great thing, but a little bit to complex to use, and I dislike some casts done into it ; I also dislike the fact that a function (or method) connected twice will be called twice when emitting the signal ;
Boost is fine, but to use the signals module you also need a rather large part of the whole lib ; there's nothing really wrong with that, I just wanted something smaller – and easier to use ;
It was fun to code, and because I did it, I find SlotSig the simplest signal/slot library available ;-)
Download
Pyside2 Signal Slot
I would like here to send a great thanks to those who tried the library,and gave so useful feedback about it. Especially Leopold Palomo Avellaneda,who tried it hard and gave some nice advices from the user's point-of-vue.Thanks Leo !
A changelog is available, because the libraryevolves, as does everything in the known universe.
All releases are available through these links :
Release | Date | File | md5sum |
---|---|---|---|
1.0.0 | 2006-04-17 | slotsig-1.0.0.tar.bz2 | 420dd16af7a6fca92b0b9cdda55363dd |
0.7 | 2005-12-09 | slotsig-0.7.tar.bz2 | 38795d1b6f2caecad60fb36dedc1f94b |
0.6 | 2004-06-11 | slotsig-0.6.tar.bz2 | dfe9f5d3f17075ec23eb923899ac5f24 |
0.5.1 | 2004-05-23 | slotsig-0.5.1.tar.bz2 | 1bf990adb33c556c67a13df81ff88889 |
0.5 | 2004-05-20 | slotsig-0.5.tar.bz2 | f023d1f88d57e9298fbbd6d3288d2ca3 |
0.4 | 2004-03-23 | slotsig-0.4.tar.bz2 | 877f7da03b247d1c778fc0729269fb60 |
0.3 | 2003-11-22 | slotsig-0.3.tar.bz2 | 06343ee4472b9f56d6b7cf1ba2c9e98d |
0.2 | 2003-06-09 | slotsig-0.2.tar.bz2 | 47d4b9a86020c970142c256769ed7f6c |
0.1 | 2003-06-03 | slotsig-0.1.tar.bz2 | 61d6ff387d0b451035aec7aa1ccb2d24 |
About the two oldest, I guess I should be ashamed...
Documentation
SlotSig comes with a full set of documentation, which can be readon-line :
- a simple tutorial, to get started ;
- the so-called 'installation procedure', if it can be called such ;
- advanced documentation, to go further with SlotSig ;
- benchmarks comparing SlotSig performances with some others, for those who like graphs ;
- features comparison, again comparing SlotSig with others.
There's also a mailing-listabout SlotSig, for now mainly used to announce new releases or major newfeatures. So its volume is very low (say, a message every two weeks), and isnot expected to grow much.
Contact
If you have nice ideas, or pertinent comments about this humble library,you can send me an email at slotsig_AT_kafka-fr_DOT_net(change the _AT_ and the _DOT_ to the letters of the same name).
I would also appreciate to know about you if you're using the library, andwhat you're doing with it.
Last update 2006-04-17
- C++ Basics
C Signal Slot Library Locations
- C++ Object Oriented
C Signal Slot Library Games
- C++ Advanced
- C++ Useful Resources
- Selected Reading
Signals are the interrupts delivered to a process by the operating system which can terminate a program prematurely. You can generate interrupts by pressing Ctrl+C on a UNIX, LINUX, Mac OS X or Windows system.
There are signals which can not be caught by the program but there is a following list of signals which you can catch in your program and can take appropriate actions based on the signal. These signals are defined in C++ header file <csignal>.
Sr.No | Signal & Description |
---|---|
1 | SIGABRT Abnormal termination of the program, such as a call to abort. |
2 | SIGFPE An erroneous arithmetic operation, such as a divide by zero or an operation resulting in overflow. |
3 | SIGILL Detection of an illegal instruction. |
4 | SIGINT Receipt of an interactive attention signal. |
5 | SIGSEGV An invalid access to storage. |
6 | SIGTERM A termination request sent to the program. |
The signal() Function
C++ signal-handling library provides function signal to trap unexpected events. Following is the syntax of the signal() function −
Keeping it simple, this function receives two arguments: first argument as an integer which represents signal number and second argument as a pointer to the signal-handling function.
Let us write a simple C++ program where we will catch SIGINT signal using signal() function. Whatever signal you want to catch in your program, you must register that signal using signal function and associate it with a signal handler. Examine the following example −
When the above code is compiled and executed, it produces the following result −
Now, press Ctrl+c to interrupt the program and you will see that your program will catch the signal and would come out by printing something as follows −
The raise() Function
You can generate signals by function raise(), which takes an integer signal number as an argument and has the following syntax.
Here, sig is the signal number to send any of the signals: SIGINT, SIGABRT, SIGFPE, SIGILL, SIGSEGV, SIGTERM, SIGHUP. Following is the example where we raise a signal internally using raise() function as follows −
When the above code is compiled and executed, it produces the following result and would come out automatically −