Commit de00ad47ad4cf93c472394c8fb309ddee8638a49

Authored by Georg Hopp
1 parent b122f341

add subject/observer interface

  1 +#ifndef __OBSERVER_H__
  2 +#define __OBSERVER_H__
  3 +
  4 +typedef void (* fptr_observerNotify)(void *, void*);
  5 +
  6 +extern const struct interface i_Observer;
  7 +
  8 +struct i_Observer {
  9 + const struct interface * const _;
  10 + fptr_observerNotify notify;
  11 +};
  12 +
  13 +extern void observerNotify(void *, void *);
  14 +
  15 +#endif // __OBSERVER_H__
  16 +
  17 +// vim: set ts=4 sw=4:
  1 +#ifndef __SUBJECT_H__
  2 +#define __SUBJECT_H__
  3 +
  4 +typedef void (* fptr_subjectAttach)(void *, void *);
  5 +typedef void (* fptr_subjectDetach)(void *, void *);
  6 +typedef void (* fptr_subjectNotify)(void *);
  7 +
  8 +extern const struct interface i_Subject;
  9 +
  10 +struct i_Subject {
  11 + const struct interface * const _;
  12 + fptr_subjectAttach attach;
  13 + fptr_subjectDetach detach;
  14 + fptr_subjectNotify notify;
  15 +};
  16 +
  17 +extern void subjectAttach(void *, void *);
  18 +extern void subjectDetach(void *, void *);
  19 +extern void subjectNotify(void *);
  20 +
  21 +#endif // __SUBJECT_H__
  22 +
  23 +// vim: set ts=4 sw=4:
@@ -2,7 +2,8 @@ ACLOCAL_AMFLAGS = -I m4 @@ -2,7 +2,8 @@ ACLOCAL_AMFLAGS = -I m4
2 AUTOMAKE_OPTIONS = subdir-objects 2 AUTOMAKE_OPTIONS = subdir-objects
3 3
4 IFACE = interface/class.c interface/stream_reader.c interface/logger.c \ 4 IFACE = interface/class.c interface/stream_reader.c interface/logger.c \
5 - interface/stream_writer.c interface/http_intro.c 5 + interface/stream_writer.c interface/http_intro.c \
  6 + interface/subject.c interface/observer.c
6 CLASS = class.c interface.c 7 CLASS = class.c interface.c
7 SOCKET = socket.c socket/accept.c socket/connect.c socket/listen.c 8 SOCKET = socket.c socket/accept.c socket/connect.c socket/listen.c
8 SERVER = server.c server/run.c server/close_conn.c 9 SERVER = server.c server/run.c server/close_conn.c
  1 +#include "class.h"
  2 +#include "interface/observer.h"
  3 +
  4 +const struct interface i_Observer = {
  5 + "observer",
  6 + 1
  7 +};
  8 +
  9 +void
  10 +observerNotify(void * observer, void * subject)
  11 +{
  12 + CALL(observer, Observer, notify, subject);
  13 +}
  14 +
  15 +// vim: set ts=4 sw=4:
  1 +#include "class.h"
  2 +#include "interface/subject.h"
  3 +
  4 +const struct interface i_Subject = {
  5 + "subject",
  6 + 3
  7 +};
  8 +
  9 +void
  10 +subjectAttach(void * subject, void * observer)
  11 +{
  12 + CALL(subject, Subject, attach, observer);
  13 +}
  14 +
  15 +void
  16 +subjectDetach(void * subject, void * observer)
  17 +{
  18 + CALL(subject, Subject, detach, observer);
  19 +}
  20 +
  21 +void
  22 +subjectNotify(void * subject)
  23 +{
  24 + CALL(subject, Subject, notify);
  25 +}
  26 +
  27 +// vim: set ts=4 sw=4:
Please register or login to post a comment