AppNearMe µNFC stack for the NXP PN532 chip License: You can use the stack free of charge to prototype with mbed; if you want to use the stack with your commercial product, get in touch!

Dependents:   IOT_sensor_nfc AppNearMe_MuNFC_PN532_Test p2p_nfc_test NFCMoodLamp ... more

License

You can use the stack free of charge to prototype with mbed; if you want to use the stack with your commercial product, get in touch!

Revision:
0:480387549d89
Child:
3:0b949b2d3b55
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PN532/EventCallback.h	Thu Jul 26 09:12:27 2012 +0000
@@ -0,0 +1,63 @@
+/*
+	EventCallback.h 
+	Copyright (c) Donatien Garnier 2012
+	donatien.garnier@appnearme.com
+	http://www.appnearme.com/
+*/
+
+
+#ifndef EVENTCALLBACK_H_
+#define EVENTCALLBACK_H_
+
+#include "NFCEvent.h"
+
+#include "munfc/core/fwk.h"
+#include "munfc/target/event.h"
+
+class EventCallback
+{
+protected:
+  EventCallback();
+
+  void init( void (*fn)(target_event_callback, void*) ); //Callable by MuNFC
+
+  void attach(void (*fn)(NFCEvent, void*), void* arg);
+
+  template <class T>
+  void attach(T* inst, void (T::*member)(NFCEvent))
+  {
+    m_fn = NULL;
+    m_inst = inst;
+    m_member = member;
+    m_caller = &EventCallback::memberCaller<T>;
+  }
+
+
+private:
+  void callback(target_event event);
+
+  //Function
+  void(*m_fn)(NFCEvent, void*);
+  void* m_arg;
+
+  //Member of object instance
+  void* m_inst;
+  void* m_member;
+  void* (*m_caller)(NFCEvent);
+
+  template <class T>
+  static inline void memberCaller(NFCEvent event)
+  {
+    T* inst = (T*) m_inst;
+    void (T::*member)(NFCEvent) = m_member;
+    inst->member(event);
+  }
+
+  static void staticCallback(target_event event, void* param);
+
+  friend class MuNFC;
+};
+
+
+
+#endif /* EVENTCALLBACK_H_ */