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
moPostPlugin.cpp
Ir a la documentación de este archivo.
1 /*******************************************************************************
2 
3  moPostPlugin.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  Andr� Colubri
29 
30 *******************************************************************************/
31 
32 #include "moPostPlugin.h"
33 
34 #include "moArray.h"
35 moDefineDynamicArray( moPostPluginsArray )
36 
38 }
39 
40 
41 //===========================================
42 //
43 // moPostPlugin
44 //
45 //===========================================
46 
47 void moPostPlugin::Load(moText plugin_file)
48 {
49  name = plugin_file;
50  handle = moLoadPlugin(plugin_file);
51 
52  if(!handle) {
53  #ifndef MO_WIN32
54  moDebugManager::Error( "moPostPlugin::Load > Cannot open library: " + moText(dlerror()) );
55  #else
56  CHAR szBuf[80];
57  DWORD dw = GetLastError();
58  sprintf(szBuf, "%s failed: GetLastError returned %i\n",
59  (char*)plugin_file, (int)dw);
60  moDebugManager::Error( "moPostPlugin::Load > Cannot open library: " + moText(szBuf) );
61  #endif
62  return;
63  }
64 
65  #ifdef MO_WIN32
66  FARPROC farp;
67  farp = GetProcAddress(handle, "DestroyPostEffectFactory");
68  CreatePostEffectFactory = CreatePostEffectFactoryFunction(GetProcAddress(handle, "CreatePostEffectFactory"));
69  DestroyPostEffectFactory = DestroyPostEffectFactoryFunction(GetProcAddress(handle, "DestroyPostEffectFactory"));
70  #else
71  CreatePostEffectFactory = CreatePostEffectFactoryFunction(dlsym(handle, "CreatePostEffectFactory"));
72  DestroyPostEffectFactory = DestroyPostEffectFactoryFunction(dlsym(handle, "DestroyPostEffectFactory"));
73  #endif
74 
75  if(this->CreatePostEffectFactory!=NULL)
77 
78 }
79 
81 {
83 
86 
87  moUnloadPlugin(handle);
88 }
89 
90 
92 
93  moPostEffect **narray;
94 
95  if(m_factory!=NULL) {
96  moPostEffect *pfx = m_factory->Create();
97 
98  if(pfx==NULL) return NULL;
99 
100  if(n==0) {//primera vez
101  array = new moPostEffect* [1];
102  } else if(n>0) {//array dinamico
103  narray = new moPostEffect* [n+1];//generamos el nuevo vacio
104  for(int i=0;i<n;i++) narray[i] = array[i];//copiamos el array
105  delete [] array;
106  array = narray;
107  }
108 
109  array[n] = pfx;
110  n++;
111  return pfx;
112  }
113  return NULL;
114 }
115 
117 
118  moPostEffect **narray;
119  int i,j;
120 
121  if(m_factory!=NULL) {
122 
123  for(j=0;j<n;j++)
124  if(array[j]==PostEfecto) {
125 
126  m_factory->Destroy(PostEfecto);
127 
128  if(n==1) {//muere
129  delete [] array;
130  } else if(n>1) {//array dinamico
131  narray = new moPostEffect* [n-1];//generamos el nuevo vacio
132  for(i=0;i<j;i++) narray[i] = array[i];//copiamos el array hasta el j(destruido)
133  for(i=j;i<(n-1);i++) narray[i] = array[i+1];//copiamos el array desde el j
134  delete [] array;
135  array = narray;
136  }
137  n--;
138  return true;
139  }
140 
141  }
142  return false;
143 }
144 
145 
146 LIBMOLDEO_API moPostEffect* moNewPostEffect(moText effect_name, moPostPluginsArray &plugins)
147 {
148  // Creando el nombre complete del plugin(incluyendo ruta por defecto)
149  // a partir del nombre del efecto.
150  moText complete_name;
151 
152  if(!stricmp(effect_name, "nil")) return NULL;
153 
154  #if defined(_WIN32)
155  complete_name = moText(moDataManager::GetModulesDir()+ "/posteffects/") + (moText)effect_name;
156  #ifdef _DEBUG
157  complete_name+= moText("_d");
158  #endif
159  complete_name += moText(".dll");
160  #else
161  complete_name = moText(moDataManager::GetModulesDir()+ "/posteffects/libmoldeo_") + (moText)effect_name;
162  #ifdef _DEBUG
163  complete_name+= moText("_d");
164  #endif
165  complete_name += moPluginExtension;
166  #endif
167  //printf("completename:%s\n",complete_name);
168 
169  // Indice del plugin que se utilizara para crear a este efecto.
170  int plg_index = -1;
171 
172  // First, revisa que el plugin ya no haya sido cargado antes.
173  for(MOuint i = 0; i < plugins.Count(); i++)
174  if(!stricmp(plugins[i]->GetName(), complete_name))
175  {
176  plg_index = i;
177  break;
178  }
179 
180  if(plg_index == -1)
181  {
182  // Es la primera vez que se intenta cargar este plugin. Se lo agrega al array.
183  // Falta control de errores(que pasa si la libreria no carga, etc?) :-)
184  plg_index = plugins.Count();
185  moPostPlugin *pplugin = new moPostPlugin(complete_name);
186  plugins.Add( pplugin );
187  }
188 
189  // El plugin crea al efecto!
190  if(plugins[plg_index]->m_factory!=NULL)
191  return plugins[plg_index]->Create();
192  else return NULL;
193 }
194 
195 
196 LIBMOLDEO_API bool moDeletePostEffect(moPostEffect *posteffect, moPostPluginsArray &plugins)
197 {
198  // Creando el nombre complete del plugin(incluyendo ruta por defecto)
199  // a partir del nombre del efecto.
200  moText complete_name;
201 
202  if(!stricmp(posteffect->GetName(), "")) return false;
203 
204  #if defined(_WIN32)
205  complete_name = moText(moDataManager::GetModulesDir()+ "/posteffects/") + moText(posteffect->GetName());
206  #ifdef _DEBUG
207  complete_name+= moText("_d");
208  #endif
209  complete_name += moText(".dll");
210  #else
211  complete_name = moText(moDataManager::GetModulesDir()+ "/posteffects/libmoldeo_") + moText(posteffect->GetName());
212  #ifdef _DEBUG
213  complete_name+= moText("_d");
214  #endif
215  complete_name += moPluginExtension;
216  #endif
217 
218  // Indice del plugin que se utilizara para crear a este efecto.
219  int plg_index = -1;
220 
221  // First, revisa que el plugin ya no haya sido cargado antes.
222  for(MOuint i = 0; i < plugins.Count(); i++)
223  if(!stricmp(plugins[i]->GetName(), complete_name))
224  {
225  plg_index = i;
226  break;
227  }
228 
229  if(plg_index == -1)
230  {
231  return false;
232  }
233 
234  bool res = plugins[plg_index]->Destroy(posteffect);
235 
237  if (res && plugins[plg_index]->n == 0) {
238  plugins[plg_index]->Unload();
239  plugins.Remove(plg_index);
240 
241  }
242 
243  return res;
244 }
245 
moPostEffect * Create()
static void Error(moText p_text)
Anuncia un error.
moDefineDynamicArray(moPostPluginsArray) moPostEffectFactory
moPostEffectFactory *(MO_PLG_ENTRY * CreatePostEffectFactoryFunction)()
Definition: moPostPlugin.h:47
int n
Definition: moPostPlugin.h:54
const moText & GetName() const
Definition: moPostEffect.h:53
CreatePostEffectFactoryFunction CreatePostEffectFactory
Definition: moPostPlugin.h:56
LIBMOLDEO_API bool moDeletePostEffect(moPostEffect *posteffect, moPostPluginsArray &plugins)
#define LIBMOLDEO_API
Definition: moTypes.h:180
void Load(moText plugin_file)
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()
DestroyPostEffectFactoryFunction DestroyPostEffectFactory
Definition: moPostPlugin.h:57
bool Destroy(moPostEffect *posteffect)
Definition: moPostPlugin.h:50
virtual moPostEffect * Create(void)=0
void(MO_PLG_ENTRY * DestroyPostEffectFactoryFunction)()
Definition: moPostPlugin.h:48
moPostEffectFactory * m_factory
Definition: moPostPlugin.h:59
LIBMOLDEO_API moPostEffect * moNewPostEffect(moText effect_name, moPostPluginsArray &plugins)
virtual void Destroy(moPostEffect *fx)=0
Definition: moPostPlugin.h:38
#define MOuint
Definition: moTypes.h:387
moPostEffect ** array
Definition: moPostPlugin.h:53
MOpluginHandle moLoadPlugin(moText fn)
Definition: moBasePlugin.h:55
void Unload()