{"id":17062139,"url":"https://github.com/recp/libsig","last_synced_at":"2025-08-22T12:41:38.891Z","repository":{"id":20154621,"uuid":"23425108","full_name":"recp/libsig","owner":"recp","description":"Signal/Event handling lib for C/C++","archived":false,"fork":false,"pushed_at":"2015-05-08T11:54:22.000Z","size":416,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T18:12:41.055Z","etag":null,"topics":["event","event-emitter","notification","signal","signal-handler"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/recp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-28T11:12:58.000Z","updated_at":"2024-04-22T12:30:56.000Z","dependencies_parsed_at":"2022-09-01T12:40:34.556Z","dependency_job_id":null,"html_url":"https://github.com/recp/libsig","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/recp/libsig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recp%2Flibsig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recp%2Flibsig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recp%2Flibsig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recp%2Flibsig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/recp","download_url":"https://codeload.github.com/recp/libsig/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recp%2Flibsig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271641787,"owners_count":24795435,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["event","event-emitter","notification","signal","signal-handler"],"created_at":"2024-10-14T10:49:18.766Z","updated_at":"2025-08-22T12:41:38.805Z","avatar_url":"https://github.com/recp.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"libsig\n======\n\nSignal/Event handling lib for C/C++\n\n[![Build Status](https://travis-ci.org/recp/libsig.svg?branch=master)](https://travis-ci.org/recp/libsig)\n\nligsig is a signal/event library for C and C++ which allows to handling\nsignals/events like observer pattern. Member functions also\ncan be used as callbacks.\n\nEach signal has a signal context which allows that signals can be used in their own\n context.\nAlso the system signals such as SIGPIPE... can be observed in system context\n(sig_sys_ctx) ).\n\nPredefined contexts:\n```C\n// sig_attach/sig_detach/sig_fire functions\n// use the default ctx if there is no specified one\nconst sig_context_t * sig_ctx_default();\n\n// sistem signals can be observed by using this ctx\nconst sig_context_t * sig_ctx_sys();\n```\n\nAlloc and free custom contexts:\n```C\nconst sig_context_t * sig_ctx_new();\nvoid sig_ctx_free(const sig_context_t * ctx);\n```\n\n####For C:####\nThe functions are overloaded by `_s` postfix (and `c` postfix for custom contexts):\n```C\n/*\n  For all (or full) declerations (especially for custom ctx)\n  look at the sig.h header\n */\n\n/* Observe a signal by signal name or id */\nvoid sig_attach(int signal, sig_observer_cb_t cb);\nvoid sig_attach_s(const char * signal, sig_observer_cb_t cb);\n\n/* Stop observe a signal by signal name or id */\nvoid sig_detach(int signal, sig_observer_cb_t cb);\nvoid sig_detach_s(const char * signal, sig_observer_cb_t cb);\n\n/* Fire a signal by signal name or id */\nvoid sig_fire(int signal, void * object);\nvoid sig_fire_s(const char * signal, void * object);\n```\n\n####For C++:####\n```C++\n/*\n  For all (or full) declerations (especially for custom ctx)\n  look at the sig.h header\n */\n\n/* Observe a signal by signal name or id */\nvoid sig_attach(int signal, sig_observer_cb_t cb);\nvoid sig_attach(const char * signal, sig_observer_cb_t cb);\n\n// For member functions\nvoid sig_attach(int signal, sig_slot(T *, Func));\nvoid sig_attach(const char * signal, sig_slot(T *, Func));\n\n// -------------------------------------------------------\n\n/* Stop observe a signal by signal name or id */\nvoid sig_detach(int signal, sig_observer_cb_t cb);\nvoid sig_detach(const char * signal, sig_observer_cb_t cb);\n\n// For member functions\nvoid sig_detach(int signal, sig_slot(T *, Func));\nvoid sig_detach(const char * signal, sig_slot(T *, Func));\n\n// Detach all observers from the object/instance\nvoid sig_detach(void * observer);\nvoid sig_detach(void * observer, const sig_context_t * ctx);\n\n// -------------------------------------------------------\n\n/* Fire a signal by signal name or id */\nvoid sig_fire(int signal, void * object);\nvoid sig_fire(const char * signal, void * object);\n```\n\nSignals also can be observed or can be fired by the following style for C++:\n\n```C++\n/* Observe a signal */\nsig::attach[1234] \u003c\u003c fn_callback1 ... ;\nsig::attach[\"signal_name\"] \u003c\u003c fn_callback1 \u003c\u003c fn_callback2 ...;\n\n/* Stop observe */\nsig::detach[1234] \u003e\u003e fn_callback1 ...;\nsig::detach[\"signal_name\"] \u003e\u003e fn_callback1 \u003e\u003e fn_callback2 ...;\n\n/* Fire (trigger) a signal */\nsig:fire[\"signal_name\"] \u003c\u003c (void *)\"Signal object (void *)\";\n```\n\n## Build\n\n### Unix / Macintosh\n\n```text\n$ sh autogen.sh\n$ ./configure\n$ make\n$ [sudo] make install\n```\n\n### Windows\n\n```text\n$ msbuild libsig.vcxproj /p:Configuration=Release\n```\n\n###Sample###\n\n```C++\n#include \u003ciostream\u003e\n#include \u003csignal.h\u003e\n#include \u003csig.h\u003e\n\n#define CUSTOM_NTF1 123\n\nclass TestClass {\npublic:\n  TestClass() {\n    sig_attach(CUSTOM_NTF1,\n               sig_slot(this, \u0026TestClass::memberFn));\n\n    sig_attach(\"custom_ntf2\",\n               sig_slot(this, \u0026TestClass::memberFn));\n\n    // Attach / Observe system signals\n    sig_attach(SIGUSR1,\n               sig_slot(this, \u0026TestClass::memberFn),\n               sig_ctx_sys());\n  }\n\n  void memberFn(const sig_signal_t sig) {\n\n    // Do somethings...\n\n    std::cout \u003c\u003c \"notification (TestClass): \"\n              \u003c\u003c (const char *)sig.object\n              \u003c\u003c std::endl;\n  }\n\n  void stopObserveNtf1() {\n    sig_detach(CUSTOM_NTF1,\n               sig_slot(this, \u0026TestClass::memberFn));\n  }\n\n  ~TestClass() {\n    sig_detach(this);\n  }\n};\n\n// non-member function\nvoid do_somethings(const sig_signal_t signal) {\n    std::cout \u003c\u003c \"notification (do_somethings): \"\n              \u003c\u003c (const char *)signal.object\n              \u003c\u003c std::endl;\n}\n\nint main() {\n\n  // Observe a signal/event\n  sig_attach(\"signal-1\", do_somethings);\n\n  // Fire signal\n  sig_fire(\"signal-1\", (void *)\"signal-1 object\");\n\n\n  // Test Member functions\n\n  TestClass t1;\n\n  sig_fire(CUSTOM_NTF1, (void *)\"ntf 1 object\");\n  t1.stopObserveNtf1();\n  sig_fire(CUSTOM_NTF1, (void *)\"ntf 1 object\");\n\n  sig_fire(\"custom_ntf2\", (void *)\"ntf 2 object\");\n\n  raise(SIGUSR1);\n\n  return 0;\n}\n```\nOutput:\n```text\nnotification (do_somethings): signal-1 object\nnotification (TestClass): ntf 1 object\nnotification (TestClass): ntf 2 object\nnotification (TestClass): \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frecp%2Flibsig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frecp%2Flibsig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frecp%2Flibsig/lists"}