libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo es el conjunto de objetos y funciones, que permiten ejecutar las operaciones básicas de la plataforma Moldeo, y que compone su núcleo.
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Amigas 'defines' Grupos Páginas
moPrePlugin.cpp
Ir a la documentación de este archivo.
1 /*******************************************************************************
2 
3  moPrePlugin.cpp
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28 
29 
30 *******************************************************************************/
31 
32 #include "moPrePlugin.h"
33 
34 #include "moArray.h"
35 moDefineDynamicArray( moPrePluginsArray )
36 
37 
39 }
40 
41 
42 //===========================================
43 //
44 // moPrePlugin
45 //
46 //===========================================
47 
48 void moPrePlugin::Load(moText plugin_file)
49 {
50 
51  name = plugin_file;
52  handle = moLoadPlugin(plugin_file);
53 
54  if(!handle) {
55  #ifndef MO_WIN32
56  moDebugManager::Error( "moPrePlugin::Load > Cannot open library: " + moText(dlerror()) );
57  #else
58  CHAR szBuf[80];
59  DWORD dw = GetLastError();
60  sprintf(szBuf, "%s failed: GetLastError returned %u\n",
61  (char*)plugin_file, (int)dw);
62  moDebugManager::Error( "moPrePlugin::Load > Cannot open library: " + moText(szBuf) );
63  #endif
64  return;
65  }
66 
67  #ifdef MO_WIN32
68  FARPROC farp;
69  farp = GetProcAddress(handle, "DestroyPreEffectFactory");
70  CreatePreEffectFactory = CreatePreEffectFactoryFunction(GetProcAddress(handle, "CreatePreEffectFactory"));
71  DestroyPreEffectFactory = DestroyPreEffectFactoryFunction(GetProcAddress(handle, "DestroyPreEffectFactory"));
72  #else
73  CreatePreEffectFactory = CreatePreEffectFactoryFunction(dlsym(handle, "CreatePreEffectFactory"));
74  DestroyPreEffectFactory = DestroyPreEffectFactoryFunction(dlsym(handle, "DestroyPreEffectFactory"));
75  #endif
76 
77  if(this->CreatePreEffectFactory!=NULL)
79 
80 }
81 
83 {
85 
88 
89  moUnloadPlugin(handle);
90 }
91 
92 
94 
95  moPreEffect **narray;
96 
97  if(m_factory!=NULL) {
98  moPreEffect *pfx = m_factory->Create();
99 
100  if(pfx==NULL) return NULL;
101 
102  if(n==0) {//primera vez
103  array = new moPreEffect* [1];
104  } else if(n>0) {//array dinamico
105  narray = new moPreEffect* [n+1];//generamos el nuevo vacio
106  for(int i=0;i<n;i++) narray[i] = array[i];//copiamos el array
107  delete [] array;
108  array = narray;
109  }
110 
111  array[n] = pfx;
112  n++;
113  return pfx;
114  }
115  return NULL;
116 }
117 
119 
120  moPreEffect **narray;
121  int i,j;
122 
123  if(m_factory!=NULL) {
124 
125  for(j=0;j<n;j++)
126  if(array[j]==preeffect) {
127 
129  m_factory->Destroy(preeffect);
130 
131  if(n==1) {//muere
132  delete [] array;
133  } else if(n>1) {//array dinamico
134  narray = new moPreEffect* [n-1];//generamos el nuevo vacio
135  for(i=0;i<j;i++) narray[i] = array[i];//copiamos el array hasta el j(destruido)
136  for(i=j;i<(n-1);i++) narray[i] = array[i+1];//copiamos el array desde el j
137  delete [] array;
138  array = narray;
139  }
140  n--;
141 
142  return true;
143  }
144  }
145  return false;
146 }
147 
148 
149 LIBMOLDEO_API moPreEffect* moNewPreEffect(moText effect_name, moPrePluginsArray &plugins)
150 {
151  // Creando el nombre complete del plugin(incluyendo ruta por defecto)
152  // a partir del nombre del efecto.
153  moText complete_name;
154 
155  if(!stricmp(effect_name, "nil")) return NULL;
156 
157  #if defined(_WIN32)
158  complete_name = moText(moDataManager::GetModulesDir()+ "/preeffects/") + (moText)effect_name;
159  #ifdef _DEBUG
160  complete_name+= moText("_d");
161  #endif
162  complete_name += moText(".dll");
163  #else
164  complete_name = moText(moDataManager::GetModulesDir()+ "/preeffects/libmoldeo_") + (moText)effect_name;
165  #ifdef _DEBUG
166  complete_name+= moText("_d");
167  #endif
168  complete_name += moPluginExtension;
169  #endif
170 
171  // Indice del plugin que se utilizara para crear a este efecto.
172  int plg_index = -1;
173 
174  // First, revisa que el plugin ya no haya sido cargado antes.
175  for(MOuint i = 0; i < plugins.Count(); i++)
176  if(!stricmp(plugins[i]->GetName(), complete_name))
177  {
178  plg_index = i;
179  break;
180  }
181 
182  if(plg_index == -1)
183  {
184  // Es la primera vez que se intenta cargar este plugin. Se lo agrega al array.
185  // Falta control de errores(que pasa si la libreria no carga, etc?) :-)
186  plg_index = plugins.Count();
187  moPrePlugin *pplugin = new moPrePlugin(complete_name);
188  plugins.Add( pplugin );
189  }
190 
191  // El plugin crea al efecto!
192  if(plugins[plg_index]->m_factory!=NULL)
193  return plugins[plg_index]->Create();
194  else return NULL;
195 }
196 
197 
198 LIBMOLDEO_API bool moDeletePreEffect(moPreEffect *preeffect, moPrePluginsArray &plugins)
199 {
200  // Creando el nombre complete del plugin(incluyendo ruta por defecto)
201  // a partir del nombre del efecto.
202  moText complete_name;
203 
204  if(!stricmp(preeffect->GetName(), "")) return false;
205 
206  #if defined(_WIN32)
207  complete_name = moText(moDataManager::GetModulesDir()+ "/preeffects/") + moText(preeffect->GetName());
208  #ifdef _DEBUG
209  complete_name+= moText("_d");
210  #endif
211  complete_name += moText(".dll");
212  #else
213  complete_name = moText(moDataManager::GetModulesDir()+ "/preeffects/libmoldeo_") + moText(preeffect->GetName());
214  #ifdef _DEBUG
215  complete_name+= moText("_d");
216  #endif
217  complete_name += moPluginExtension;
218  #endif
219 
220  // Indice del plugin que se utilizara para crear a este efecto.
221  int plg_index = -1;
222 
223  // First, revisa que el plugin ya no haya sido cargado antes.
224  for(MOuint i = 0; i < plugins.Count(); i++)
225  if(!stricmp(plugins[i]->GetName(), complete_name))
226  {
227  plg_index = i;
228  break;
229  }
230 
231  if(plg_index == -1)
232  {
233  return false;
234  }
235 
236  bool res = plugins[plg_index]->Destroy(preeffect);
237 
239  if (res && plugins[plg_index]->n == 0) {
240  plugins[plg_index]->Unload();
241  plugins.Remove(plg_index);
242 
243  }
244 
245  return res;
246 }
247 
248 
void Load(moText plugin_file)
Definition: moPrePlugin.cpp:48
virtual moPreEffect * Create(void)=0
void(MO_PLG_ENTRY * DestroyPreEffectFactoryFunction)()
Definition: moPrePlugin.h:48
CreatePreEffectFactoryFunction CreatePreEffectFactory
Definition: moPrePlugin.h:56
static void Error(moText p_text)
Anuncia un error.
const moText & GetName() const
clase base para definir Pre-Efectos.
Definition: moPreEffect.h:59
#define LIBMOLDEO_API
Definition: moTypes.h:180
moPreEffectFactory *(MO_PLG_ENTRY * CreatePreEffectFactoryFunction)()
Definition: moPrePlugin.h:47
LIBMOLDEO_API moPreEffect * moNewPreEffect(moText effect_name, moPrePluginsArray &plugins)
clase de para manejar textos
Definition: moText.h:75
moTypes MOint moText moParamIndex moParamReference int iRow int int i int i
Definition: all_f.js:18
void moUnloadPlugin(MOpluginHandle &handle)
Definition: moBasePlugin.h:64
moText0 moText
Definition: moText.h:291
static const moText & GetModulesDir()
moPreEffectFactory * m_factory
Definition: moPrePlugin.h:59
bool Destroy(moPreEffect *preeffect)
moPreEffect ** array
Definition: moPrePlugin.h:53
void Unload()
Definition: moPrePlugin.cpp:82
moPreEffect * Create()
Definition: moPrePlugin.cpp:93
virtual void Destroy(moPreEffect *fx)=0
#define MOuint
Definition: moTypes.h:387
moDefineDynamicArray(moPrePluginsArray) moPreEffectFactory
Definition: moPrePlugin.cpp:35
LIBMOLDEO_API bool moDeletePreEffect(moPreEffect *preeffect, moPrePluginsArray &plugins)
MOpluginHandle moLoadPlugin(moText fn)
Definition: moBasePlugin.h:55
DestroyPreEffectFactoryFunction DestroyPreEffectFactory
Definition: moPrePlugin.h:57