00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _GADGET_PROXY_FACTORY_H_
00034 #define _GADGET_PROXY_FACTORY_H_
00035
00036
00037 #include <gadget/gadgetConfig.h>
00038 #include <vector>
00039 #include <gadget/Type/Proxy.h>
00040 #include <jccl/Config/ConfigElementPtr.h>
00041 #include <vpr/Util/Singleton.h>
00042 #include <jccl/RTRC/DependencyManager.h>
00043
00044
00045 namespace gadget
00046 {
00047
00054 class ProxyConstructorBase
00055 {
00056 public:
00061 ProxyConstructorBase()
00062 {;}
00063
00064 virtual ~ProxyConstructorBase()
00065 {;}
00066
00071 virtual Proxy* createProxy(jccl::ConfigElementPtr element) const = 0;
00072
00074 virtual std::string getElementType() const = 0;
00075 };
00076
00077
00082 template <class PROXY>
00083 class ProxyConstructor : public ProxyConstructorBase
00084 {
00085 public:
00086 ProxyConstructor();
00087
00092 Proxy* createProxy(jccl::ConfigElementPtr element) const
00093 {
00094 PROXY* new_proxy = new PROXY;
00095 bool success = new_proxy->config(element);
00096
00097
00098 if(success)
00099 {
00100 return new_proxy;
00101 }
00102 else
00103 {
00104
00105 return NULL;
00106 }
00107 }
00108
00109 std::string getElementType() const
00110 {
00111 return PROXY::getElementType();
00112 }
00113 };
00114
00115
00121 class ProxyFactory
00122 {
00123 private:
00125 ProxyFactory() {;}
00126
00131 void loadKnownProxies();
00132
00133 public:
00134 void registerProxy(ProxyConstructorBase* constructor);
00135
00143 bool recognizeProxy(jccl::ConfigElementPtr element);
00144
00153 Proxy* loadProxy(jccl::ConfigElementPtr element);
00154
00155 private:
00156
00162 int findConstructor(jccl::ConfigElementPtr element);
00163
00164 private:
00165 std::vector<ProxyConstructorBase*> mConstructors;
00168 vprSingletonHeaderWithInitFunc(ProxyFactory,loadKnownProxies);
00169 };
00170
00171 }
00172
00173 #endif