The Assimilation Project
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
authlistener.c
Go to the documentation of this file.
1 
23 #include <projectcommon.h>
24 #include <memory.h>
25 #include <glib.h>
26 #include <frame.h>
27 #include <frameset.h>
28 #define IS_LISTENER_SUBCLASS
29 #include <authlistener.h>
36 
38 
43 #define ONESEC 1000000
44 
46 FSTATIC gboolean
48 {
49  AuthListener* aself = CASTTOCLASS(AuthListener, self);
50  AuthListenerAction action;
51 
52  action = g_hash_table_lookup(aself->actionmap, GINT_TO_POINTER((int)fs->fstype));
53 
54  if (NULL == action) {
55  g_warning("%s received FrameSet of unrecognized type %u", __FUNCTION__, fs->fstype);
56  goto returnout;
57  }
59  action(aself, fs, addr);
60 
61 
62 
63 returnout:
64  if (aself->autoack) {
65  DUMP3("_authlistener_got_frameset: AutoACKing FrameSet", &fs->baseclass, NULL);
66  self->transport->_netio->ackmessage(self->transport->_netio, addr, fs);
67  }
68  UNREF(fs);
69  return TRUE;
70 }
71 FSTATIC void
73 {
74  AuthListener* self = CASTTOCLASS(AuthListener, lself);
75  GHashTableIter iter;
76  gpointer key;
77  gpointer value;
78  if (lself->transport) {
79  lself->dissociate(lself);
80  }
81  g_hash_table_iter_init(&iter, self->actionmap);
82  while (g_hash_table_iter_next(&iter, &key, &value)) {
83  guint16 fstype = GPOINTER_TO_INT(key);
84  transport->addListener(transport, fstype, lself);
85  }
86  lself->transport = transport;
87 }
88 FSTATIC void
90 {
91  AuthListener* self = CASTTOCLASS(AuthListener, lself);
92  GHashTableIter iter;
93  gpointer key;
94  gpointer value;
95  if (!lself->transport) {
96  return;
97  }
98  g_hash_table_iter_init(&iter, self->actionmap);
99  while (g_hash_table_iter_next(&iter, &key, &value)) {
100  guint16 fstype = GPOINTER_TO_INT(key);
101  lself->transport->addListener(lself->transport, fstype, NULL);
102  }
103  lself->transport = NULL;
104 }
105 
107 FSTATIC void
109 {
110  AuthListener* self = CASTTOCLASS(AuthListener, aself);
111  self->baseclass.dissociate(&self->baseclass);
112  if (self->actionmap) {
113  g_hash_table_destroy(self->actionmap);
114  self->actionmap = NULL;
115  }
116  _listener_finalize(aself);
117 }
118 
119 
123 authlistener_new(gsize objsize,
126  gboolean autoack)
127 {
128  AuthListener * newlistener;
130  if (objsize < sizeof(AuthListener)) {
131  objsize = sizeof(AuthListener);
132  }
133  newlistener = NEWSUBCLASS(AuthListener, listener_new(config, objsize));
134  if (newlistener != NULL) {
135  GHashTable* hash;
140  hash = g_hash_table_new(NULL, NULL);
141  for (; map->action; ++map) {
142  g_hash_table_insert(hash, GINT_TO_POINTER(map->framesettype), map->action);
143  }
144  newlistener->actionmap = hash;
145  newlistener->autoack = autoack;
146 
147 
148  }
149  return newlistener;
150 }