The Assimilation Project
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
listener.c
Go to the documentation of this file.
1 
22 #include <projectcommon.h>
23 #include <memory.h>
24 #include <glib.h>
25 #include <frame.h>
26 #include <frameset.h>
27 #include <listener.h>
30 void _listener_finalize(AssimObj * self);
32 FSTATIC void _listener_associate(Listener* self, NetGSource* source);
34 
39 #define ONESEC 1000000
40 
42 FSTATIC gboolean
44 {
45  (void)self;
46  UNREF(fs);
47  (void)addr;
48  return TRUE;
49 }
50 
52 void
54 {
55  Listener* self = CASTTOCLASS(Listener, aself);
56  UNREF(self->config);
57  self->dissociate(self);
58  memset(self, 0x00, sizeof(*self));
59  FREECLASSOBJ(self);
60 }
61 
63 FSTATIC void
65 {
66  // We kinda have to just hope that 'source' lives as long as we do...
67  self->transport = source;
68 }
69 
71 FSTATIC void
73 {
74  self->transport = NULL;
75 }
76 
77 
78 
81 Listener*
83  gsize objsize)
84 {
85  Listener * newlistener;
86  if (objsize < sizeof(Listener)) {
87  objsize = sizeof(Listener);
88  }
89  newlistener = NEWSUBCLASS(Listener, assimobj_new(objsize));
90  if (newlistener != NULL) {
91  newlistener->baseclass._finalize = _listener_finalize;
92  newlistener->got_frameset = _listener_got_frameset;
93  newlistener->associate = _listener_associate;
94  newlistener->dissociate = _listener_dissociate;
95  newlistener->config = config;
96  REF(config);
97  }
98  return newlistener;
99 }
FSTATIC void _listener_associate(Listener *self, NetGSource *source)
Associate the given NetGSource with this Listener class..
Definition: listener.c:64
Listener * listener_new(ConfigContext *config, gsize objsize)
Construct a new Listener - setting up GSource and timeout data structures for it. ...
Definition: listener.c:82
Defines Generic Listener interfaces.
Implements minimal client-oriented Frame and Frameset capabilities.
#define FSTATIC
Definition: projectcommon.h:31
#define FREECLASSOBJ(obj)
Free a C-class object.
Definition: proj_classes.h:76
FSTATIC void _listener_dissociate(Listener *self)
Associate the current NetGSource from this Listener class..
Definition: listener.c:72
FSTATIC gboolean _listener_got_frameset(Listener *self, FrameSet *, NetAddr *)
(not very useful) Function called when a Frame class arrived from the given NetAddr class ...
Definition: listener.c:43
#define REF(obj)
Definition: assimobj.h:39
Implements basic Frame class.
Project common header file.
AssimObj * assimobj_new(guint objsize)
Definition: assimobj.c:74
ConfigContext * config
Definition: listener.h:43
void(* _finalize)(AssimObj *)
Free object (private)
Definition: assimobj.h:55
The NetAddr class class represents a general network address - whether IP, MAC, or any other type of ...
Definition: netaddr.h:43
gboolean(* got_frameset)(Listener *self, FrameSet *fs, NetAddr *na)
called when a FrameSet arrives
Definition: listener.h:45
struct _Listener Listener
Definition: listener.h:33
FrameSet class - used for collecting Frames when not on the wire, and for marshalling/demarshalling t...
Definition: frameset.h:46
void(* dissociate)(Listener *self)
Dissociate us from our source.
Definition: listener.h:51
AssimObj baseclass
Definition: listener.h:42
void(* associate)(Listener *self, NetGSource *source)
NetGSource class to associate with
Definition: listener.h:49
#define CASTTOCLASS(Cclass, obj)
Safely cast 'obj' to C-class 'class' - verifying that it was registerd as being of type class ...
Definition: proj_classes.h:66
#define UNREF(obj)
Definition: assimobj.h:35
The NetGSource class objects integrate NetIO class objects into the g_main_loop paradigm.
Definition: netgsource.h:43
#define NEWSUBCLASS(Cclass, obj)
Definition: proj_classes.h:67
This is the Listener class. object - which generically listens for packets.
Definition: listener.h:41
void _listener_finalize(AssimObj *self)
Finalize a Listener.
Definition: listener.c:53