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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EventCallback.cpp Source File

EventCallback.cpp

00001 /*
00002     EventCallback.cpp 
00003     Copyright (c) Donatien Garnier 2012
00004     donatien.garnier@appnearme.com
00005     http://www.appnearme.com/
00006 */
00007 
00008 #include "EventCallback.h"
00009 
00010 EventCallback::EventCallback()
00011 {
00012 
00013 }
00014 
00015 void EventCallback::init(void (*fn)(transaction_event_callback, void*))
00016 {
00017   fn(staticCallback, this);
00018 }
00019 
00020 void EventCallback::attach(void (*fn)(NFCEvent, void*), void* arg)
00021 {
00022   m_inst = NULL;
00023   m_fn = fn;
00024   m_arg = arg;
00025 }
00026 
00027 void EventCallback::callback(transaction_event event, transaction_type type)
00028 {
00029   if(m_inst)
00030   {
00031     m_caller(this, (NFCEvent)event); //At some point, should not cast event directly
00032   }
00033   else if(m_fn)
00034   {
00035     m_fn((NFCEvent)event, m_arg);
00036   }
00037 }
00038 
00039 /*static*/ void EventCallback::staticCallback(transaction_event event, transaction_type type, void* param)
00040 {
00041   ((EventCallback*)(param))->callback(event, type);
00042 }
00043 
00044 
00045 
00046 
00047