Skip to content

Instantly share code, notes, and snippets.

@torralbaa
Last active July 24, 2020 17:11
Show Gist options
  • Save torralbaa/3afc55da75890961ce1a166ef8ee66cb to your computer and use it in GitHub Desktop.
Save torralbaa/3afc55da75890961ce1a166ef8ee66cb to your computer and use it in GitHub Desktop.
E(P)API: environ (Plugin) API.
/*
* plugins.c
*
* Copyright 2020 Alvarito050506 <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
#include <gtk/gtk.h>
#include <plugins.h>
#include <stdlib.h>
struct eapi_base_t
{
char* name;
eapi_type type;
};
struct eapi_plugin_t
{
eapi_base_t _base;
eapi_expose_callback expose_func;
char* tag_name;
};
eapi_plugin_t* eapi_new_plugin(const char* tag_name, eapi_expose_callback expose_func)
{
eapi_plugin_t* plugin = (eapi_plugin_t*)malloc(sizeof(eapi_plugin_t));
plugin->_base.name = (char*)tag_name;
plugin->tag_name = (char*)tag_name;
plugin->expose_func = expose_func;
return plugin;
}
int eapi_free(eapi_base_t* base)
{
if (base->type == EAPI_BASE_T)
{
free(base);
} else if (base->type == EAPI_PLUGIN_T)
{
free((eapi_plugin_t*)base);
} else
{
return -1;
}
return 0;
}
char* eapi_get_name(eapi_base_t* base)
{
if (base->name != NULL)
{
return base->name;
}
return NULL;
}
char* eapi_plugin_get_tag(eapi_plugin_t* plugin)
{
return plugin->tag_name;
}
eapi_expose_callback eapi_plugin_get_expose(eapi_plugin_t* plugin)
{
return plugin->expose_func;
}
/*
* plugins.h
*
* Copyright 2020 Alvarito050506 <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
#ifndef E_PAPI
#define E_PAPI
#define EAPI_BASE(ext) (eapi_base_t*)ext
#define EAPI_EXPOSE(func) (eapi_expose_callback)func
#include <gtk/gtk.h>
/* Obscure type(s), if you really want to access the definition(s), go to the `plugins.c` file. */
typedef struct eapi_base_t eapi_base_t;
typedef struct eapi_plugin_t eapi_plugin_t;
typedef GtkWidget* (*eapi_expose_callback)();
typedef char e_bool;
typedef enum eapi_type {
EAPI_BASE_T,
EAPI_PLUGIN_T
} eapi_type;
eapi_plugin_t* eapi_new_plugin(const char* tag_name, eapi_expose_callback expose_func);
int eapi_free(eapi_base_t* base);
char* eapi_get_name(eapi_base_t* base);
char* eapi_plugin_get_tag(eapi_plugin_t* plugin);
eapi_expose_callback eapi_plugin_get_expose(eapi_plugin_t* plugin);
#endif /* E_PAPI */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment