LightWrap++
AC++wrapperfortheLightWave3DSDK
master_handler.h
Go to the documentation of this file.
1 #ifndef LWPP_MASTER_HANDLER
2 #define LWPP_MASTER_HANDLER
3 
4 #include "lwpp/plugin_handler.h"
5 #include <lwmaster.h>
6 #include <lwpp/lw_server.h>
7 
8 namespace lwpp
9 {
11  class MasterHandler : public InstanceHandler, public ItemHandler
12  {
13  public:
14  MasterHandler(void *g, void *context, LWError *err) : InstanceHandler(g, context, err, LWMASTER_HCLASS)
15  {
16  ;
17  }
18  virtual ~MasterHandler()
19  {
20  ;
21  }
22  virtual double Event (const LWMasterAccess *ma) {UNUSED(ma);return 0.0;}
23  virtual unsigned int Flags() {return 0;}
24  };
25 
27 
30 template <class T, int maxVersion, int minVersion, int plugType, bool noIO = false>
31 class MasterAdaptor : public InstanceAdaptor <T>, public ItemAdaptor <T>
32 {
33  public:
34  MasterAdaptor(const char *name, ServerTagInfo *tags)
35  {
36  LWServer::AddPlugin(LWMASTER_HCLASS, name, Activate, tags);
37  }
39  static int Activate (int version, GlobalFunc *global, LWInstance inst, void *serverData)
40  {
41  if ( version > maxVersion ) return AFUNC_BADVERSION;
42  if ( version < minVersion ) return AFUNC_BADVERSION;
43  try
44  {
45  UNUSED(serverData);
46  lwpp::SetSuperGlobal(global);
47 
48  LWMasterHandler *plugin = static_cast<LWMasterHandler *>(inst);
49 
50  InstanceAdaptor<T>::Activate(plugin->inst);
51  if (noIO) // cause "warning C4127: conditional expression is constant" but is fine...
52  {
53  plugin->inst->load = 0;
54  plugin->inst->save = 0;
55  }
56  ItemAdaptor<T>::Activate(plugin->item);
57  plugin->type = plugType;
58  plugin->event = Event;
59  plugin->flags = Flags;
60  return AFUNC_OK;
61  }
62  catch (std::exception &e)
63  {
64  lwpp::LWMessage::Error("An exception occured in MasterAdaptor::Activate():", e.what());
65  return AFUNC_BADAPP;
66  }
67  }
68  private:
69 
70  static double Event (LWInstance instance, const LWMasterAccess *ma)
71  {
72  try
73  {
74  T *plugin = (T *) instance;
75  return plugin->Event(ma);
76  }
77  catch (std::exception &e)
78  {
79  lwpp::LWMessage::Error("An exception occured in MasterAdaptor::Event():", e.what());
80  return 0.0;
81  }
82  }
83 
84  static unsigned int Flags (LWInstance instance)
85  {
86  try
87  {
88  T *plugin = (T *) instance;
89  return plugin->Flags();
90  }
91  catch (std::exception &e)
92  {
93  lwpp::LWMessage::Error("An exception occured in MasterAdaptor::Flags():", e.what());
94  return 0;
95  }
96  }
97 };
98 
102 
105 
107  template <class T, int maxVersion, int minVersion, int plugType>
108  class XPanelMasterAdaptor : public MasterAdaptor<T, maxVersion, minVersion, plugType>, public XPanelAdaptor<T>
109  {
110  public:
111  XPanelMasterAdaptor(const char *name, ServerTagInfo *tags = 0)
112  : XPanelAdaptor<T>(name, LWMASTER_ICLASS, tags),
113  MasterAdaptor<T, maxVersion, minVersion, plugType>(name, tags)
114  {
115  ;
116  }
117  };
118 
120  template <class T, int maxVersion, int minVersion, int plugType>
121  class LWPanelMasterAdaptor : public MasterAdaptor<T, maxVersion, minVersion, plugType>, public LWPanelAdaptor<T>
122  {
123  public:
124  LWPanelMasterAdaptor(const char *name, ServerTagInfo *tags = 0)
125  : LWPanelAdaptor<T>(name, LWMASTER_ICLASS, tags),
126  MasterAdaptor<T, maxVersion, minVersion, plugType>(name, tags)
127  {
128  ;
129  }
130  };
131 
132 } // namespace lwpp
133 #endif // LWPP_MASTER_HANDLER