00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "ModuleModule.h"
00012
00013 ModuleModule::ModuleModule()
00014 {
00015 *File = '\0';
00016 *Name = '\0';
00017 *Realname = '\0';
00018 *Version = '\0';
00019 *Autor = '\0';
00020 *Desc = '\0';
00021 Fonction = NULL;
00022 ModuleAdr = NULL;
00023 NbFonction = 0;
00024 Fonctions = NULL;
00025 Loaded = 0;
00026 }
00027
00028 ModuleModule::~ModuleModule()
00029 {
00030 int i;
00031
00032 UnLoad();
00033
00034 for(i = 0; i < NbFonction; i++)
00035 {
00036 if(Fonctions[i])
00037 free(Fonctions[i]);
00038 Fonctions[i] = NULL;
00039 }
00040 if(Fonctions)
00041 free(Fonctions);
00042 Fonctions = NULL;
00043 }
00044
00045 int ModuleModule::Load(char *pName, char *pFile)
00046 {
00047 int i = 0, Nb;
00048 char Nbr[12];
00049 ROUTINE Temp;
00050 BEGIN
00051 LOC("ModuleModule::Load")
00052
00053 if(!Loaded)
00054 {
00055 strcpy(Name, pName);
00056 strcpy(File, pFile);
00057
00058 TRY if(ModuleLoad(&ModuleAdr, pFile))
00059 {
00060 printf("[Module] Load %36s [ OK ]\n", pName);
00061
00062 TRYIF(ModuleImport(ModuleAdr, &Temp, "ModuleInit"), 25)
00063 TRYIF((int)Temp(NULL), 27)
00064
00065 TRY if(ModuleImport(ModuleAdr, &Temp, "ModuleName"))
00066 {
00067 strcpy(Realname, (char *)Temp(NULL));
00068 }
00069 ENDTRY(25)
00070
00071 TRY if(ModuleImport(ModuleAdr, &Temp, "ModuleVersion"))
00072 {
00073 strcpy(Version, (char *)Temp(NULL));
00074 }
00075 ENDTRY(25)
00076
00077 TRY if(ModuleImport(ModuleAdr, &Temp, "ModuleDesc"))
00078 {
00079 strcpy(Desc, (char *)Temp(NULL));
00080 }
00081 ENDTRY(25)
00082
00083 TRY if(ModuleImport(ModuleAdr, &Temp, "ModuleAutor"))
00084 {
00085 strcpy(Autor, (char *)Temp(NULL));
00086 }
00087 ENDTRY(25)
00088
00089 Loaded = 1;
00090
00091 TRYIF(ModuleImport(ModuleAdr, &Fonction, "ModuleFonction"), 25)
00092
00093 TRY {
00094 for(i = 0; i < NbFonction; i++)
00095 {
00096 if(Fonctions[i])
00097 free(Fonctions[i]);
00098 Fonctions[i] = NULL;
00099 }
00100 if(Fonctions)
00101 free(Fonctions);
00102 Fonctions = NULL;
00103
00104 printf("\t%s V%s by %s\n", Realname, Version, Autor);
00105 printf("\t%s\n", Desc);
00106 }
00107
00108 TRY Nb = AtoD((char *)Fonction(NULL));
00109 TRY if(Nb)
00110 {
00111 Fonctions = (ModuleFonction **)realloc(Fonctions, Nb * sizeof(ModuleFonction *));
00112
00113 for(i = 0; i < (Nb && !CERROR); i++)
00114 {
00115 Fonctions[i] = new ModuleFonction;
00116
00117 DtoA(i + 1, Nbr);
00118 CERROR = AddFonction((char *)Fonction(Nbr));
00119 }
00120 }
00121 ENDTRY(26)
00122 }
00123 else
00124 {
00125 printf("[Module] Load %36s [FAILED]\n", pName);
00126 CERROR = 23;
00127 }
00128 }
00129
00130 PERROR
00131
00132 ENDBEGIN
00133 }
00134
00135 int ModuleModule::UnLoad()
00136 {
00137 int i = 0;
00138 ROUTINE Close;
00139 BEGIN
00140 LOC("ModuleModule::UnLoad")
00141
00142 if(Loaded)
00143 {
00144 if(ModuleImport(ModuleAdr, &Close, "ModuleClose"))
00145 Close(NULL);
00146
00147 TRY if(!ModuleUnload(&ModuleAdr))
00148 {
00149 printf("[Module] Unload %34s [ OK ]\n", Name);
00150
00151 for(i = 0; i < NbFonction; i++)
00152 {
00153 if(Fonctions[i])
00154 free(Fonctions[i]);
00155 Fonctions[i] = NULL;
00156 }
00157 if(Fonctions)
00158 free(Fonctions);
00159 Fonctions = NULL;
00160 NbFonction = 0;
00161 Loaded = 0;
00162 }
00163 else
00164 {
00165 printf("[Module] Unload %34s [FAILED]\n", Name);
00166 CERROR = 24;
00167 }
00168 }
00169
00170 PERROR
00171
00172 ENDBEGIN
00173 }
00174
00175 int ModuleModule::AddFonction(char *pName)
00176 {
00177 ModuleFonction *Fonction;
00178 BEGIN
00179 LOC("ModuleModule::AddFonction")
00180
00181 TRY if(Loaded)
00182 {
00183 Fonction = new ModuleFonction;
00184
00185 printf("[Module] Import %34s ", pName);
00186 TRY if(ModuleImport(ModuleAdr, &Fonction->Fonction, pName))
00187 {
00188 Fonctions = (ModuleFonction **)realloc(Fonctions, (NbFonction + 1) * sizeof(ModuleFonction *));
00189
00190 Fonctions[NbFonction] = Fonction;
00191 strcpy(Fonctions[NbFonction]->Name, pName);
00192
00193 NbFonction++;
00194
00195 printf("[ OK ]\n");
00196 }
00197 else
00198 {
00199 printf("[FAILED]\n");
00200 CERROR = 25;
00201 }
00202 }
00203 ENDTRY(23)
00204
00205 PERROR
00206
00207 ENDBEGIN
00208 }
00209
00210 int ModuleModule::DelFonction(int iPos)
00211 {
00212 int i = 0;
00213 BEGIN
00214 LOC("ModuleModule::DelFonction")
00215
00216 TRY if(Loaded)
00217 {
00218 TRY if(iPos < NbFonction)
00219 {
00220 if(Fonctions[iPos])
00221 free(Fonctions[iPos]);
00222 Fonctions[iPos] = NULL;
00223
00224 for(i = iPos; i < (NbFonction - 1); Fonctions[i] = Fonctions[i++]);
00225 Fonctions = (ModuleFonction **)realloc(Fonctions, (NbFonction - 1) * sizeof(ModuleFonction *));
00226
00227 NbFonction--;
00228 }
00229 ENDTRY(26)
00230 }
00231 ENDTRY(23)
00232
00233 PERROR
00234
00235 ENDBEGIN
00236 }
00237