ACKme Logo WiConnect Host Library- API Reference Guide
 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
LogFunc.h
1 
29 #pragma once
30 
31 #include "api/WiconnectTypes.h"
32 #include "FunctionPointer.h"
33 
34 namespace wiconnect
35 {
36 
37 typedef int (*_LogFunc)(const char *str);
38 
39 
45 class LogFunc : public FunctionPointer
46 {
47 public:
48  /*************************************************************************************************/
49  LogFunc(_LogFunc func = 0)
50  {
51  _function = (void*)func;
52  _membercaller = NULL;
53  _object = NULL;
54  }
55 
56  /*************************************************************************************************/
57  template<typename T>
58  LogFunc(T *object, WiconnectResult (T::*member)(const char *str))
59  {
60  _object = static_cast<void*>(object);
61  memcpy(_member, (char*)&member, sizeof(member));
62  _membercaller = (void*)&LogFunc::membercaller<T>;
63  _function = 0;
64  }
65 
66  /*************************************************************************************************/
67  int call(const char *str)
68  {
69  if (_function)
70  {
71  return ((_LogFunc)_function)(str);
72  }
73  else if (_object)
74  {
75  typedef int (*membercallerFunc)(void*, char*, const char *str);
76  return ((membercallerFunc)_membercaller)(_object, _member, str);
77  }
78  else
79  {
80  return -1;
81  }
82  }
83 
84 private:
85 
86  /*************************************************************************************************/
87  template<typename T>
88  static int membercaller(void *object, char *member, const char *str)
89  {
90  T* o = static_cast<T*>(object);
91  int (T::*m)(const char *str);
92  memcpy((char*)&m, member, sizeof(m));
93  return (o->*m)(str);
94  }
95 };
96 
97 
98 
99 
100 }
WiconnectResult
API Result code.
Logging callback function.
Definition: LogFunc.h:45
Generic function pointer.