TEMU  4.4
The Terma Emulator
Notifications.h
Go to the documentation of this file.
1 //===-- temu-c/Notifications.h - Untimed Event API --------------*- C++ -*-===//
2 //
3 // TEMU: The Terma Emulator
4 // (c) Terma 2015
5 // Authors: Mattias Holm <maho (at) terma.com>
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef TEMU_NOTIFICATIONS_H
10 #define TEMU_NOTIFICATIONS_H
11 
12 #include <stdint.h>
13 #include "temu-c/Support/Attributes.h"
14 #include "temu-c/Support/Objsys.h"
15 
16 // The following interfaces are for non-timed events (or
17 // notifications). Notification 0 is reserved as a special
18 // no-notification handler connected id. Notifications have a name and
19 // are associated with an object. The subscriber can request a
20 // notification with a null object (i.e. will accept all identical
21 // notifications, or a given object, which means the notification
22 // handler will be called only for some objects. There is currently
23 // no way to depublish a notification, but the standard approach is to
24 // set the notification id to 0.
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 typedef void (*temu_NotificationHandler)(void *Arg, temu_Object_ *Source, void *NotInfo);
30 
31 /*! Publish a notification source
32  * A notification source is identified by an event name and an object pointer
33  * \param NotName Name of the notification
34  * \param Obj Pointer to the object
35  * \result Notification ID of the published event.
36  */
37 TEMU_API int64_t temu_publishNotification(const char *NotName, temu_Object_ *Obj);
38 
39 /*! Install notification functions for the given event generated by source
40  *
41  * \param NotName Name of the notification
42  * \param Source If source is NULL, the event subscriber will be
43  * notified by all the sources for the given name.
44  * \param Arg Context argument to be passed to the callback notification function
45  * \param NotFunc The callback function on notification
46  */
49 
50 /*! Remove notification handler for the given name and source.
51  * Note that this function runs in O(N) time. It is not meant for
52  * being used in performance critical code.
53  * \param NotName Name of the notification
54  * \param Source If source is NULL, the event subscriber will be
55  * notified by all the sources for the given name.
56  * \param NotFunc The callback function to be called on notification
57  */
60 
61 /*! Remove notification handler for the given name, source and arg.
62  * Note that this function runs in O(N) time. It is not meant for
63  * being used in performance critical code.
64  * \param NotName Name of the notification
65  * \param Source If source is NULL, the event subscriber will be
66  * notified by all the sources for the given name.
67  * \param NotFunc The callback function to be called on notification
68  * \param Arg Context argument to be passed to the callback notification function
69  * \result zero on success, otherwise non-zero
70  */
73  void *Arg);
74 
75 
76 /*! Call event subscriber, EvInfo is a per event specific struct
77  * the event handler must cast this to the appropriate type.
78  * \param Id Notification ID
79  * \param NotInfo Ponter to pass to notification handlers
80  */
82 
83 /*! Quick inline call macro that do not call the function for an invalid
84  * event id. This saves the function call to the notify
85  * function, minimising the cost for unset event handlers.
86  * \param Id Notification ID
87  * \param NotInfo Pointer to pass to notification handlers
88  */
89 static inline void
90 temu_notifyFast(int64_t *Id, void *NotInfo)
91 {
92  if (*Id) {
93  temu_notify(*Id, NotInfo);
94  }
95 }
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif /* ! TEMU_EVENTS_H */
temu_subscribeNotification
TEMU_API int temu_subscribeNotification(const char *NotName, temu_Object_ *Source, void *Arg, temu_NotificationHandler NotFunc)
temu_notify
TEMU_API void temu_notify(int64_t Id, void *NotInfo)
temu_unsubscribeNotification
TEMU_API int temu_unsubscribeNotification(const char *NotName, temu_Object_ *Source, temu_NotificationHandler NotFunc)
temu_NotificationHandler
void(* temu_NotificationHandler)(void *Arg, temu_Object_ *Source, void *NotInfo)
Definition: Notifications.h:29
temu_unsubscribeNotificationArg
TEMU_API int temu_unsubscribeNotificationArg(const char *NotName, temu_Object_ *Source, temu_NotificationHandler NotFunc, void *Arg)