libtrbase  1.0.2
Web server and task management solution.
subject.h
Go to the documentation of this file.
1 /**
2  * \file
3  * Definition of the subject pattern implementation.
4  *
5  * \author Georg Hopp
6  *
7  * \copyright
8  * Copyright © 2014 Georg Hopp
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 #ifndef __SUBJECT_H__
24 #define __SUBJECT_H__
25 
26 #include "tr/interface.h"
27 
28 
29 typedef void (* fptr_subjectAttach)(void *, void *);
30 typedef void (* fptr_subjectDetach)(void *, void *);
31 typedef void (* fptr_subjectNotify)(void *);
32 
33 TR_INTERFACE(TR_Subject) {
34  TR_IFID;
35  fptr_subjectAttach attach;
36  fptr_subjectDetach detach;
37  fptr_subjectNotify notify;
38 };
39 
40 /**
41  * Attach an observer to a subject. After a successfull
42  * call to this the subject will inform the observer about events.
43  */
44 inline
45 void
46 TR_subjectAttach(void * subject, void * observer)
47 {
48  TR_CALL(subject, TR_Subject, attach, observer);
49 }
50 
51 /**
52  * Detach an Observer from a Subject. After this no events
53  * will be propagated from the subject to the observer anymore.
54  */
55 inline
56 void
57 TR_subjectDetach(void * subject, void * observer)
58 {
59  TR_CALL(subject, TR_Subject, detach, observer);
60 }
61 
62 /**
63  * Trigger the a notification of all attached observers.
64  */
65 inline
66 void
67 TR_subjectNotify(void * subject)
68 {
69  TR_CALL(subject, TR_Subject, notify);
70 }
71 
72 #endif // __SUBJECT_H__
73 
74 // vim: set ts=4 sw=4:
void TR_subjectNotify(void *subject)
Definition: subject.h:67
#define TR_CALL(object, _iface, method,...)
Definition: class.h:256
void TR_subjectDetach(void *subject, void *observer)
Definition: subject.h:57
#define TR_IFID
Definition: interface.h:61
void TR_subjectAttach(void *subject, void *observer)
Definition: subject.h:46
TR_INTERFACE(TR_Subject)
Definition: subject.h:33
void(* fptr_subjectAttach)(void *, void *)
Definition: subject.h:29
void(* fptr_subjectDetach)(void *, void *)
Definition: subject.h:30
void(* fptr_subjectNotify)(void *)
Definition: subject.h:31