From ba4f775c64197dfa05b86616b9137e83b312e04d Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 13 Mar 2016 10:38:36 +0100 Subject: [PATCH] Added prototypes of process model and instance. --- src/Makefile.am | 15 ++- src/instance.c | 130 +++++++++++++++++++++++++ src/instance.h | 45 +++++++++ src/libzakgflow.h | 3 +- src/model.c | 241 ++++++++++++++++++++++++++++++++++++++++++++++ src/model.h | 52 ++++++++++ 6 files changed, 476 insertions(+), 10 deletions(-) create mode 100644 src/instance.c create mode 100644 src/instance.h create mode 100644 src/model.c create mode 100644 src/model.h diff --git a/src/Makefile.am b/src/Makefile.am index 7e2a93f..5b9d406 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,24 +2,21 @@ LIBS = $(ZAKGFLOW_LIBS) AM_CPPFLAGS = $(ZAKGFLOW_CFLAGS) \ -DLOCALEDIR=\"$(localedir)\" \ - -DMODULESDIR=\""$(libdir)/$(PACKAGE)/modules"\" \ -DG_LOG_DOMAIN=\"ZakGFlow\" lib_LTLIBRARIES = libzakgflow.la libzakgflow_la_SOURCES = \ - commons.c + commons.c \ + instance.c \ + model.c libzakgflow_la_LDFLAGS = -no-undefined libzakgflow_include_HEADERS = \ libzakgflow.h \ - commons.h + commons.h \ + instance.h \ + model.h libzakgflow_includedir = $(includedir)/libzakgflow - -install-exec-hook: - mkdir -p "$(libdir)/$(PACKAGE)/modules" - -uninstall-hook: - rm -rf "$(libdir)/$(PACKAGE)" diff --git a/src/instance.c b/src/instance.c new file mode 100644 index 0000000..744622d --- /dev/null +++ b/src/instance.c @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2016 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include +#include + +#include + +#include "instance.h" + +#ifdef G_OS_WIN32 + #include +#endif + +static void zak_gflow_instance_class_init (ZakGFlowInstanceClass *class); +static void zak_gflow_instance_init (ZakGFlowInstance *zak_gflow_instance); + +static void zak_gflow_instance_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void zak_gflow_instance_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static void zak_gflow_instance_dispose (GObject *gobject); +static void zak_gflow_instance_finalize (GObject *gobject); + +typedef struct + { + } ZakGFlowInstancePrivate; + +G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ZakGFlowInstance, zak_gflow_instance, G_TYPE_OBJECT) + +static void +zak_gflow_instance_class_init (ZakGFlowInstanceClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->set_property = zak_gflow_instance_set_property; + object_class->get_property = zak_gflow_instance_get_property; + object_class->dispose = zak_gflow_instance_dispose; + object_class->finalize = zak_gflow_instance_finalize; +} + +static void +zak_gflow_instance_init (ZakGFlowInstance *zak_gflow_instance) +{ + ZakGFlowInstancePrivate *priv = zak_gflow_instance_get_instance_private (zak_gflow_instance); + +} + +/* PRIVATE */ +static void +zak_gflow_instance_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + ZakGFlowInstance *zak_gflow_instance = (ZakGFlowInstance *)object; + ZakGFlowInstancePrivate *priv = zak_gflow_instance_get_instance_private (zak_gflow_instance); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +zak_gflow_instance_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + ZakGFlowInstance *zak_gflow_instance = (ZakGFlowInstance *)object; + ZakGFlowInstancePrivate *priv = zak_gflow_instance_get_instance_private (zak_gflow_instance); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +zak_gflow_instance_dispose (GObject *gobject) +{ + ZakGFlowInstance *zak_gflow_instance = (ZakGFlowInstance *)gobject; + ZakGFlowInstancePrivate *priv = zak_gflow_instance_get_instance_private (zak_gflow_instance); + + + + GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); + parent_class->dispose (gobject); +} + +static void +zak_gflow_instance_finalize (GObject *gobject) +{ + ZakGFlowInstance *zak_gflow_instance = (ZakGFlowInstance *)gobject; + ZakGFlowInstancePrivate *priv = zak_gflow_instance_get_instance_private (zak_gflow_instance); + + + + GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); + parent_class->finalize (gobject); +} diff --git a/src/instance.h b/src/instance.h new file mode 100644 index 0000000..fc8a674 --- /dev/null +++ b/src/instance.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2016 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __ZAK_GFLOW_INSTANCE_H__ +#define __ZAK_GFLOW_INSTANCE_H__ + + +#include + +#include + + +G_BEGIN_DECLS + + +#define ZAK_GFLOW_TYPE_INSTANCE zak_gflow_instance_get_type () +G_DECLARE_DERIVABLE_TYPE (ZakGFlowInstance, zak_gflow_instance, ZAK_GFLOW, INSTANCE, GObject) + +struct _ZakGFlowInstanceClass +{ + GObjectClass parent_class; +}; + + + + +G_END_DECLS + + +#endif /* __ZAK_GFLOW_INSTANCE_H__ */ diff --git a/src/libzakgflow.h b/src/libzakgflow.h index 3f1ab4d..1c95e6f 100644 --- a/src/libzakgflow.h +++ b/src/libzakgflow.h @@ -20,7 +20,8 @@ #define __LIBZAKGFLOW_H__ -#include +#include +#include #endif /* __LIBZAKGFLOW_H__ */ diff --git a/src/model.c b/src/model.c new file mode 100644 index 0000000..f895434 --- /dev/null +++ b/src/model.c @@ -0,0 +1,241 @@ +/* + * Copyright (C) 2016 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include +#include + +#include + +#include "model.h" + +#ifdef G_OS_WIN32 + #include +#endif + +static void zak_gflow_model_class_init (ZakGFlowModelClass *class); +static void zak_gflow_model_init (ZakGFlowModel *zak_gflow_model); + +static void zak_gflow_model_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void zak_gflow_model_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static void zak_gflow_model_dispose (GObject *gobject); +static void zak_gflow_model_finalize (GObject *gobject); + +typedef struct + { + } ZakGFlowModelPrivate; + +G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ZakGFlowModel, zak_gflow_model, G_TYPE_OBJECT) + +#ifdef G_OS_WIN32 +static HMODULE backend_dll = NULL; + +BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved); + +BOOL WINAPI +DllMain (HINSTANCE hinstDLL, + DWORD fdwReason, + LPVOID lpReserved) +{ + switch (fdwReason) + { + case DLL_MODELESS_ATTACH: + backend_dll = (HMODULE) hinstDLL; + break; + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_MODELESS_DETACH: + break; + } + return TRUE; +} +#endif + +static void +zak_gflow_model_class_init (ZakGFlowModelClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->set_property = zak_gflow_model_set_property; + object_class->get_property = zak_gflow_model_get_property; + object_class->dispose = zak_gflow_model_dispose; + object_class->finalize = zak_gflow_model_finalize; +} + +static void +zak_gflow_model_init (ZakGFlowModel *zak_gflow_model) +{ + gchar *localedir; + + ZakGFlowModelPrivate *priv = zak_gflow_model_get_instance_private (zak_gflow_model); + +#ifdef G_OS_WIN32 + + gchar *moddir; + gchar *p; + + moddir = g_win32_get_package_installation_directory_of_module (backend_dll); + + p = g_strrstr (moddir, g_strdup_printf ("%c", G_DIR_SEPARATOR)); + if (p != NULL + && (g_ascii_strcasecmp (p + 1, "src") == 0 + || g_ascii_strcasecmp (p + 1, ".libs") == 0)) + { + localedir = g_strdup (LOCALEDIR); + } + else + { + localedir = g_build_filename (moddir, "share", "locale", NULL); + } + + g_free (moddir); + +#else + + localedir = g_strdup (LOCALEDIR); + +#endif + + bindtextdomain (GETTEXT_PACKAGE, localedir); + textdomain (GETTEXT_PACKAGE); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); +} + +/** + * zak_gflow_model_load_from_xml: + * @zakmodel: + * @xmldoc: + * + */ +gboolean +zak_gflow_model_load_from_xml (ZakGFlowModel *zakmodel, xmlDoc *xmldoc) +{ + ZakGFlowModelPrivate *priv; + xmlNode *cur; + xmlNode *cur_clean; + + gboolean ret; + + g_return_val_if_fail (ZAK_GFLOW_IS_MODEL (zakmodel), FALSE); + g_return_val_if_fail (xmldoc != NULL, FALSE); + + ret = FALSE; + + cur = xmlDocGetRootElement (xmldoc); + if (cur != NULL) + { + } + + return ret; +} + +/** + * zak_gflow_model_load_from_file: + * @zakmodel: + * @filename: + * + */ +gboolean +zak_gflow_model_load_from_file (ZakGFlowModel *zakmodel, const gchar *filename) +{ + xmlDoc *xdoc; + + gboolean ret; + + g_return_val_if_fail (ZAK_GFLOW_IS_MODEL (zakmodel), FALSE); + g_return_val_if_fail (filename != NULL, FALSE); + + ret = FALSE; + + xdoc = xmlParseFile (filename); + if (xdoc != NULL) + { + ret = zak_gflow_model_load_from_xml (zakmodel, xdoc); + } + + return ret; +} + +/* PRIVATE */ +static void +zak_gflow_model_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + ZakGFlowModel *zak_gflow_model = (ZakGFlowModel *)object; + ZakGFlowModelPrivate *priv = zak_gflow_model_get_instance_private (zak_gflow_model); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +zak_gflow_model_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + ZakGFlowModel *zak_gflow_model = (ZakGFlowModel *)object; + ZakGFlowModelPrivate *priv = zak_gflow_model_get_instance_private (zak_gflow_model); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +zak_gflow_model_dispose (GObject *gobject) +{ + ZakGFlowModel *zak_gflow_model = (ZakGFlowModel *)gobject; + ZakGFlowModelPrivate *priv = zak_gflow_model_get_instance_private (zak_gflow_model); + + + + GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); + parent_class->dispose (gobject); +} + +static void +zak_gflow_model_finalize (GObject *gobject) +{ + ZakGFlowModel *zak_gflow_model = (ZakGFlowModel *)gobject; + ZakGFlowModelPrivate *priv = zak_gflow_model_get_instance_private (zak_gflow_model); + + + + GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); + parent_class->finalize (gobject); +} diff --git a/src/model.h b/src/model.h new file mode 100644 index 0000000..aa6f1e8 --- /dev/null +++ b/src/model.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2016 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __ZAK_GFLOW_MODEL_H__ +#define __ZAK_GFLOW_MODEL_H__ + + +#include + +#include + + +#include "instance.h" + + +G_BEGIN_DECLS + + +#define ZAK_GFLOW_TYPE_MODEL zak_gflow_model_get_type () +G_DECLARE_DERIVABLE_TYPE (ZakGFlowModel, zak_gflow_model, ZAK_GFLOW, MODEL, GObject) + +struct _ZakGFlowModelClass +{ + GObjectClass parent_class; +}; + + +gboolean zak_gflow_model_load_from_xml (ZakGFlowModel *model, xmlDoc *xmldoc); +gboolean zak_gflow_model_load_from_file (ZakGFlowModel *model, const gchar *filename); + +ZakGFlowInstance *zak_gflow_model_start (ZakGFlowModel *model, const gchar *model_id); + + +G_END_DECLS + + +#endif /* __ZAK_GFLOW_MODEL_H__ */ -- 2.49.0