Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split code out of mojosetup.c into fileio.c and gui.c, and did some p…
…olish work on the GUI plugin stuff.
- Loading branch information
Showing
8 changed files
with
262 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "fileio.h" | ||
|
||
// !!! FIXME: don't have this here. (need unlink for now). | ||
#include <unistd.h> | ||
|
||
boolean mojoInputToPhysicalFile(MojoInput *in, const char *fname) | ||
{ | ||
FILE *out = NULL; | ||
boolean iofailure = false; | ||
char buf[1024]; | ||
size_t br; | ||
|
||
STUBBED("mkdir first?"); | ||
|
||
if (in == NULL) | ||
return false; | ||
|
||
STUBBED("fopen?"); | ||
unlink(fname); | ||
out = fopen(fname, "wb"); | ||
if (out == NULL) | ||
return false; | ||
|
||
while (!iofailure) | ||
{ | ||
br = in->read(in, buf, sizeof (buf)); | ||
STUBBED("how to detect read failures?"); | ||
if (br == 0) // we're done! | ||
break; | ||
else if (br < 0) | ||
iofailure = true; | ||
else | ||
{ | ||
if (fwrite(buf, br, 1, out) != 1) | ||
iofailure = true; | ||
} // else | ||
} // while | ||
|
||
fclose(out); | ||
if (iofailure) | ||
{ | ||
unlink(fname); | ||
return false; | ||
} // if | ||
|
||
return true; | ||
} // mojoInputToPhysicalFile | ||
|
||
// end of fileio.c ... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
#include "gui.h" | ||
#include "fileio.h" | ||
|
||
// !!! FIXME: None of these should be here. | ||
#include <dlfcn.h> | ||
#include <unistd.h> | ||
#include <time.h> | ||
#include <sys/time.h> | ||
|
||
typedef struct S_PLUGINLIST | ||
{ | ||
char fname[1024]; | ||
void *lib; | ||
MojoGui *gui; | ||
MojoGuiPluginPriority priority; | ||
struct S_PLUGINLIST *next; | ||
} PluginList; | ||
|
||
MojoGui *GGui = NULL; | ||
PluginList *pluginDetails = NULL; | ||
|
||
|
||
static PluginList *loadGuiPlugin(MojoArchive *ar) | ||
{ | ||
char fname[1024] = { 0 }; | ||
PluginList *retval = NULL; | ||
void *lib = NULL; | ||
MojoGuiEntryType entry = NULL; | ||
boolean rc; | ||
MojoInput *io = ar->openCurrentEntry(ar); | ||
if (io == NULL) | ||
return false; | ||
|
||
STUBBED("Don't copy if it's a physical file already?"); | ||
|
||
STUBBED("Filename creation has to change"); | ||
{ | ||
struct timeval tv; | ||
gettimeofday(&tv, NULL); | ||
snprintf(fname, sizeof (fname), "/tmp/mojosetup-gui-%ld.so", tv.tv_sec); | ||
} | ||
|
||
rc = mojoInputToPhysicalFile(io, fname); | ||
io->close(io); | ||
|
||
if (rc) | ||
{ | ||
lib = dlopen(fname, RTLD_NOW | RTLD_GLOBAL); | ||
STUBBED("abstract out dlopen!"); | ||
if (lib != NULL) | ||
{ | ||
MojoGui *gui = NULL; | ||
entry = (MojoGuiEntryType) dlsym(lib, MOJOGUI_ENTRY_POINT_STR); | ||
if ( (entry != NULL) && ((gui = entry()) != NULL) ) | ||
{ | ||
retval = malloc(sizeof (PluginList)); | ||
if (retval != NULL) | ||
{ | ||
strcpy(retval->fname, fname); | ||
retval->lib = lib; | ||
retval->gui = gui; | ||
retval->priority = gui->priority(gui); | ||
retval->next = NULL; | ||
} // if | ||
} // if | ||
} // if | ||
} // if | ||
|
||
if (!retval) | ||
{ | ||
if (lib != NULL) | ||
dlclose(lib); | ||
if (fname[0]) | ||
unlink(fname); | ||
} // if | ||
|
||
return retval; | ||
} // loadGuiPlugin | ||
|
||
|
||
static PluginList *initGuiPluginsByPriority(PluginList *plugins) | ||
{ | ||
MojoGuiPluginPriority p; | ||
for (p = MOJOGUI_PRIORITY_TRY_FIRST; p < MOJOGUI_PRIORITY_TOTAL; p++) | ||
{ | ||
PluginList *i; | ||
for (i = plugins->next; i != NULL; i = i->next) | ||
{ | ||
if ( (i->priority == p) && (i->gui->init(i->gui)) ) | ||
return i; | ||
} // for | ||
} // for | ||
|
||
return NULL; | ||
} // initGuiPluginsByPriority | ||
|
||
|
||
static void deleteGuiPlugin(PluginList *plugin) | ||
{ | ||
if (plugin != NULL) | ||
{ | ||
if (plugin->gui) | ||
plugin->gui->deinit(plugin->gui); | ||
if (plugin->lib) | ||
dlclose(plugin->lib); | ||
if (plugin->fname[0]) | ||
unlink(plugin->fname); | ||
free(plugin); | ||
} // if | ||
} // deleteGuiPlugin | ||
|
||
|
||
MojoGui *MojoGui_initGuiPlugin(void) | ||
{ | ||
const MojoArchiveEntryInfo *entinfo = NULL; | ||
PluginList plugins; | ||
|
||
if (pluginDetails != NULL) | ||
return pluginDetails->gui; | ||
|
||
assert(GGui == NULL); | ||
|
||
memset(&plugins, '\0', sizeof (plugins)); | ||
|
||
// !!! FIXME: Have a global MojoArchive that represents the install | ||
// !!! FIXME: (either an archive, a physical dir, etc.) | ||
STUBBED("use a global MojoArchive for basedir"); | ||
MojoArchive *dir = MojoArchive_newFromDirectory("."); | ||
if (dir == NULL) | ||
return false; | ||
|
||
dir->restartEnumeration(dir); | ||
while ((entinfo = dir->enumEntry(dir)) != NULL) | ||
{ | ||
PluginList *item; | ||
|
||
if (entinfo->type != MOJOARCHIVE_ENTRY_FILE) | ||
continue; | ||
|
||
// not in the gui dir? | ||
if (strncmp(entinfo->filename, "guiplugins/", 4) != 0) | ||
continue; | ||
|
||
item = loadGuiPlugin(dir); | ||
if (item == NULL) | ||
continue; | ||
|
||
item->next = plugins.next; | ||
plugins.next = item; | ||
} // while | ||
|
||
STUBBED("Add static plugins to the list?"); | ||
|
||
pluginDetails = initGuiPluginsByPriority(&plugins); | ||
|
||
// cleanout unused plugins... | ||
PluginList *i = plugins.next; | ||
while (i != NULL) | ||
{ | ||
PluginList *next = i->next; | ||
if (i != pluginDetails) | ||
deleteGuiPlugin(i); | ||
i = next; | ||
} // while | ||
|
||
STUBBED("Don't close this when it's a global."); | ||
dir->close(dir); | ||
|
||
if (pluginDetails != NULL) | ||
{ | ||
GGui = pluginDetails->gui; | ||
pluginDetails->next = NULL; | ||
} // if | ||
|
||
return GGui; | ||
} // MojoGui_findGuiPlugin | ||
|
||
|
||
void MojoGui_deinitGuiPlugin(void) | ||
{ | ||
GGui = NULL; | ||
deleteGuiPlugin(pluginDetails); | ||
pluginDetails = NULL; | ||
} // MojoGui_deinitGuiPlugin | ||
|
||
// end of gui.c ... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,8 @@ INCLUDES := \ | |
|
||
SRCS := \ | ||
mojosetup.c \ | ||
gui.c \ | ||
fileio.c \ | ||
|
||
|
||
ifeq ($(isunix),true) | ||
|
Oops, something went wrong.