[planner: 1/2] libplanner: refactored gobject derived objects to current macro definition.
- From: Mart Raudsepp <mraudsepp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [planner: 1/2] libplanner: refactored gobject derived objects to current macro definition.
- Date: Thu, 29 Jul 2021 17:20:39 +0000 (UTC)
commit 1b3b5f404e28ae82f7296d392d7b87f25f218f14
Author: Günther Wagner <info gunibert de>
Date: Sun Jun 20 13:56:02 2021 +0200
libplanner: refactored gobject derived objects to current macro definition.
This reduces boilerplate and keeps the private structs
and parent class pointer away from usercode. This should make it easier
to maintain libplanner in the long run.
libplanner/mrp-application.c | 158 ++---
libplanner/mrp-application.h | 26 +-
libplanner/mrp-assignment.c | 192 +++---
libplanner/mrp-assignment.h | 28 +-
libplanner/mrp-calendar.c | 329 ++++------
libplanner/mrp-calendar.h | 30 +-
libplanner/mrp-group.c | 204 +++---
libplanner/mrp-group.h | 27 +-
libplanner/mrp-mpx.c | 2 +-
libplanner/mrp-object.c | 303 ++++-----
libplanner/mrp-object.h | 25 +-
libplanner/mrp-parser.c | 1 -
libplanner/mrp-private.h | 12 +-
libplanner/mrp-project.c | 8 +-
libplanner/mrp-relation.c | 248 +++----
libplanner/mrp-relation.h | 36 +-
libplanner/mrp-resource.c | 458 ++++++-------
libplanner/mrp-resource.h | 69 +-
libplanner/mrp-sql.c | 1 +
libplanner/mrp-storage-module-factory.c | 112 ++--
libplanner/mrp-storage-module-factory.h | 27 +-
libplanner/mrp-storage-module.c | 37 +-
libplanner/mrp-storage-module.h | 24 +-
libplanner/mrp-storage-mrproject.c | 43 +-
libplanner/mrp-storage-mrproject.h | 20 +-
libplanner/mrp-storage-sql.c | 43 +-
libplanner/mrp-storage-sql.h | 20 +-
libplanner/mrp-task-manager.c | 297 ++++-----
libplanner/mrp-task-manager.h | 103 ++-
libplanner/mrp-task.c | 1075 ++++++++++++++++---------------
libplanner/mrp-task.h | 33 +-
libplanner/mrp-xml.c | 4 +-
libplanner/mrp-xsl.c | 4 +-
src/planner-gantt-chart.c | 1 +
src/planner-gantt-print.c | 1 +
src/planner-predecessor-model.c | 1 +
src/planner-task-cmd.c | 1 +
src/planner-task-dialog.c | 1 +
src/planner-task-tree.c | 2 +-
tests/task-test.c | 1 +
40 files changed, 1686 insertions(+), 2321 deletions(-)
---
diff --git a/libplanner/mrp-application.c b/libplanner/mrp-application.c
index bd785419..912246ba 100644
--- a/libplanner/mrp-application.c
+++ b/libplanner/mrp-application.c
@@ -51,106 +51,64 @@
#include "mrp-application.h"
#include "mrp-paths.h"
-struct _MrpApplicationPriv {
+typedef struct {
GList *file_readers;
GList *file_writers;
GList *modules;
-};
+} MrpApplicationPrivate;
-static void application_class_init (MrpApplicationClass *klass);
-static void application_init (MrpApplication *app);
-static void application_finalize (GObject *object);
-
-static void application_init_gettext (void);
-static void application_init_file_modules (MrpApplication *app);
-static void application_finalize_file_modules
- (MrpApplication *app);
+G_DEFINE_TYPE_WITH_PRIVATE (MrpApplication, mrp_application, G_TYPE_OBJECT)
static GObjectClass *parent_class;
static guint last_used_id;
static GHashTable *data_hash;
-GType
-mrp_application_get_type (void)
-{
- static GType type = 0;
-
- if (!type) {
- static const GTypeInfo info = {
- sizeof (MrpApplicationClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) application_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (MrpApplication),
- 0, /* n_preallocs */
- (GInstanceInitFunc) application_init,
- };
-
- type = g_type_register_static (G_TYPE_OBJECT,
- "MrpApplication",
- &info, 0);
- }
-
- return type;
-}
-
static void
-application_class_init (MrpApplicationClass *klass)
+mrp_application_finalize_file_modules (MrpApplication *app)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
-
- object_class->finalize = application_finalize;
-
- data_hash = g_hash_table_new (NULL, NULL);
+ MrpApplicationPrivate *priv = mrp_application_get_instance_private (app);
+ g_list_foreach (priv->file_readers, (GFunc) g_free, NULL);
+ g_list_free (priv->file_readers);
+ priv->file_readers = NULL;
- last_used_id = 0;
+ g_list_foreach (priv->file_writers, (GFunc) g_free, NULL);
+ g_list_free (priv->file_writers);
+ priv->file_writers = NULL;
+ g_list_foreach (priv->modules, (GFunc) g_free, NULL);
+ g_list_free (priv->modules);
+ priv->modules = NULL;
}
static void
-application_init (MrpApplication *app)
+mrp_application_finalize (GObject *object)
{
- MrpApplicationPriv *priv;
- static gboolean first = TRUE;
-
- if (!first) {
- g_error ("You can only create one instance of MrpApplication");
- exit (1);
- }
-
- priv = g_new0 (MrpApplicationPriv, 1);
- priv->file_readers = NULL;
- priv->file_writers = NULL;
-
- app->priv = priv;
+ MrpApplication *app = MRP_APPLICATION (object);
- application_init_gettext ();
- application_init_file_modules (app);
+ mrp_application_finalize_file_modules (app);
- first = FALSE;
+ if (parent_class->finalize) {
+ parent_class->finalize (object);
+ }
}
static void
-application_finalize (GObject *object)
+mrp_application_class_init (MrpApplicationClass *klass)
{
- MrpApplication *app = MRP_APPLICATION (object);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- application_finalize_file_modules (app);
+ parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
- g_free (app->priv);
- app->priv = NULL;
+ object_class->finalize = mrp_application_finalize;
+
+ data_hash = g_hash_table_new (NULL, NULL);
+
+ last_used_id = 0;
- if (parent_class->finalize) {
- parent_class->finalize (object);
- }
}
static void
-application_init_gettext (void)
+mrp_application_init_gettext (void)
{
gchar *locale_dir;
@@ -164,74 +122,72 @@ application_init_gettext (void)
}
static void
-application_init_file_modules (MrpApplication *app)
+mrp_application_init_file_modules (MrpApplication *app)
{
- app->priv->modules = mrp_file_module_load_all (app);
+ MrpApplicationPrivate *priv = mrp_application_get_instance_private (app);
+ priv->modules = mrp_file_module_load_all (app);
}
static void
-application_finalize_file_modules (MrpApplication *app)
+mrp_application_init (MrpApplication *app)
{
- g_list_foreach (app->priv->file_readers, (GFunc) g_free, NULL);
- g_list_free (app->priv->file_readers);
- app->priv->file_readers = NULL;
+ MrpApplicationPrivate *priv;
+ static gboolean first = TRUE;
- g_list_foreach (app->priv->file_writers, (GFunc) g_free, NULL);
- g_list_free (app->priv->file_writers);
- app->priv->file_writers = NULL;
+ if (!first) {
+ g_error ("You can only create one instance of MrpApplication");
+ exit (1);
+ }
+
+ priv = mrp_application_get_instance_private (app);
+ priv->file_readers = NULL;
+ priv->file_writers = NULL;
- g_list_foreach (app->priv->modules, (GFunc) g_free, NULL);
- g_list_free (app->priv->modules);
- app->priv->modules = NULL;
+ mrp_application_init_gettext ();
+ mrp_application_init_file_modules (app);
+
+ first = FALSE;
}
void
-imrp_application_register_reader (MrpApplication *app, MrpFileReader *reader)
+mrp_application_register_reader (MrpApplication *app, MrpFileReader *reader)
{
- MrpApplicationPriv *priv;
+ MrpApplicationPrivate *priv = mrp_application_get_instance_private (app);
g_return_if_fail (MRP_IS_APPLICATION (app));
g_return_if_fail (reader != NULL);
- priv = app->priv;
-
priv->file_readers = g_list_prepend (priv->file_readers, reader);
}
void
-imrp_application_register_writer (MrpApplication *app, MrpFileWriter *writer)
+mrp_application_register_writer (MrpApplication *app, MrpFileWriter *writer)
{
- MrpApplicationPriv *priv;
+ MrpApplicationPrivate *priv = mrp_application_get_instance_private (app);
g_return_if_fail (MRP_IS_APPLICATION (app));
g_return_if_fail (writer != NULL);
- priv = app->priv;
-
priv->file_writers = g_list_prepend (priv->file_writers, writer);
}
GList *
-imrp_application_get_all_file_readers (MrpApplication *app)
+mrp_application_get_all_file_readers (MrpApplication *app)
{
- MrpApplicationPriv *priv;
+ MrpApplicationPrivate *priv = mrp_application_get_instance_private (app);
g_return_val_if_fail (MRP_IS_APPLICATION (app), NULL);
- priv = app->priv;
-
return priv->file_readers;
}
GList *
-imrp_application_get_all_file_writers (MrpApplication *app)
+mrp_application_get_all_file_writers (MrpApplication *app)
{
- MrpApplicationPriv *priv;
+ MrpApplicationPrivate *priv = mrp_application_get_instance_private (app);
g_return_val_if_fail (MRP_IS_APPLICATION (app), NULL);
- priv = app->priv;
-
return priv->file_writers;
}
@@ -269,7 +225,7 @@ mrp_application_get_unique_id (void)
* Return value: TRUE if the change has been done
**/
gboolean
-imrp_application_id_set_data (gpointer data,
+mrp_application_id_set_data (gpointer data,
guint data_id)
{
g_assert (g_hash_table_lookup (data_hash, GUINT_TO_POINTER (data_id)) == NULL);
@@ -306,7 +262,7 @@ mrp_application_id_get_data (guint object_id)
* Return value: a pointer to the data
**/
gboolean
-imrp_application_id_remove_data (guint object_id)
+mrp_application_id_remove_data (guint object_id)
{
return g_hash_table_remove (data_hash, GUINT_TO_POINTER (object_id));
}
diff --git a/libplanner/mrp-application.h b/libplanner/mrp-application.h
index 8e795816..d9fa0454 100644
--- a/libplanner/mrp-application.h
+++ b/libplanner/mrp-application.h
@@ -20,17 +20,15 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __MRP_APPLICATION_H__
-#define __MRP_APPLICATION_H__
+#pragma once
#include <glib-object.h>
+G_BEGIN_DECLS
+
#define MRP_TYPE_APPLICATION (mrp_application_get_type ())
-#define MRP_APPLICATION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MRP_TYPE_APPLICATION, MrpApplication))
-#define MRP_APPLICATION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MRP_TYPE_APPLICATION,
MrpApplicationClass))
-#define MRP_IS_APPLICATION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MRP_TYPE_APPLICATION))
-#define MRP_IS_APPLICATION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MRP_TYPE_APPLICATION))
-#define MRP_APPLICATION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MRP_TYPE_APPLICATION,
MrpApplicationClass))
+
+G_DECLARE_DERIVABLE_TYPE (MrpApplication, mrp_application, MRP, APPLICATION, GObject)
/**
* MrpApplication:
@@ -39,16 +37,6 @@
* create an #MrpApplication object to create projects and use
* libmrproject.
*/
-typedef struct _MrpApplication MrpApplication;
-typedef struct _MrpApplicationClass MrpApplicationClass;
-typedef struct _MrpApplicationPriv MrpApplicationPriv;
-
-struct _MrpApplication {
- GObject parent;
-
- MrpApplicationPriv *priv;
-};
-
struct _MrpApplicationClass {
GObjectClass parent_class;
};
@@ -57,10 +45,8 @@ struct _MrpApplicationClass {
/* General functions.
*/
-GType mrp_application_get_type (void) G_GNUC_CONST;
-
MrpApplication * mrp_application_new (void);
guint mrp_application_get_unique_id (void);
gpointer mrp_application_id_get_data (guint object_id);
-#endif /* __MRP_APPLICATION_H__ */
+G_END_DECLS
diff --git a/libplanner/mrp-assignment.c b/libplanner/mrp-assignment.c
index bd546d8c..05ae470b 100644
--- a/libplanner/mrp-assignment.c
+++ b/libplanner/mrp-assignment.c
@@ -39,12 +39,19 @@
#include "mrp-marshal.h"
#include "mrp-assignment.h"
-struct _MrpAssignmentPriv {
+struct _MrpAssignment
+{
+ MrpObject parent_instance;
+};
+
+typedef struct {
MrpTask *task;
MrpResource *resource;
gint units;
-};
+} MrpAssignmentPrivate;
+
+G_DEFINE_TYPE_WITH_CODE (MrpAssignment, mrp_assignment, MRP_TYPE_OBJECT, G_ADD_PRIVATE (MrpAssignment))
/* Properties */
enum {
@@ -54,101 +61,11 @@ enum {
PROP_UNITS
};
-
-static void assignment_class_init (MrpAssignmentClass *klass);
-static void assignment_init (MrpAssignment *assignment);
-static void assignment_finalize (GObject *object);
-static void assignment_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void assignment_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-static MrpObjectClass *parent_class;
-
-GType
-mrp_assignment_get_type (void)
-{
- static GType type = 0;
-
- if (!type) {
- static const GTypeInfo info = {
- sizeof (MrpAssignmentClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) assignment_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (MrpAssignment),
- 0, /* n_preallocs */
- (GInstanceInitFunc) assignment_init,
- };
-
- type = g_type_register_static (MRP_TYPE_OBJECT,
- "MrpAssignment",
- &info, 0);
- }
-
- return type;
-}
-
static void
-assignment_class_init (MrpAssignmentClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- parent_class = MRP_OBJECT_CLASS (g_type_class_peek_parent (klass));
-
- object_class->finalize = assignment_finalize;
- object_class->set_property = assignment_set_property;
- object_class->get_property = assignment_get_property;
-
- /* Properties */
- g_object_class_install_property (object_class,
- PROP_TASK,
- g_param_spec_object ("task",
- "Task",
- "The task",
- MRP_TYPE_TASK,
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_RESOURCE,
- g_param_spec_object ("resource",
- "Resource",
- "The resource that is assigned to the task",
- MRP_TYPE_RESOURCE,
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_UNITS,
- g_param_spec_int ("units",
- "Units",
- "Number of units assignment",
- -1,
- G_MAXINT,
- 0,
- G_PARAM_READWRITE));
-}
-
-static void
-assignment_init (MrpAssignment *assignment)
-{
- MrpAssignmentPriv *priv;
-
- priv = g_new0 (MrpAssignmentPriv, 1);
-
- assignment->priv = priv;
-}
-
-static void
-assignment_finalize (GObject *object)
+mrp_assignment_finalize (GObject *object)
{
MrpAssignment *assignment = MRP_ASSIGNMENT (object);
- MrpAssignmentPriv *priv;
-
- priv = assignment->priv;
+ MrpAssignmentPrivate *priv = mrp_assignment_get_instance_private (assignment);
if (priv->task) {
g_object_unref (priv->task);
@@ -160,22 +77,17 @@ assignment_finalize (GObject *object)
priv->resource = NULL;
}
- if (G_OBJECT_CLASS (parent_class)->finalize) {
- (* G_OBJECT_CLASS (parent_class)->finalize) (object);
- }
+ G_OBJECT_CLASS (mrp_assignment_parent_class)->finalize (object);
}
static void
-assignment_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+mrp_assignment_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- MrpAssignment *assignment;
- MrpAssignmentPriv *priv;
-
- assignment = MRP_ASSIGNMENT (object);
- priv = assignment->priv;
+ MrpAssignment *assignment = MRP_ASSIGNMENT (object);
+ MrpAssignmentPrivate *priv = mrp_assignment_get_instance_private (assignment);
/* FIXME: See bug #138368 about this. The assignment doesn't have a
* project pointer so we can't emit changed on it. We cheat for now and
@@ -210,16 +122,13 @@ assignment_set_property (GObject *object,
}
static void
-assignment_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+mrp_assignment_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- MrpAssignment *assignment;
- MrpAssignmentPriv *priv;
-
- assignment = MRP_ASSIGNMENT (object);
- priv = assignment->priv;
+ MrpAssignment *assignment = MRP_ASSIGNMENT (object);
+ MrpAssignmentPrivate *priv = mrp_assignment_get_instance_private (assignment);
switch (prop_id) {
case PROP_TASK:
@@ -237,6 +146,47 @@ assignment_get_property (GObject *object,
}
}
+
+static void
+mrp_assignment_class_init (MrpAssignmentClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = mrp_assignment_finalize;
+ object_class->set_property = mrp_assignment_set_property;
+ object_class->get_property = mrp_assignment_get_property;
+
+ /* Properties */
+ g_object_class_install_property (object_class,
+ PROP_TASK,
+ g_param_spec_object ("task",
+ "Task",
+ "The task",
+ MRP_TYPE_TASK,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_RESOURCE,
+ g_param_spec_object ("resource",
+ "Resource",
+ "The resource that is assigned to the task",
+ MRP_TYPE_RESOURCE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_UNITS,
+ g_param_spec_int ("units",
+ "Units",
+ "Number of units assignment",
+ -1,
+ G_MAXINT,
+ 0,
+ G_PARAM_READWRITE));
+}
+
+static void
+mrp_assignment_init (MrpAssignment *assignment)
+{
+}
+
/**
* mrp_assignment_new:
*
@@ -267,9 +217,11 @@ mrp_assignment_new (void)
MrpTask *
mrp_assignment_get_task (MrpAssignment *assignment)
{
+ MrpAssignmentPrivate *priv = mrp_assignment_get_instance_private (assignment);
+
g_return_val_if_fail (MRP_IS_ASSIGNMENT (assignment), NULL);
- return assignment->priv->task;
+ return priv->task;
}
/**
@@ -284,9 +236,11 @@ mrp_assignment_get_task (MrpAssignment *assignment)
MrpResource *
mrp_assignment_get_resource (MrpAssignment *assignment)
{
+ MrpAssignmentPrivate *priv = mrp_assignment_get_instance_private (assignment);
+
g_return_val_if_fail (MRP_IS_ASSIGNMENT (assignment), NULL);
- return assignment->priv->resource;
+ return priv->resource;
}
/**
@@ -301,7 +255,9 @@ mrp_assignment_get_resource (MrpAssignment *assignment)
gint
mrp_assignment_get_units (MrpAssignment *assignment)
{
+ MrpAssignmentPrivate *priv = mrp_assignment_get_instance_private (assignment);
+
g_return_val_if_fail (MRP_IS_ASSIGNMENT (assignment), -1);
- return assignment->priv->units;
+ return priv->units;
}
diff --git a/libplanner/mrp-assignment.h b/libplanner/mrp-assignment.h
index 095f0ca8..28d3999a 100644
--- a/libplanner/mrp-assignment.h
+++ b/libplanner/mrp-assignment.h
@@ -20,39 +20,21 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __MRP_ASSIGNMENT_H__
-#define __MRP_ASSIGNMENT_H__
+#pragma once
#include <libplanner/mrp-object.h>
#include <libplanner/mrp-time.h>
#include <libplanner/mrp-types.h>
-#define MRP_TYPE_ASSIGNMENT (mrp_assignment_get_type ())
-#define MRP_ASSIGNMENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MRP_TYPE_ASSIGNMENT, MrpAssignment))
-#define MRP_ASSIGNMENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MRP_TYPE_ASSIGNMENT, MrpAssignmentClass))
-#define MRP_IS_ASSIGNMENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MRP_TYPE_ASSIGNMENT))
-#define MRP_IS_ASSIGNMENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MRP_TYPE_ASSIGNMENT))
-#define MRP_ASSIGNMENT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MRP_TYPE_ASSIGNMENT,
MrpAssignmentClass))
-
-typedef struct _MrpAssignmentClass MrpAssignmentClass;
-typedef struct _MrpAssignmentPriv MrpAssignmentPriv;
-
-struct _MrpAssignment {
- MrpObject parent;
+G_BEGIN_DECLS
- MrpAssignmentPriv *priv;
-};
-
-struct _MrpAssignmentClass {
- MrpObjectClass parent_class;
-};
+#define MRP_TYPE_ASSIGNMENT (mrp_assignment_get_type ())
-GType mrp_assignment_get_type (void) G_GNUC_CONST;
+G_DECLARE_FINAL_TYPE (MrpAssignment, mrp_assignment, MRP, ASSIGNMENT, MrpObject)
MrpAssignment *mrp_assignment_new (void);
-
MrpTask *mrp_assignment_get_task (MrpAssignment *assignment);
MrpResource *mrp_assignment_get_resource (MrpAssignment *assignment);
gint mrp_assignment_get_units (MrpAssignment *assignment);
-#endif /* __MRP_ASSIGNMENT_H__ */
+G_END_DECLS
diff --git a/libplanner/mrp-calendar.c b/libplanner/mrp-calendar.c
index 8277b936..78bfa3ad 100644
--- a/libplanner/mrp-calendar.c
+++ b/libplanner/mrp-calendar.c
@@ -60,7 +60,11 @@ enum {
LAST_SIGNAL
};
-struct _MrpCalendarPriv {
+struct _MrpCalendar {
+ MrpObject parent;
+};
+
+typedef struct {
MrpProject *project;
gchar *name;
@@ -76,7 +80,9 @@ struct _MrpCalendarPriv {
/* This can override single days and is hashed on the date */
GHashTable *days;
-};
+} MrpCalendarPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (MrpCalendar, mrp_calendar, MRP_TYPE_OBJECT)
struct _MrpInterval
{
@@ -87,17 +93,6 @@ struct _MrpInterval
guint ref_count;
};
-static void calendar_class_init (MrpCalendarClass *class);
-static void calendar_init (MrpCalendar *module);
-static void calendar_finalize (GObject *object);
-static void calendar_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void calendar_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
static MrpDay * calendar_get_default_day (MrpCalendar *calendar,
mrptime date,
gboolean derive);
@@ -114,46 +109,79 @@ static void calendar_emit_changed (MrpCalendar *calendar);
static GList * calendar_clean_intervals (GList *list);
-
-static MrpObjectClass *parent_class;
static guint signals[LAST_SIGNAL];
-GType
-mrp_calendar_get_type (void)
+static void
+mrp_calendar_finalize (GObject *object)
{
- static GType object_type = 0;
-
- if (!object_type) {
- static const GTypeInfo object_info = {
- sizeof (MrpCalendarClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) calendar_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (MrpCalendar),
- 0, /* n_preallocs */
- (GInstanceInitFunc) calendar_init,
- };
-
- object_type = g_type_register_static (MRP_TYPE_OBJECT,
- "MrpCalendar",
- &object_info, 0);
+ MrpCalendar *calendar = MRP_CALENDAR (object);
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
+
+ g_hash_table_destroy (priv->days);
+ g_hash_table_destroy (priv->day_intervals);
+
+ g_list_foreach (priv->children, (GFunc) g_object_unref, NULL);
+ g_list_free (priv->children);
+
+ g_free (priv->name);
+
+ g_free (priv);
+
+ G_OBJECT_CLASS (mrp_calendar_parent_class)->finalize (object);
+}
+
+static void
+mrp_calendar_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ MrpCalendar *calendar = MRP_CALENDAR (object);
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
+
+ switch (prop_id) {
+ case PROP_NAME:
+ g_value_set_string (value, priv->name);
+ break;
+ case PROP_PROJECT:
+ g_value_set_object (value, priv->project);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
}
+}
- return object_type;
+static void
+mrp_calendar_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ MrpCalendar *calendar = MRP_CALENDAR (object);
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
+
+ switch (prop_id) {
+ case PROP_NAME:
+ mrp_calendar_set_name (calendar, g_value_get_string (value));
+ break;
+ case PROP_PROJECT:
+ priv->project = MRP_PROJECT (g_value_get_pointer (value));
+ break;
+ default:
+ break;
+ }
}
static void
-calendar_class_init (MrpCalendarClass *klass)
+mrp_calendar_class_init (MrpCalendarClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- parent_class = MRP_OBJECT_CLASS (g_type_class_peek_parent (klass));
-
- object_class->finalize = calendar_finalize;
- object_class->get_property = calendar_get_property;
- object_class->set_property = calendar_set_property;
+ object_class->finalize = mrp_calendar_finalize;
+ object_class->get_property = mrp_calendar_get_property;
+ object_class->set_property = mrp_calendar_set_property;
/**
* MrpCalendar::calendar-changed:
@@ -190,11 +218,9 @@ calendar_class_init (MrpCalendarClass *klass)
}
static void
-calendar_init (MrpCalendar *calendar)
+mrp_calendar_init (MrpCalendar *calendar)
{
- MrpCalendarPriv *priv;
-
- priv = g_new0 (MrpCalendarPriv, 1);
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
priv->name = NULL;
priv->parent = NULL;
@@ -205,93 +231,16 @@ calendar_init (MrpCalendar *calendar)
priv->children = NULL;
priv->day_intervals = g_hash_table_new (NULL, NULL);
-
- calendar->priv = priv;
-}
-
-static void
-calendar_finalize (GObject *object)
-{
- MrpCalendar *calendar;
- MrpCalendarPriv *priv;
-
- calendar = MRP_CALENDAR (object);
- priv = calendar->priv;
-
- g_hash_table_destroy (priv->days);
- g_hash_table_destroy (priv->day_intervals);
-
- g_list_foreach (priv->children, (GFunc) g_object_unref, NULL);
- g_list_free (priv->children);
-
- g_free (priv->name);
-
- g_free (priv);
-
- if (G_OBJECT_CLASS (parent_class)->finalize) {
- (* G_OBJECT_CLASS (parent_class)->finalize) (object);
- }
-}
-
-static void
-calendar_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MrpCalendar *calendar;
- MrpCalendarPriv *priv;
-
- calendar = MRP_CALENDAR (object);
- priv = calendar->priv;
-
- switch (prop_id) {
- case PROP_NAME:
- g_value_set_string (value, priv->name);
- break;
- case PROP_PROJECT:
- g_value_set_object (value, priv->project);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-calendar_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MrpCalendar *calendar;
- MrpCalendarPriv *priv;
-
- calendar = MRP_CALENDAR (object);
- priv = calendar->priv;
-
- switch (prop_id) {
- case PROP_NAME:
- mrp_calendar_set_name (calendar, g_value_get_string (value));
- break;
- case PROP_PROJECT:
- priv->project = MRP_PROJECT (g_value_get_pointer (value));
- break;
- default:
- break;
- }
}
static MrpDay *
calendar_get_default_day (MrpCalendar *calendar, mrptime date, gboolean derive)
{
- MrpCalendarPriv *priv;
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
gint week_day;
g_return_val_if_fail (MRP_IS_CALENDAR (calendar), 0);
- priv = calendar->priv;
week_day = mrp_time_day_of_week (date);
if (priv->default_days[week_day] == mrp_day_get_use_base ()) {
@@ -310,13 +259,11 @@ calendar_get_default_day (MrpCalendar *calendar, mrptime date, gboolean derive)
static MrpDay *
calendar_get_day (MrpCalendar *calendar, mrptime date, gboolean derive)
{
- MrpCalendarPriv *priv;
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
MrpDay *day;
g_return_val_if_fail (MRP_IS_CALENDAR (calendar), 0);
- priv = calendar->priv;
-
day = (MrpDay *) g_hash_table_lookup (priv->days,
GINT_TO_POINTER ((int)date));
if (!day) {
@@ -333,11 +280,12 @@ calendar_get_day (MrpCalendar *calendar, mrptime date, gboolean derive)
static MrpCalendar *
calendar_new (const gchar *name, MrpCalendar *parent)
{
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (parent);
MrpCalendar *calendar;
calendar = g_object_new (MRP_TYPE_CALENDAR,
"name", name,
- "project", parent->priv->project,
+ "project", priv->project,
NULL);
calendar_add_child (parent, calendar);
@@ -348,27 +296,33 @@ calendar_new (const gchar *name, MrpCalendar *parent)
static void
calendar_add_child (MrpCalendar *parent, MrpCalendar *child)
{
- if (child->priv->project != parent->priv->project) {
+ MrpCalendarPrivate *parent_priv = mrp_calendar_get_instance_private (parent);
+ MrpCalendarPrivate *child_priv = mrp_calendar_get_instance_private (child);
+
+ if (child_priv->project != parent_priv->project) {
g_warning ("Trying to add child calendar from different project than the parent calendar");
return;
}
- parent->priv->children = g_list_prepend (parent->priv->children,
+ parent_priv->children = g_list_prepend (parent_priv->children,
g_object_ref (child));
- child->priv->parent = parent;
+ child_priv->parent = parent;
}
static void
calendar_reparent (MrpCalendar *new_parent, MrpCalendar *child)
{
- if (child->priv->parent) {
+ MrpCalendarPrivate *child_priv = mrp_calendar_get_instance_private (child);
+
+ if (child_priv->parent) {
MrpCalendar *parent;
- parent = child->priv->parent;
- parent->priv->children = g_list_remove (parent->priv->children,
+ parent = child_priv->parent;
+ MrpCalendarPrivate *old_parent_priv = mrp_calendar_get_instance_private (parent);
+ old_parent_priv->children = g_list_remove (old_parent_priv->children,
child);
- child->priv->parent = NULL;
+ child_priv->parent = NULL;
}
calendar_add_child (new_parent, child);
@@ -404,13 +358,14 @@ foreach_copy_day_intervals (gpointer key,
gpointer value,
MrpCalendar *copy)
{
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (copy);
MrpDay *day = key;
GList *list;
list = g_list_copy (value);
g_list_foreach (list, (GFunc) mrp_interval_ref, NULL);
- g_hash_table_insert (copy->priv->day_intervals, day, list);
+ g_hash_table_insert (priv->day_intervals, day, list);
}
static void
@@ -418,9 +373,11 @@ foreach_copy_days (gpointer key,
gpointer value,
MrpCalendar *copy)
{
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (copy);
+
MrpDay *day = value;
- g_hash_table_insert (copy->priv->days, key, mrp_day_ref (day));
+ g_hash_table_insert (priv->days, key, mrp_day_ref (day));
}
/**
@@ -433,10 +390,12 @@ foreach_copy_days (gpointer key,
void
mrp_calendar_add (MrpCalendar *calendar, MrpCalendar *parent)
{
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
+
calendar_add_child (parent, calendar);
- imrp_project_signal_calendar_tree_changed (calendar->priv->project);
- imrp_project_set_needs_saving (calendar->priv->project, TRUE);
+ imrp_project_signal_calendar_tree_changed (priv->project);
+ imrp_project_set_needs_saving (priv->project, TRUE);
}
/**
@@ -452,26 +411,28 @@ mrp_calendar_add (MrpCalendar *calendar, MrpCalendar *parent)
MrpCalendar *
mrp_calendar_copy (const gchar *name, MrpCalendar *calendar)
{
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
MrpCalendar *parent, *ret_val;
- parent = mrp_project_get_root_calendar (calendar->priv->project);
+ parent = mrp_project_get_root_calendar (priv->project);
ret_val = calendar_new (name, parent);
+ MrpCalendarPrivate *ret_val_priv = mrp_calendar_get_instance_private (ret_val);
- memcpy (ret_val->priv->default_days,
- calendar->priv->default_days,
+ memcpy (ret_val_priv->default_days,
+ priv->default_days,
7 * sizeof (MrpDay *));
- g_hash_table_foreach (calendar->priv->day_intervals,
+ g_hash_table_foreach (priv->day_intervals,
(GHFunc) foreach_copy_day_intervals,
ret_val);
- g_hash_table_foreach (calendar->priv->days,
+ g_hash_table_foreach (priv->days,
(GHFunc) foreach_copy_days,
ret_val);
- imrp_project_signal_calendar_tree_changed (calendar->priv->project);
- imrp_project_set_needs_saving (calendar->priv->project, TRUE);
+ imrp_project_signal_calendar_tree_changed (priv->project);
+ imrp_project_set_needs_saving (priv->project, TRUE);
return ret_val;
}
@@ -496,13 +457,14 @@ mrp_calendar_derive (const gchar *name, MrpCalendar *parent)
g_return_val_if_fail (MRP_IS_CALENDAR (parent), NULL);
ret_val = calendar_new (name, parent);
+ MrpCalendarPrivate *ret_val_priv = mrp_calendar_get_instance_private (ret_val);
for (i = 0; i < 7; ++i) {
- ret_val->priv->default_days[i] = mrp_day_get_use_base ();
+ ret_val_priv->default_days[i] = mrp_day_get_use_base ();
}
- imrp_project_signal_calendar_tree_changed (ret_val->priv->project);
- imrp_project_set_needs_saving (ret_val->priv->project, TRUE);
+ imrp_project_signal_calendar_tree_changed (ret_val_priv->project);
+ imrp_project_set_needs_saving (ret_val_priv->project, TRUE);
return ret_val;
}
@@ -519,13 +481,15 @@ mrp_calendar_derive (const gchar *name, MrpCalendar *parent)
void
mrp_calendar_reparent (MrpCalendar *new_parent, MrpCalendar *child)
{
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (new_parent);
+
g_return_if_fail (MRP_IS_CALENDAR (new_parent));
g_return_if_fail (MRP_IS_CALENDAR (child));
calendar_reparent (new_parent, child);
- imrp_project_signal_calendar_tree_changed (new_parent->priv->project);
- imrp_project_set_needs_saving (new_parent->priv->project, TRUE);
+ imrp_project_signal_calendar_tree_changed (priv->project);
+ imrp_project_set_needs_saving (priv->project, TRUE);
}
/**
@@ -542,7 +506,7 @@ mrp_calendar_reparent (MrpCalendar *new_parent, MrpCalendar *child)
void
mrp_calendar_remove (MrpCalendar *calendar)
{
- MrpCalendarPriv *priv;
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
MrpCalendar *parent;
MrpCalendar *root;
GList *list, *l;
@@ -551,7 +515,6 @@ mrp_calendar_remove (MrpCalendar *calendar)
g_return_if_fail (MRP_IS_CALENDAR (calendar));
- priv = calendar->priv;
parent = priv->parent;
root = mrp_project_get_root_calendar (priv->project);
@@ -615,21 +578,22 @@ mrp_calendar_remove (MrpCalendar *calendar)
for (l = list; l; l = l->next) {
MrpCalendar *child = l->data;
+ MrpCalendarPrivate *child_priv = mrp_calendar_get_instance_private (child);
if (parent) {
calendar_reparent (parent, child);
} else {
/* FIXME: Should never happen, right? */
g_warning ("No new parent.");
- child->priv->parent = NULL;
+ child_priv->parent = NULL;
}
}
g_list_free (list);
if (parent) {
- parent->priv->children = g_list_remove (parent->priv->children,
- calendar);
+ priv->children = g_list_remove (priv->children,
+ calendar);
priv->parent = NULL;
}
@@ -650,9 +614,11 @@ mrp_calendar_remove (MrpCalendar *calendar)
const gchar *
mrp_calendar_get_name (MrpCalendar *calendar)
{
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
+
g_return_val_if_fail (MRP_IS_CALENDAR (calendar), "");
- return calendar->priv->name;
+ return priv->name;
}
/**
@@ -666,13 +632,11 @@ mrp_calendar_get_name (MrpCalendar *calendar)
void
mrp_calendar_set_name (MrpCalendar *calendar, const gchar *name)
{
- MrpCalendarPriv *priv;
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
g_return_if_fail (MRP_IS_CALENDAR (calendar));
g_return_if_fail (name != NULL);
- priv = calendar->priv;
-
g_free (priv->name);
priv->name = g_strdup (name);
}
@@ -691,13 +655,11 @@ mrp_calendar_day_set_intervals (MrpCalendar *calendar,
MrpDay *day,
GList *intervals)
{
- MrpCalendarPriv *priv;
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
GList *list;
g_return_if_fail (MRP_IS_CALENDAR (calendar));
- priv = calendar->priv;
-
list = g_hash_table_lookup (priv->day_intervals, day);
if (list) {
g_list_foreach (list, (GFunc) mrp_interval_unref, NULL);
@@ -733,17 +695,15 @@ mrp_calendar_day_get_intervals (MrpCalendar *calendar,
MrpDay *day,
gboolean check_ancestors)
{
- MrpCalendarPriv *priv;
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
GList *list = NULL;
g_return_val_if_fail (MRP_IS_CALENDAR (calendar), NULL);
- priv = calendar->priv;
-
/* Look upwards in the tree structure until we find a calendar that has
* defined the working time intervals for this day type.
*/
- list = g_hash_table_lookup (calendar->priv->day_intervals, day);
+ list = g_hash_table_lookup (priv->day_intervals, day);
if (!list && check_ancestors && priv->parent) {
return mrp_calendar_day_get_intervals (priv->parent, day, TRUE);
@@ -798,12 +758,10 @@ MrpDay *
mrp_calendar_get_default_day (MrpCalendar *calendar,
gint week_day)
{
- MrpCalendarPriv *priv;
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
g_return_val_if_fail (MRP_IS_CALENDAR (calendar), NULL);
- priv = calendar->priv;
-
return priv->default_days[week_day];
}
@@ -822,13 +780,11 @@ mrp_calendar_set_default_days (MrpCalendar *calendar,
gint week_day,
...)
{
- MrpCalendarPriv *priv;
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
va_list args;
g_return_if_fail (MRP_IS_CALENDAR (calendar));
- priv = calendar->priv;
-
va_start (args, week_day);
/* Loop the args */
@@ -864,14 +820,13 @@ mrp_calendar_set_days (MrpCalendar *calendar,
mrptime date,
...)
{
- MrpCalendarPriv *priv;
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
mrptime time;
gint key;
va_list args;
g_return_if_fail (MRP_IS_CALENDAR (calendar));
- priv = calendar->priv;
va_start (args, date);
for (time = date; time != -1; time = va_arg (args, mrptime)) {
@@ -910,9 +865,11 @@ mrp_calendar_set_days (MrpCalendar *calendar,
MrpCalendar *
mrp_calendar_get_parent (MrpCalendar *calendar)
{
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
+
g_return_val_if_fail (MRP_IS_CALENDAR (calendar), NULL);
- return calendar->priv->parent;
+ return priv->parent;
}
/**
@@ -927,9 +884,11 @@ mrp_calendar_get_parent (MrpCalendar *calendar)
GList *
mrp_calendar_get_children (MrpCalendar *calendar)
{
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
+
g_return_val_if_fail (MRP_IS_CALENDAR (calendar), NULL);
- return calendar->priv->children;
+ return priv->children;
}
/**
@@ -1126,13 +1085,11 @@ foreach_day_interval_add_to_list (MrpDay *day,
GList *
mrp_calendar_get_overridden_days (MrpCalendar *calendar)
{
- MrpCalendarPriv *priv;
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
GList *ret_val = NULL;
g_return_val_if_fail (MRP_IS_CALENDAR (calendar), NULL);
- priv = calendar->priv;
-
g_hash_table_foreach (priv->day_intervals,
(GHFunc) foreach_day_interval_add_to_list,
&ret_val);
@@ -1163,13 +1120,11 @@ foreach_day_add_to_list (gpointer key, MrpDay *day, GList **list)
GList *
mrp_calendar_get_all_overridden_dates (MrpCalendar *calendar)
{
- MrpCalendarPriv *priv;
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
GList *ret_val = NULL;
g_return_val_if_fail (MRP_IS_CALENDAR (calendar), NULL);
- priv = calendar->priv;
-
g_hash_table_foreach (priv->days,
(GHFunc) foreach_day_add_to_list,
&ret_val);
@@ -1197,7 +1152,7 @@ imrp_calendar_replace_day (MrpCalendar *calendar,
MrpDay *orig_day,
MrpDay *new_day)
{
- MrpCalendarPriv *priv;
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
MatchingDayData data;
GList *l;
gint i;
@@ -1206,8 +1161,6 @@ imrp_calendar_replace_day (MrpCalendar *calendar,
g_return_if_fail (orig_day != NULL);
g_return_if_fail (new_day != NULL);
- priv = calendar->priv;
-
/* Default week. */
for (i = 0; i < 7; i++) {
if (priv->default_days[i] == orig_day) {
@@ -1238,11 +1191,9 @@ imrp_calendar_replace_day (MrpCalendar *calendar,
static void
calendar_emit_changed (MrpCalendar *calendar)
{
- MrpCalendarPriv *priv;
+ MrpCalendarPrivate *priv = mrp_calendar_get_instance_private (calendar);
GList *l;
- priv = calendar->priv;
-
g_signal_emit (calendar, signals[CALENDAR_CHANGED], 0, NULL);
for (l = priv->children; l; l = l->next) {
diff --git a/libplanner/mrp-calendar.h b/libplanner/mrp-calendar.h
index 8bf9ce15..f313a567 100644
--- a/libplanner/mrp-calendar.h
+++ b/libplanner/mrp-calendar.h
@@ -20,8 +20,7 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __MRP_CALENDAR_H__
-#define __MRP_CALENDAR_H__
+#pragma once
#include <glib-object.h>
#include <time.h>
@@ -30,12 +29,11 @@
#include <libplanner/mrp-types.h>
#include <libplanner/mrp-time.h>
+G_BEGIN_DECLS
+
#define MRP_TYPE_CALENDAR (mrp_calendar_get_type ())
-#define MRP_CALENDAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MRP_TYPE_CALENDAR, MrpCalendar))
-#define MRP_CALENDAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MRP_TYPE_CALENDAR,
MrpCalendarClass))
-#define MRP_IS_CALENDAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MRP_TYPE_CALENDAR))
-#define MRP_IS_CALENDAR_CLASS(klass) (G_TYPE_CHECK_TYPE ((obj), MRP_TYPE_CALENDAR))
-#define MRP_CALENDAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MRP_TYPE_CALENDAR,
MrpCalendarClass))
+
+G_DECLARE_FINAL_TYPE (MrpCalendar, mrp_calendar, MRP, CALENDAR, MrpObject)
#define MRP_TYPE_INTERVAL (mrp_interval_get_type ())
@@ -44,9 +42,8 @@
*
* Object representing a calendar in the project.
*/
-typedef struct _MrpCalendar MrpCalendar;
-typedef struct _MrpCalendarClass MrpCalendarClass;
-typedef struct _MrpCalendarPriv MrpCalendarPriv;
+
+
/**
* MrpInterval:
*
@@ -86,16 +83,6 @@ typedef struct {
MrpDay *day;
} MrpDateWithDay;
-struct _MrpCalendar {
- MrpObject parent;
-
- MrpCalendarPriv *priv;
-};
-
-struct _MrpCalendarClass {
- MrpObjectClass parent_class;
-};
-
enum {
MRP_CALENDAR_DAY_SUN,
MRP_CALENDAR_DAY_MON,
@@ -106,7 +93,6 @@ enum {
MRP_CALENDAR_DAY_SAT
};
-GType mrp_calendar_get_type (void) G_GNUC_CONST;
MrpCalendar *mrp_calendar_new (const gchar *name,
MrpProject *project);
void mrp_calendar_add (MrpCalendar *calendar,
@@ -162,4 +148,4 @@ void mrp_interval_set_absolute (MrpInterval *interval,
mrptime end);
-#endif /* __MRP_CALENDAR_H__ */
+G_END_DECLS
diff --git a/libplanner/mrp-group.c b/libplanner/mrp-group.c
index 63ad1ffe..ba19ae87 100644
--- a/libplanner/mrp-group.c
+++ b/libplanner/mrp-group.c
@@ -42,12 +42,18 @@
#include <glib/gi18n.h>
#include "mrp-group.h"
-struct _MrpGroupPriv {
+struct _MrpGroup {
+ MrpObject parent_instance;
+};
+
+typedef struct {
gchar *name;
gchar *manager_name;
gchar *manager_phone;
gchar *manager_email;
-};
+} MrpGroupPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (MrpGroup, mrp_group, MRP_TYPE_OBJECT)
/* Properties */
enum {
@@ -58,115 +64,11 @@ enum {
PROP_MANAGER_EMAIL
};
-
-static void group_class_init (MrpGroupClass *klass);
-static void group_init (MrpGroup *group);
-static void group_finalize (GObject *object);
-static void group_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void group_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-
-static MrpObjectClass *parent_class;
-
-
-GType
-mrp_group_get_type (void)
-{
- static GType object_type = 0;
-
- if (!object_type) {
- static const GTypeInfo object_info = {
- sizeof (MrpGroupClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) group_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (MrpGroup),
- 0, /* n_preallocs */
- (GInstanceInitFunc) group_init,
- };
-
- object_type = g_type_register_static (MRP_TYPE_OBJECT,
- "MrpGroup",
- &object_info, 0);
- }
-
- return object_type;
-}
-
-static void
-group_class_init (MrpGroupClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- parent_class = MRP_OBJECT_CLASS (g_type_class_peek_parent (klass));
-
- object_class->finalize = group_finalize;
- object_class->set_property = group_set_property;
- object_class->get_property = group_get_property;
-
- g_object_class_install_property (object_class,
- PROP_NAME,
- g_param_spec_string ("name",
- "Name",
- "Name of the group",
- "empty",
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_MANAGER_NAME,
- g_param_spec_string ("manager_name",
- "Manager Name",
- "The name of the group manager",
- "empty",
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_MANAGER_PHONE,
- g_param_spec_string ("manager_phone",
- "Manager Phone",
- "The phone number of the group manager",
- "empty",
- G_PARAM_READWRITE));
-
- g_object_class_install_property (object_class,
- PROP_MANAGER_EMAIL,
- g_param_spec_string ("manager_email",
- "Manager Email",
- "The email address of the group manager",
- "empty",
- G_PARAM_READWRITE));
-
-}
-
-
-static void
-group_init (MrpGroup *group)
-{
- MrpGroupPriv *priv;
-
- priv = g_new0 (MrpGroupPriv, 1);
-
- priv->name = g_strdup ("");
- priv->manager_name = g_strdup ("");
- priv->manager_phone = g_strdup ("");
- priv->manager_email = g_strdup ("");
-
- group->priv = priv;
-}
-
static void
-group_finalize (GObject *object)
+mrp_group_finalize (GObject *object)
{
MrpGroup *group = MRP_GROUP (object);
- MrpGroupPriv *priv;
-
- priv = group->priv;
+ MrpGroupPrivate *priv = mrp_group_get_instance_private (group);
g_free (priv->name);
priv->name = NULL;
@@ -180,26 +82,24 @@ group_finalize (GObject *object)
g_free (priv->manager_email);
priv->manager_email = NULL;
- if (G_OBJECT_CLASS (parent_class)->finalize) {
- (* G_OBJECT_CLASS (parent_class)->finalize) (object);
- }
+ G_OBJECT_CLASS (mrp_group_parent_class)->finalize (object);
}
static void
-group_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+mrp_group_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
MrpGroup *group;
- MrpGroupPriv *priv;
+ MrpGroupPrivate *priv;
gboolean changed = FALSE;
const gchar *str;
g_return_if_fail (MRP_IS_GROUP (object));
group = MRP_GROUP (object);
- priv = group->priv;
+ priv = mrp_group_get_instance_private (group);
switch (prop_id) {
case PROP_NAME:
@@ -251,18 +151,18 @@ group_set_property (GObject *object,
}
static void
-group_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+mrp_group_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
MrpGroup *group;
- MrpGroupPriv *priv;
+ MrpGroupPrivate *priv;
g_return_if_fail (MRP_IS_GROUP (object));
group = MRP_GROUP (object);
- priv = group->priv;
+ priv = mrp_group_get_instance_private (group);
switch (prop_id) {
case PROP_NAME:
@@ -283,6 +183,60 @@ group_get_property (GObject *object,
}
}
+
+static void
+mrp_group_class_init (MrpGroupClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = mrp_group_finalize;
+ object_class->set_property = mrp_group_set_property;
+ object_class->get_property = mrp_group_get_property;
+
+ g_object_class_install_property (object_class,
+ PROP_NAME,
+ g_param_spec_string ("name",
+ "Name",
+ "Name of the group",
+ "empty",
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_MANAGER_NAME,
+ g_param_spec_string ("manager_name",
+ "Manager Name",
+ "The name of the group manager",
+ "empty",
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_MANAGER_PHONE,
+ g_param_spec_string ("manager_phone",
+ "Manager Phone",
+ "The phone number of the group manager",
+ "empty",
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_MANAGER_EMAIL,
+ g_param_spec_string ("manager_email",
+ "Manager Email",
+ "The email address of the group manager",
+ "empty",
+ G_PARAM_READWRITE));
+
+}
+
+
+static void
+mrp_group_init (MrpGroup *group)
+{
+ MrpGroupPrivate *priv = mrp_group_get_instance_private (group);
+
+ priv->name = g_strdup ("");
+ priv->manager_name = g_strdup ("");
+ priv->manager_phone = g_strdup ("");
+ priv->manager_email = g_strdup ("");
+}
+
/**
* mrp_group_new:
*
@@ -313,9 +267,11 @@ mrp_group_new (void)
const gchar *
mrp_group_get_name (MrpGroup *group)
{
+ MrpGroupPrivate *priv = mrp_group_get_instance_private (group);
+
g_return_val_if_fail (MRP_IS_GROUP (group), NULL);
- return group->priv->name;
+ return priv->name;
}
/**
diff --git a/libplanner/mrp-group.h b/libplanner/mrp-group.h
index 6e618dec..551ed659 100644
--- a/libplanner/mrp-group.h
+++ b/libplanner/mrp-group.h
@@ -20,36 +20,19 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __MRP_GROUP_H__
-#define __MRP_GROUP_H__
+#pragma once
#include <libplanner/mrp-object.h>
#include <libplanner/mrp-types.h>
-#define MRP_TYPE_GROUP (mrp_group_get_type ())
-#define MRP_GROUP(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MRP_TYPE_GROUP, MrpGroup))
-#define MRP_GROUP_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MRP_TYPE_GROUP, MrpGroupClass))
-#define MRP_IS_GROUP(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MRP_TYPE_GROUP))
-#define MRP_IS_GROUP_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MRP_TYPE_GROUP))
-#define MRP_GROUP_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MRP_TYPE_GROUP, MrpGroupClass))
-
-typedef struct _MrpGroupClass MrpGroupClass;
-typedef struct _MrpGroupPriv MrpGroupPriv;
-
-struct _MrpGroup {
- MrpObject parent;
+G_BEGIN_DECLS
- MrpGroupPriv *priv;
-};
-
-struct _MrpGroupClass {
- MrpObjectClass parent_class;
-};
+#define MRP_TYPE_GROUP (mrp_group_get_type ())
-GType mrp_group_get_type (void) G_GNUC_CONST;
+G_DECLARE_FINAL_TYPE (MrpGroup, mrp_group, MRP, GROUP, MrpObject)
MrpGroup * mrp_group_new (void);
const gchar * mrp_group_get_name (MrpGroup *group);
void mrp_group_set_name (MrpGroup *group,
const gchar *name);
-#endif /* __MRP_GROUP_H__ */
+G_END_DECLS
diff --git a/libplanner/mrp-mpx.c b/libplanner/mrp-mpx.c
index daf33b89..053884d0 100644
--- a/libplanner/mrp-mpx.c
+++ b/libplanner/mrp-mpx.c
@@ -54,5 +54,5 @@ init (MrpFileModule *module, MrpApplication *application)
reader->read_string = mpx_read_string;
- imrp_application_register_reader (application, reader);
+ mrp_application_register_reader (application, reader);
}
diff --git a/libplanner/mrp-object.c b/libplanner/mrp-object.c
index 5c3704da..459d6559 100644
--- a/libplanner/mrp-object.c
+++ b/libplanner/mrp-object.c
@@ -57,11 +57,13 @@
#include "mrp-private.h"
#include "mrp-object.h"
-struct _MrpObjectPriv {
+typedef struct {
MrpProject *project;
guint id;
GHashTable *property_hash;
-};
+} MrpObjectPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (MrpObject, mrp_object, G_TYPE_OBJECT)
/* Signals */
enum {
@@ -77,62 +79,114 @@ enum {
};
-static GObjectClass *parent_class;
static guint signals[LAST_SIGNAL];
-static void object_class_init (MrpObjectClass *klass);
-static void object_init (MrpObject *object);
-static void object_finalize (GObject *g_object);
-static void object_set_g_property (GObject *g_object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void object_get_g_property (GObject *g_object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void object_property_removed_cb (MrpProject *project,
- MrpProperty *property,
- MrpObject *object);
-
-
-GType
-mrp_object_get_type (void)
+static void
+mrp_object_init (MrpObject *object)
+{
+ MrpObjectPrivate *priv = mrp_object_get_instance_private (object);
+
+ priv->id = mrp_application_get_unique_id ();
+ mrp_application_id_set_data (object, priv->id);
+
+ priv->property_hash = g_hash_table_new (NULL, NULL);
+}
+
+static void
+mrp_object_finalize (GObject *g_object)
{
- static GType object_type = 0;
-
- if (!object_type) {
- static const GTypeInfo object_info = {
- sizeof (MrpObjectClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) object_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (MrpObject),
- 0, /* n_preallocs */
- (GInstanceInitFunc) object_init,
- };
-
- object_type = g_type_register_static (G_TYPE_OBJECT,
- "MrpObject",
- &object_info, 0);
+ G_OBJECT_CLASS (mrp_object_parent_class)->finalize (g_object);
+}
+
+static void
+object_property_removed_cb (MrpProject *project,
+ MrpProperty *property,
+ MrpObject *object)
+{
+ MrpObjectPrivate *priv = mrp_object_get_instance_private (object);
+ GValue *value;
+
+ g_return_if_fail (MRP_IS_PROJECT (project));
+ g_return_if_fail (property != NULL);
+ g_return_if_fail (MRP_IS_OBJECT (object));
+
+ value = g_hash_table_lookup (priv->property_hash, property);
+
+ if (value) {
+ g_hash_table_steal (priv->property_hash, property);
+ g_value_unset (value);
+ g_free (value);
+ mrp_property_unref (property);
}
+}
- return object_type;
+
+static void
+mrp_object_set_g_property (GObject *g_object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ MrpObject *object = MRP_OBJECT (g_object);
+ MrpObjectPrivate *priv = mrp_object_get_instance_private (object);
+
+ g_return_if_fail (MRP_IS_OBJECT (g_object));
+
+ switch (prop_id) {
+ case PROP_PROJECT:
+ if (priv->project) {
+ g_signal_handlers_disconnect_by_func (priv->project,
+ G_CALLBACK (object_property_removed_cb),
+ object);
+ g_object_unref (priv->project);
+ }
+
+ priv->project = g_value_get_object (value);
+ if (priv->project) {
+ g_object_ref (priv->project);
+ g_signal_connect_object (priv->project,
+ "property_removed",
+ G_CALLBACK (object_property_removed_cb),
+ object,
+ G_CONNECT_AFTER);
+ }
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
-object_class_init (MrpObjectClass *klass)
+mrp_object_get_g_property (GObject *g_object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ MrpObject *object = MRP_OBJECT (g_object);
+ MrpObjectPrivate *priv = mrp_object_get_instance_private (object);
- parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
+ g_return_if_fail (MRP_IS_OBJECT (g_object));
- object_class->finalize = object_finalize;
- object_class->set_property = object_set_g_property;
- object_class->get_property = object_get_g_property;
+ switch (prop_id) {
+ case PROP_PROJECT:
+ g_value_set_object (value, priv->project);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+mrp_object_class_init (MrpObjectClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = mrp_object_finalize;
+ object_class->set_property = mrp_object_set_g_property;
+ object_class->get_property = mrp_object_get_g_property;
klass->removed = NULL;
@@ -183,28 +237,6 @@ object_class_init (MrpObjectClass *klass)
G_PARAM_READWRITE));
}
-static void
-object_init (MrpObject *object)
-{
- MrpObjectPriv *priv;
-
- priv = g_new0 (MrpObjectPriv, 1);
- object->priv = priv;
-
- priv->id = mrp_application_get_unique_id ();
- imrp_application_id_set_data (object, priv->id);
-
- priv->property_hash = g_hash_table_new (NULL, NULL);
-}
-
-static void
-object_finalize (GObject *g_object)
-{
- if (G_OBJECT_CLASS (parent_class)->finalize) {
- (* G_OBJECT_CLASS (parent_class)->finalize) (g_object);
- }
-}
-
/**
* mrp_object_set_property:
* @object: an #MrpObject
@@ -217,12 +249,11 @@ object_finalize (GObject *g_object)
void
mrp_object_set_property (MrpObject *object, MrpProperty *property, GValue *value)
{
- MrpObjectPriv *priv;
+ MrpObjectPrivate *priv = mrp_object_get_instance_private (object);
GValue *value_cpy;
GParamSpec *pspec;
GValue *tmp_value;
- priv = object->priv;
pspec = G_PARAM_SPEC (property);
value_cpy = g_new0 (GValue, 1);
@@ -263,11 +294,9 @@ mrp_object_set_property (MrpObject *object, MrpProperty *property, GValue *value
void
mrp_object_get_property (MrpObject *object, MrpProperty *property, GValue *value)
{
- MrpObjectPriv *priv;
+ MrpObjectPrivate *priv = mrp_object_get_instance_private (object);
GValue *tmp_value;
- priv = object->priv;
-
tmp_value = g_hash_table_lookup (priv->property_hash,
property);
@@ -280,93 +309,6 @@ mrp_object_get_property (MrpObject *object, MrpProperty *property, GValue *value
g_value_copy (tmp_value, value);
}
-static void
-object_set_g_property (GObject *g_object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MrpObject *object;
- MrpObjectPriv *priv;
-
- g_return_if_fail (MRP_IS_OBJECT (g_object));
-
- object = MRP_OBJECT (g_object);
- priv = object->priv;
-
- switch (prop_id) {
- case PROP_PROJECT:
- if (priv->project) {
- g_signal_handlers_disconnect_by_func (priv->project,
- G_CALLBACK (object_property_removed_cb),
- object);
- g_object_unref (priv->project);
- }
-
- priv->project = g_value_get_object (value);
- if (priv->project) {
- g_object_ref (priv->project);
- g_signal_connect_object (priv->project,
- "property_removed",
- G_CALLBACK (object_property_removed_cb),
- object,
- G_CONNECT_AFTER);
- }
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-object_get_g_property (GObject *g_object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MrpObject *object;
- MrpObjectPriv *priv;
-
- g_return_if_fail (MRP_IS_OBJECT (g_object));
-
- object = MRP_OBJECT (g_object);
- priv = object->priv;
-
- switch (prop_id) {
- case PROP_PROJECT:
- g_value_set_object (value, priv->project);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-object_property_removed_cb (MrpProject *project,
- MrpProperty *property,
- MrpObject *object)
-{
- MrpObjectPriv *priv;
- GValue *value;
-
- g_return_if_fail (MRP_IS_PROJECT (project));
- g_return_if_fail (property != NULL);
- g_return_if_fail (MRP_IS_OBJECT (object));
-
- priv = object->priv;
-
- value = g_hash_table_lookup (priv->property_hash, property);
-
- if (value) {
- g_hash_table_steal (priv->property_hash, property);
- g_value_unset (value);
- g_free (value);
- mrp_property_unref (property);
- }
-}
-
/**
* mrp_object_removed:
* @object: an #MrpObject
@@ -392,12 +334,10 @@ mrp_object_removed (MrpObject *object)
void
mrp_object_changed (MrpObject *object)
{
- MrpObjectPriv *priv;
+ MrpObjectPrivate *priv = mrp_object_get_instance_private (object);
g_return_if_fail (MRP_IS_OBJECT (object));
- priv = object->priv;
-
if (priv->project) {
imrp_project_set_needs_saving (priv->project, TRUE);
}
@@ -420,22 +360,23 @@ mrp_object_set (gpointer pobject,
...)
{
MrpObject *object = MRP_OBJECT (pobject);
+ MrpObjectPrivate *priv = mrp_object_get_instance_private (object);
va_list var_args;
gboolean blocked = FALSE;
g_return_if_fail (MRP_IS_OBJECT (object));
- if (object->priv->project) {
- blocked = mrp_project_get_block_scheduling (object->priv->project);
- mrp_project_set_block_scheduling (object->priv->project, TRUE);
+ if (priv->project) {
+ blocked = mrp_project_get_block_scheduling (priv->project);
+ mrp_project_set_block_scheduling (priv->project, TRUE);
}
va_start (var_args, first_property_name);
mrp_object_set_valist (object, first_property_name, var_args);
va_end (var_args);
- if (object->priv->project) {
- mrp_project_set_block_scheduling (object->priv->project, blocked);
+ if (priv->project) {
+ mrp_project_set_block_scheduling (priv->project, blocked);
}
}
@@ -476,13 +417,11 @@ mrp_object_set_valist (MrpObject *object,
const gchar *first_property_name,
va_list var_args)
{
- MrpObjectPriv *priv;
+ MrpObjectPrivate *priv = mrp_object_get_instance_private (object);
const gchar *name;
g_return_if_fail (MRP_IS_OBJECT (object));
- priv = object->priv;
-
g_object_ref (object);
name = first_property_name;
@@ -566,13 +505,11 @@ mrp_object_get_valist (MrpObject *object,
const gchar *first_property_name,
va_list var_args)
{
- MrpObjectPriv *priv;
+ MrpObjectPrivate *priv = mrp_object_get_instance_private (object);
const gchar *name;
g_return_if_fail (MRP_IS_OBJECT (object));
- priv = object->priv;
-
g_object_ref (object);
name = first_property_name;
@@ -644,12 +581,10 @@ mrp_object_get_valist (MrpObject *object,
GList *
mrp_object_get_properties (MrpObject *object)
{
- MrpObjectPriv *priv;
+ MrpObjectPrivate *priv = mrp_object_get_instance_private (object);
g_return_val_if_fail (MRP_IS_OBJECT (object), NULL);
- priv = object->priv;
-
return mrp_project_get_properties_from_type (priv->project,
G_OBJECT_TYPE (object));
}
@@ -665,12 +600,10 @@ mrp_object_get_properties (MrpObject *object)
guint
mrp_object_get_id (MrpObject *object)
{
- MrpObjectPriv *priv;
+ MrpObjectPrivate *priv = mrp_object_get_instance_private (object);
g_return_val_if_fail (MRP_IS_OBJECT (object), 0);
- priv = object->priv;
-
return priv->id;
}
@@ -689,13 +622,11 @@ gboolean
mrp_object_set_id (MrpObject *object,
guint id)
{
- MrpObjectPriv *priv;
+ MrpObjectPrivate *priv = mrp_object_get_instance_private (object);
g_return_val_if_fail (MRP_IS_OBJECT (object), FALSE);
- priv = object->priv;
-
- if (imrp_application_id_set_data (object, id)) {
+ if (mrp_application_id_set_data (object, id)) {
priv->id = id;
return TRUE;
} else {
@@ -713,11 +644,9 @@ mrp_object_set_id (MrpObject *object,
gpointer
mrp_object_get_project (MrpObject *object)
{
- MrpObjectPriv *priv;
+ MrpObjectPrivate *priv = mrp_object_get_instance_private (object);
g_return_val_if_fail (MRP_IS_OBJECT (object), FALSE);
- priv = object->priv;
-
return priv->project;
}
diff --git a/libplanner/mrp-object.h b/libplanner/mrp-object.h
index 525f66e1..50660585 100644
--- a/libplanner/mrp-object.h
+++ b/libplanner/mrp-object.h
@@ -20,34 +20,21 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __MRP_OBJECT_H__
-#define __MRP_OBJECT_H__
+#pragma once
#include <glib-object.h>
#include <libplanner/mrp-property.h>
+G_BEGIN_DECLS
+
#define MRP_TYPE_OBJECT (mrp_object_get_type ())
-#define MRP_OBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MRP_TYPE_OBJECT, MrpObject))
-#define MRP_OBJECT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MRP_TYPE_OBJECT, MrpObjectClass))
-#define MRP_IS_OBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MRP_TYPE_OBJECT))
-#define MRP_IS_OBJECT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MRP_TYPE_OBJECT))
-#define MRP_OBJECT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MRP_TYPE_OBJECT, MrpObjectClass))
+G_DECLARE_DERIVABLE_TYPE (MrpObject, mrp_object, MRP, OBJECT, GObject)
/**
* MrpObject:
*
* The base class for objects in libmrproject.
*/
-typedef struct _MrpObject MrpObject;
-typedef struct _MrpObjectClass MrpObjectClass;
-typedef struct _MrpObjectPriv MrpObjectPriv;
-
-struct _MrpObject {
- GObject parent;
-
- MrpObjectPriv *priv;
-};
-
struct _MrpObjectClass {
GObjectClass parent_class;
@@ -59,7 +46,6 @@ struct _MrpObjectClass {
};
-GType mrp_object_get_type (void) G_GNUC_CONST;
void mrp_object_removed (MrpObject *object);
void mrp_object_changed (MrpObject *object);
void mrp_object_set (gpointer object,
@@ -88,5 +74,4 @@ gboolean mrp_object_set_id (MrpObject *object,
/* FIXME: Sucks but we have a circular dependency. Could fix properly later. */
gpointer mrp_object_get_project (MrpObject *object);
-
-#endif /* __MRP_OBJECT_H__ */
+G_END_DECLS
diff --git a/libplanner/mrp-parser.c b/libplanner/mrp-parser.c
index 79098599..dc687dc7 100644
--- a/libplanner/mrp-parser.c
+++ b/libplanner/mrp-parser.c
@@ -45,7 +45,6 @@
/* WARNING: This code is a hack just to have a file loader/saver for the old
* format. Don't expect to understand any of the code or anything. It sucks.
*/
-
typedef struct {
xmlDocPtr doc;
diff --git a/libplanner/mrp-private.h b/libplanner/mrp-private.h
index 2ab16fe9..a9ddf35f 100644
--- a/libplanner/mrp-private.h
+++ b/libplanner/mrp-private.h
@@ -139,15 +139,15 @@ void imrp_property_set_project (MrpProperty *property,
/* MrpApplication functions. */
-GList * imrp_application_get_all_file_readers (MrpApplication *app);
-GList * imrp_application_get_all_file_writers (MrpApplication *app);
-void imrp_application_register_reader (MrpApplication *app,
+GList * mrp_application_get_all_file_readers (MrpApplication *app);
+GList * mrp_application_get_all_file_writers (MrpApplication *app);
+void mrp_application_register_reader (MrpApplication *app,
MrpFileReader *reader);
-void imrp_application_register_writer (MrpApplication *app,
+void mrp_application_register_writer (MrpApplication *app,
MrpFileWriter *writer);
-gboolean imrp_application_id_set_data (gpointer data,
+gboolean mrp_application_id_set_data (gpointer data,
guint data_id);
-gboolean imrp_application_id_remove_data (guint object_id);
+gboolean mrp_application_id_remove_data (guint object_id);
diff --git a/libplanner/mrp-project.c b/libplanner/mrp-project.c
index c7352c0c..18811f9c 100644
--- a/libplanner/mrp-project.c
+++ b/libplanner/mrp-project.c
@@ -870,7 +870,7 @@ mrp_project_load (MrpProject *project, const gchar *uri, GError **error)
mrp_task_manager_set_block_scheduling (priv->task_manager, TRUE);
- l = imrp_application_get_all_file_readers (priv->app);
+ l = mrp_application_get_all_file_readers (priv->app);
for (; l; l = l->next) {
MrpFileReader *reader = l->data;
@@ -1076,7 +1076,7 @@ mrp_project_export (MrpProject *project,
priv = project->priv;
- l = imrp_application_get_all_file_writers (priv->app);
+ l = mrp_application_get_all_file_writers (priv->app);
for (; l; l = l->next) {
MrpFileWriter *writer = l->data;
@@ -1086,7 +1086,7 @@ mrp_project_export (MrpProject *project,
}
}
- l = imrp_application_get_all_file_writers (priv->app);
+ l = mrp_application_get_all_file_writers (priv->app);
for (; l; l = l->next) {
MrpFileWriter *writer = l->data;
@@ -1134,7 +1134,7 @@ mrp_project_load_from_xml (MrpProject *project, const gchar *str, GError **error
mrp_task_manager_set_block_scheduling (priv->task_manager, TRUE);
- l = imrp_application_get_all_file_readers (priv->app);
+ l = mrp_application_get_all_file_readers (priv->app);
for (; l; l = l->next) {
MrpFileReader *reader = l->data;
diff --git a/libplanner/mrp-relation.c b/libplanner/mrp-relation.c
index f9c4c3ee..c773e4b2 100644
--- a/libplanner/mrp-relation.c
+++ b/libplanner/mrp-relation.c
@@ -39,15 +39,20 @@
#include "mrp-types.h"
#include "mrp-marshal.h"
#include "mrp-relation.h"
-#include "mrp-task.h"
-struct _MrpRelationPriv {
+struct _MrpRelation {
+ MrpObject parent_instance;
+};
+
+typedef struct {
MrpTask *successor;
MrpTask *predecessor;
MrpRelationType type;
gint lag;
-};
+} MrpRelationPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (MrpRelation, mrp_relation, MRP_TYPE_OBJECT)
/* Properties */
enum {
@@ -64,150 +69,33 @@ enum {
LAST_SIGNAL
};
-
-static void relation_class_init (MrpRelationClass *klass);
-static void relation_init (MrpRelation *relation);
-static void relation_finalize (GObject *object);
-static void relation_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void relation_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-static MrpObjectClass *parent_class;
static guint signals[LAST_SIGNAL];
-GType
-mrp_relation_get_type (void)
-{
- static GType object_type = 0;
-
- if (!object_type) {
- static const GTypeInfo object_info = {
- sizeof (MrpRelationClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) relation_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (MrpRelation),
- 0, /* n_preallocs */
- (GInstanceInitFunc) relation_init,
- };
-
- object_type = g_type_register_static (MRP_TYPE_OBJECT,
- "MrpRelation",
- &object_info, 0);
- }
-
- return object_type;
-}
-
-static void
-relation_class_init (MrpRelationClass *klass)
-{
- GObjectClass *object_class = (GObjectClass *) klass;
-
- parent_class = g_type_class_peek_parent (klass);
-
- object_class->finalize = relation_finalize;
- object_class->set_property = relation_set_property;
- object_class->get_property = relation_get_property;
-
- /**
- * MrpRelation::changed:
- * @relation: an #MrpRelation.
- *
- * emitted when @relation changes.
- */
- signals[CHANGED] = g_signal_new
- ("changed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0, /*G_STRUCT_OFFSET (MrpRelationClass, method), */
- NULL, NULL,
- mrp_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-
- /* Properties. */
- g_object_class_install_property (object_class,
- PROP_SUCCESSOR,
- g_param_spec_object ("successor",
- "Successor",
- "The successor in the relation",
- MRP_TYPE_TASK,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (object_class,
- PROP_PREDECESSOR,
- g_param_spec_object ("predecessor",
- "Predecessor",
- "The predecessor in the relation",
- MRP_TYPE_TASK,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property (object_class,
- PROP_TYPE,
- g_param_spec_enum ("type",
- "Type",
- "The type of relation",
- MRP_TYPE_RELATION_TYPE,
- MRP_RELATION_FS,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (object_class,
- PROP_LAG,
- g_param_spec_int ("lag",
- "Lag",
- "Lag between the predecessor and successor",
- -G_MAXINT, G_MAXINT, 0,
- G_PARAM_READWRITE));
-}
-
static void
-relation_init (MrpRelation *relation)
-{
- MrpRelationPriv *priv;
-
- relation->priv = g_new0 (MrpRelationPriv, 1);
-
- priv = relation->priv;
-
- priv->type = MRP_RELATION_FS;
- priv->lag = 0;
-}
-
-static void
-relation_finalize (GObject *object)
+mrp_relation_finalize (GObject *object)
{
MrpRelation *relation = MRP_RELATION (object);
+ MrpRelationPrivate *priv = mrp_relation_get_instance_private (relation);
- g_object_unref (relation->priv->successor);
- g_object_unref (relation->priv->predecessor);
+ g_object_unref (priv->successor);
+ g_object_unref (priv->predecessor);
- if (G_OBJECT_CLASS (parent_class)->finalize) {
- (* G_OBJECT_CLASS (parent_class)->finalize) (object);
- }
+ G_OBJECT_CLASS (mrp_relation_parent_class)->finalize (object);
}
static void
-relation_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+mrp_relation_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
MrpRelation *relation;
- MrpRelationPriv *priv;
+ MrpRelationPrivate *priv;
MrpTask *task;
gboolean changed = FALSE;
relation = MRP_RELATION (object);
- priv = relation->priv;
+ priv = mrp_relation_get_instance_private (relation);
switch (prop_id) {
case PROP_SUCCESSOR:
@@ -255,16 +143,16 @@ relation_set_property (GObject *object,
}
static void
-relation_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+mrp_relation_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
MrpRelation *relation;
- MrpRelationPriv *priv;
+ MrpRelationPrivate *priv;
relation = MRP_RELATION (object);
- priv = relation->priv;
+ priv = mrp_relation_get_instance_private (relation);
switch (prop_id) {
case PROP_SUCCESSOR:
@@ -289,6 +177,76 @@ relation_get_property (GObject *object,
}
}
+static void
+mrp_relation_class_init (MrpRelationClass *klass)
+{
+ GObjectClass *object_class = (GObjectClass *) klass;
+
+ object_class->finalize = mrp_relation_finalize;
+ object_class->set_property = mrp_relation_set_property;
+ object_class->get_property = mrp_relation_get_property;
+
+ /**
+ * MrpRelation::changed:
+ * @relation: an #MrpRelation.
+ *
+ * emitted when @relation changes.
+ */
+ signals[CHANGED] = g_signal_new
+ ("changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0, /*G_STRUCT_OFFSET (MrpRelationClass, method), */
+ NULL, NULL,
+ mrp_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ /* Properties. */
+ g_object_class_install_property (object_class,
+ PROP_SUCCESSOR,
+ g_param_spec_object ("successor",
+ "Successor",
+ "The successor in the relation",
+ MRP_TYPE_TASK,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class,
+ PROP_PREDECESSOR,
+ g_param_spec_object ("predecessor",
+ "Predecessor",
+ "The predecessor in the relation",
+ MRP_TYPE_TASK,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property (object_class,
+ PROP_TYPE,
+ g_param_spec_enum ("type",
+ "Type",
+ "The type of relation",
+ MRP_TYPE_RELATION_TYPE,
+ MRP_RELATION_FS,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_LAG,
+ g_param_spec_int ("lag",
+ "Lag",
+ "Lag between the predecessor and successor",
+ -G_MAXINT, G_MAXINT, 0,
+ G_PARAM_READWRITE));
+}
+
+static void
+mrp_relation_init (MrpRelation *relation)
+{
+ MrpRelationPrivate *priv = mrp_relation_get_instance_private (relation);
+
+ priv->type = MRP_RELATION_FS;
+ priv->lag = 0;
+}
+
/**
* mrp_relation_get_predecessor:
* @relation: an #MrpRelation
@@ -300,9 +258,11 @@ relation_get_property (GObject *object,
MrpTask *
mrp_relation_get_predecessor (MrpRelation *relation)
{
+ MrpRelationPrivate *priv = mrp_relation_get_instance_private (relation);
+
g_return_val_if_fail (MRP_IS_RELATION (relation), NULL);
- return relation->priv->predecessor;
+ return priv->predecessor;
}
/**
@@ -316,9 +276,11 @@ mrp_relation_get_predecessor (MrpRelation *relation)
MrpTask *
mrp_relation_get_successor (MrpRelation *relation)
{
+ MrpRelationPrivate *priv = mrp_relation_get_instance_private (relation);
+
g_return_val_if_fail (MRP_IS_RELATION (relation), NULL);
- return relation->priv->successor;
+ return priv->successor;
}
/**
@@ -332,9 +294,11 @@ mrp_relation_get_successor (MrpRelation *relation)
gint
mrp_relation_get_lag (MrpRelation *relation)
{
+ MrpRelationPrivate *priv = mrp_relation_get_instance_private (relation);
+
g_return_val_if_fail (MRP_IS_RELATION (relation), 0);
- return relation->priv->lag;
+ return priv->lag;
}
/**
@@ -349,7 +313,9 @@ mrp_relation_get_lag (MrpRelation *relation)
MrpRelationType
mrp_relation_get_relation_type (MrpRelation *relation)
{
+ MrpRelationPrivate *priv = mrp_relation_get_instance_private (relation);
+
g_return_val_if_fail (MRP_IS_RELATION (relation), MRP_RELATION_NONE);
- return relation->priv->type;
+ return priv->type;
}
diff --git a/libplanner/mrp-relation.h b/libplanner/mrp-relation.h
index b0fa2dcb..c3f5b087 100644
--- a/libplanner/mrp-relation.h
+++ b/libplanner/mrp-relation.h
@@ -20,47 +20,27 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __MRP_RELATION_H__
-#define __MRP_RELATION_H__
+#pragma once
#include <glib-object.h>
+#include <libplanner/mrp-object.h>
+#include <libplanner/mrp-task.h>
+
+G_BEGIN_DECLS
#define MRP_TYPE_RELATION (mrp_relation_get_type ())
-#define MRP_RELATION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MRP_TYPE_RELATION, MrpRelation))
-#define MRP_RELATION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MRP_TYPE_RELATION, MrpRelationClass))
-#define MRP_IS_RELATION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MRP_TYPE_RELATION))
-#define MRP_IS_RELATION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MRP_TYPE_RELATION))
-#define MRP_RELATION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MRP_TYPE_RELATION, MrpRelationClass))
+
+G_DECLARE_FINAL_TYPE (MrpRelation, mrp_relation, MRP, RELATION, MrpObject)
/**
* MrpRelation:
*
* Object representing a predecessor relation between two tasks.
*/
-typedef struct _MrpRelation MrpRelation;
-typedef struct _MrpRelationPriv MrpRelationPriv;
-
-#include <libplanner/mrp-task.h>
-
-struct _MrpRelation {
- MrpObject parent;
- MrpRelationPriv *priv;
-};
-
-typedef struct {
- MrpObjectClass parent_class;
-} MrpRelationClass;
-
-
-GType mrp_relation_get_type (void) G_GNUC_CONST;
MrpTask *mrp_relation_get_predecessor (MrpRelation *relation);
-
MrpTask *mrp_relation_get_successor (MrpRelation *relation);
-
gint mrp_relation_get_lag (MrpRelation *relation);
-
MrpRelationType mrp_relation_get_relation_type (MrpRelation *relation);
-
-#endif /* __MRP_RELATION_H__ */
+G_END_DECLS
diff --git a/libplanner/mrp-resource.c b/libplanner/mrp-resource.c
index 44ee8d65..ff1a13f9 100644
--- a/libplanner/mrp-resource.c
+++ b/libplanner/mrp-resource.c
@@ -60,8 +60,11 @@
#include "mrp-task.h"
#include "mrp-resource.h"
+struct _MrpResource {
+ MrpObject parent_instance;
+};
-struct _MrpResourcePriv {
+typedef struct {
gchar *name;
gchar *short_name;
MrpGroup *group;
@@ -73,7 +76,9 @@ struct _MrpResourcePriv {
MrpCalendar *calendar;
gfloat cost;
-};
+} MrpResourcePrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (MrpResource, mrp_resource, MRP_TYPE_OBJECT)
/* Properties */
enum {
@@ -97,204 +102,21 @@ enum {
};
-static void resource_class_init (MrpResourceClass *klass);
-static void resource_init (MrpResource *resource);
-static void resource_finalize (GObject *object);
-static void resource_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void resource_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
static void resource_calendar_changed (MrpCalendar *calendar,
MrpResource *resource);
-static void resource_removed (MrpObject *object);
static void resource_invalidate_task_costs (MrpResource *resource);
static void resource_assignment_removed_cb (MrpAssignment *assignment,
MrpResource *resource);
static void resource_group_removed_cb (MrpGroup *group,
MrpResource *resource);
-
-static MrpObjectClass *parent_class;
static guint signals[LAST_SIGNAL];
-
-GType
-mrp_resource_get_type (void)
-{
- static GType object_type = 0;
-
- if (!object_type) {
- static const GTypeInfo object_info = {
- sizeof (MrpResourceClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) resource_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (MrpResource),
- 0, /* n_preallocs */
- (GInstanceInitFunc) resource_init,
- };
-
- object_type = g_type_register_static (MRP_TYPE_OBJECT,
- "MrpResource",
- &object_info, 0);
- }
-
- return object_type;
-}
-
-static void
-resource_class_init (MrpResourceClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MrpObjectClass *mrp_object_class = MRP_OBJECT_CLASS (klass);
-
- parent_class = MRP_OBJECT_CLASS (g_type_class_peek_parent (klass));
-
- object_class->finalize = resource_finalize;
- object_class->set_property = resource_set_property;
- object_class->get_property = resource_get_property;
-
- mrp_object_class->removed = resource_removed;
-
- /* Properties */
- g_object_class_install_property (object_class,
- PROP_NAME,
- g_param_spec_string ("name",
- "Name",
- "The name of the resource",
- NULL,
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_SHORT_NAME,
- g_param_spec_string ("short_name",
- "Short name",
- "The shorter name, initials or nickname of the
resource",
- NULL,
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_GROUP,
- g_param_spec_object ("group",
- "Group",
- "The group that the resource belongs to",
- MRP_TYPE_GROUP,
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_TYPE,
- g_param_spec_int ("type",
- "Type",
- "The type of resource this is",
- MRP_RESOURCE_TYPE_NONE,
- MRP_RESOURCE_TYPE_MATERIAL,
- MRP_RESOURCE_TYPE_WORK,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (object_class,
- PROP_UNITS,
- g_param_spec_int ("units",
- "Units",
- "The amount of units this resource has",
- -1,
- G_MAXINT,
- 0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (object_class,
- PROP_EMAIL,
- g_param_spec_string ("email",
- "Email",
- "The email address of the resource",
- NULL,
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_NOTE,
- g_param_spec_string ("note",
- "Note",
- "Resource note",
- "",
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_CALENDAR,
- g_param_spec_pointer ("calendar",
- "Calendar",
- "The calendar this resource uses",
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_COST,
- g_param_spec_float ("cost",
- "Cost",
- "The standard cost of the resource",
- 0.0,
- G_MAXFLOAT,
- 0.0,
- G_PARAM_READWRITE));
-
- /* Signals */
-
- /**
- * MrpResource::assignment-added:
- * @resource: the object which received the signal.
- * @assignment: the added #MrpAssignment.
- *
- * emitted when @assignment is added.
- */
- signals[ASSIGNMENT_ADDED] =
- g_signal_new ("assignment_added",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- mrp_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1, MRP_TYPE_ASSIGNMENT);
-
- /**
- * MrpResource::assignment-removed:
- * @resource: the object which received the signal.
- * @assignment: the removed #MrpAssignment.
- *
- * emitted when @assignment is removed.
- */
- signals[ASSIGNMENT_REMOVED] =
- g_signal_new ("assignment_removed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- mrp_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1, MRP_TYPE_ASSIGNMENT);
-}
-
-static void
-resource_init (MrpResource *resource)
-{
- MrpResourcePriv *priv;
-
- priv = g_new0 (MrpResourcePriv, 1);
-
- priv->assignments = NULL;
- priv->type = MRP_RESOURCE_TYPE_NONE;
- priv->name = g_strdup ("");
- priv->short_name = g_strdup ("");
- priv->group = NULL;
- priv->email = g_strdup ("");
- priv->note = g_strdup ("");
- resource->priv = priv;
-}
-
static void
-resource_finalize (GObject *object)
+mrp_resource_finalize (GObject *object)
{
MrpResource *resource = MRP_RESOURCE (object);
- MrpResourcePriv *priv;
-
- priv = resource->priv;
+ MrpResourcePrivate *priv = mrp_resource_get_instance_private (resource);
g_free (priv->name);
g_free (priv->short_name);
@@ -307,22 +129,17 @@ resource_finalize (GObject *object)
g_object_unref (priv->calendar);
}
- g_free (priv);
- resource->priv = NULL;
-
- if (G_OBJECT_CLASS (parent_class)->finalize) {
- (* G_OBJECT_CLASS (parent_class)->finalize) (object);
- }
+ G_OBJECT_CLASS (mrp_resource_parent_class)->finalize (object);
}
static void
-resource_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+mrp_resource_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
MrpResource *resource;
- MrpResourcePriv *priv;
+ MrpResourcePrivate *priv;
gboolean changed = FALSE;
const gchar *str;
gint i_val;
@@ -332,7 +149,7 @@ resource_set_property (GObject *object,
MrpProject *project;
resource = MRP_RESOURCE (object);
- priv = resource->priv;
+ priv = mrp_resource_get_instance_private (resource);
switch (prop_id) {
case PROP_NAME:
@@ -466,16 +283,16 @@ resource_set_property (GObject *object,
}
static void
-resource_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+mrp_resource_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
MrpResource *resource;
- MrpResourcePriv *priv;
+ MrpResourcePrivate *priv;
resource = MRP_RESOURCE (object);
- priv = resource->priv;
+ priv = mrp_resource_get_instance_private (resource);
switch (prop_id) {
case PROP_NAME:
@@ -511,21 +328,6 @@ resource_get_property (GObject *object,
}
}
-static void
-resource_calendar_changed (MrpCalendar *calendar,
- MrpResource *resource)
-{
- MrpProject *project;
-
- project = mrp_object_get_project (MRP_OBJECT (resource));
-
- if (!project) {
- return;
- }
-
- mrp_project_reschedule (project);
-}
-
static void
resource_remove_assignment_foreach (MrpAssignment *assignment,
MrpResource *resource)
@@ -542,24 +344,15 @@ resource_remove_assignment_foreach (MrpAssignment *assignment,
}
static void
-resource_invalidate_task_cost_foreach (MrpAssignment *assignment,
- MrpResource *resource)
-{
- g_return_if_fail (MRP_IS_ASSIGNMENT (assignment));
-
- mrp_task_invalidate_cost (mrp_assignment_get_task (assignment));
-}
-
-static void
-resource_removed (MrpObject *object)
+mrp_resource_removed (MrpObject *object)
{
MrpResource *resource;
- MrpResourcePriv *priv;
+ MrpResourcePrivate *priv;
g_return_if_fail (MRP_IS_RESOURCE (object));
resource = MRP_RESOURCE (object);
- priv = resource->priv;
+ priv = mrp_resource_get_instance_private (resource);
g_list_foreach (priv->assignments,
(GFunc) resource_remove_assignment_foreach,
@@ -568,9 +361,166 @@ resource_removed (MrpObject *object)
g_list_free (priv->assignments);
priv->assignments = NULL;
- if (MRP_OBJECT_CLASS (parent_class)->removed) {
- (* MRP_OBJECT_CLASS (parent_class)->removed) (object);
- }
+ MRP_OBJECT_CLASS (mrp_resource_parent_class)->removed (object);
+}
+
+static void
+mrp_resource_class_init (MrpResourceClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ MrpObjectClass *mrp_object_class = MRP_OBJECT_CLASS (klass);
+
+ object_class->finalize = mrp_resource_finalize;
+ object_class->set_property = mrp_resource_set_property;
+ object_class->get_property = mrp_resource_get_property;
+
+ mrp_object_class->removed = mrp_resource_removed;
+
+ /* Properties */
+ g_object_class_install_property (object_class,
+ PROP_NAME,
+ g_param_spec_string ("name",
+ "Name",
+ "The name of the resource",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_SHORT_NAME,
+ g_param_spec_string ("short_name",
+ "Short name",
+ "The shorter name, initials or nickname of the
resource",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_GROUP,
+ g_param_spec_object ("group",
+ "Group",
+ "The group that the resource belongs to",
+ MRP_TYPE_GROUP,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_TYPE,
+ g_param_spec_int ("type",
+ "Type",
+ "The type of resource this is",
+ MRP_RESOURCE_TYPE_NONE,
+ MRP_RESOURCE_TYPE_MATERIAL,
+ MRP_RESOURCE_TYPE_WORK,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_UNITS,
+ g_param_spec_int ("units",
+ "Units",
+ "The amount of units this resource has",
+ -1,
+ G_MAXINT,
+ 0,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_EMAIL,
+ g_param_spec_string ("email",
+ "Email",
+ "The email address of the resource",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_NOTE,
+ g_param_spec_string ("note",
+ "Note",
+ "Resource note",
+ "",
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_CALENDAR,
+ g_param_spec_pointer ("calendar",
+ "Calendar",
+ "The calendar this resource uses",
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_COST,
+ g_param_spec_float ("cost",
+ "Cost",
+ "The standard cost of the resource",
+ 0.0,
+ G_MAXFLOAT,
+ 0.0,
+ G_PARAM_READWRITE));
+
+ /* Signals */
+
+ /**
+ * MrpResource::assignment-added:
+ * @resource: the object which received the signal.
+ * @assignment: the added #MrpAssignment.
+ *
+ * emitted when @assignment is added.
+ */
+ signals[ASSIGNMENT_ADDED] =
+ g_signal_new ("assignment_added",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ mrp_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1, MRP_TYPE_ASSIGNMENT);
+
+ /**
+ * MrpResource::assignment-removed:
+ * @resource: the object which received the signal.
+ * @assignment: the removed #MrpAssignment.
+ *
+ * emitted when @assignment is removed.
+ */
+ signals[ASSIGNMENT_REMOVED] =
+ g_signal_new ("assignment_removed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ mrp_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1, MRP_TYPE_ASSIGNMENT);
+}
+
+static void
+mrp_resource_init (MrpResource *resource)
+{
+ MrpResourcePrivate *priv = mrp_resource_get_instance_private (resource);
+
+ priv->assignments = NULL;
+ priv->type = MRP_RESOURCE_TYPE_NONE;
+ priv->name = g_strdup ("");
+ priv->short_name = g_strdup ("");
+ priv->group = NULL;
+ priv->email = g_strdup ("");
+ priv->note = g_strdup ("");
+}
+
+static void
+resource_calendar_changed (MrpCalendar *calendar,
+ MrpResource *resource)
+{
+ MrpProject *project;
+
+ project = mrp_object_get_project (MRP_OBJECT (resource));
+
+ if (!project) {
+ return;
+ }
+
+ mrp_project_reschedule (project);
+}
+
+static void
+resource_invalidate_task_cost_foreach (MrpAssignment *assignment,
+ MrpResource *resource)
+{
+ g_return_if_fail (MRP_IS_ASSIGNMENT (assignment));
+
+ mrp_task_invalidate_cost (mrp_assignment_get_task (assignment));
}
static void
@@ -587,14 +537,12 @@ static void
resource_assignment_removed_cb (MrpAssignment *assignment,
MrpResource *resource)
{
- MrpResourcePriv *priv;
- MrpTask *task;
+ MrpResourcePrivate *priv = mrp_resource_get_instance_private (resource);
+ MrpTask *task;
g_return_if_fail (MRP_IS_RESOURCE (resource));
g_return_if_fail (MRP_IS_ASSIGNMENT (assignment));
- priv = resource->priv;
-
task = mrp_assignment_get_task (assignment);
if (!task) {
@@ -616,7 +564,8 @@ resource_assignment_removed_cb (MrpAssignment *assignment,
static void
resource_invalidate_task_costs (MrpResource *resource)
{
- g_list_foreach (resource->priv->assignments,
+ MrpResourcePrivate *priv = mrp_resource_get_instance_private (resource);
+ g_list_foreach (priv->assignments,
(GFunc) resource_invalidate_task_cost_foreach,
resource);
}
@@ -633,13 +582,11 @@ resource_invalidate_task_costs (MrpResource *resource)
void
imrp_resource_add_assignment (MrpResource *resource, MrpAssignment *assignment)
{
- MrpResourcePriv *priv;
+ MrpResourcePrivate *priv = mrp_resource_get_instance_private (resource);
g_return_if_fail (MRP_IS_RESOURCE (resource));
g_return_if_fail (MRP_IS_ASSIGNMENT (assignment));
- priv = resource->priv;
-
priv->assignments = g_list_prepend (priv->assignments,
g_object_ref (assignment));
@@ -681,9 +628,11 @@ mrp_resource_new (void)
const gchar *
mrp_resource_get_name (MrpResource *resource)
{
+ MrpResourcePrivate *priv = mrp_resource_get_instance_private (resource);
+
g_return_val_if_fail (MRP_IS_RESOURCE (resource), NULL);
- return resource->priv->name;
+ return priv->name;
}
/**
@@ -711,9 +660,11 @@ void mrp_resource_set_name (MrpResource *resource, const gchar *name)
const gchar *
mrp_resource_get_short_name (MrpResource *resource)
{
+ MrpResourcePrivate *priv = mrp_resource_get_instance_private (resource);
+
g_return_val_if_fail (MRP_IS_RESOURCE (resource), NULL);
- return resource->priv->short_name;
+ return priv->short_name;
}
/**
@@ -774,9 +725,11 @@ mrp_resource_assign (MrpResource *resource,
GList *
mrp_resource_get_assignments (MrpResource *resource)
{
+ MrpResourcePrivate *priv = mrp_resource_get_instance_private (resource);
+
g_return_val_if_fail (MRP_IS_RESOURCE (resource), NULL);
- return resource->priv->assignments;
+ return priv->assignments;
}
/**
@@ -796,10 +749,11 @@ mrp_resource_get_assigned_tasks (MrpResource *resource)
GList *l;
MrpAssignment *assignment;
MrpTask *task;
+ MrpResourcePrivate *priv = mrp_resource_get_instance_private (resource);
g_return_val_if_fail (MRP_IS_RESOURCE (resource), NULL);
- for (l = resource->priv->assignments; l; l = l->next) {
+ for (l = priv->assignments; l; l = l->next) {
assignment = l->data;
task = mrp_assignment_get_task (assignment);
@@ -825,8 +779,10 @@ mrp_resource_get_assigned_tasks (MrpResource *resource)
gint
mrp_resource_compare (gconstpointer a, gconstpointer b)
{
- return strcmp (MRP_RESOURCE(a)->priv->name,
- MRP_RESOURCE(b)->priv->name);
+ MrpResourcePrivate *priv_a = mrp_resource_get_instance_private (MRP_RESOURCE ((gpointer)a));
+ MrpResourcePrivate *priv_b = mrp_resource_get_instance_private (MRP_RESOURCE ((gpointer)b));
+ return strcmp (priv_a->name,
+ priv_b->name);
}
/**
@@ -841,12 +797,10 @@ mrp_resource_compare (gconstpointer a, gconstpointer b)
MrpCalendar *
mrp_resource_get_calendar (MrpResource *resource)
{
- MrpResourcePriv *priv;
+ MrpResourcePrivate *priv = mrp_resource_get_instance_private (resource);
g_return_val_if_fail (MRP_IS_RESOURCE (resource), NULL);
- priv = resource->priv;
-
return priv->calendar;
}
diff --git a/libplanner/mrp-resource.h b/libplanner/mrp-resource.h
index 5e6f12e9..b55061d4 100644
--- a/libplanner/mrp-resource.h
+++ b/libplanner/mrp-resource.h
@@ -21,33 +21,17 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __MRP_RESOURCE_H__
-#define __MRP_RESOURCE_H__
+#pragma once
#include <libplanner/mrp-object.h>
#include <libplanner/mrp-task.h>
+#include <libplanner/mrp-calendar.h>
+G_BEGIN_DECLS
#define MRP_TYPE_RESOURCE (mrp_resource_get_type ())
-#define MRP_RESOURCE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MRP_TYPE_RESOURCE, MrpResource))
-#define MRP_RESOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MRP_TYPE_RESOURCE, MrpResourceClass))
-#define MRP_IS_RESOURCE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MRP_TYPE_RESOURCE))
-#define MRP_IS_RESOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MRP_TYPE_RESOURCE))
-#define MRP_RESOURCE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MRP_TYPE_RESOURCE, MrpResourceClass))
-
-typedef struct _MrpResourceClass MrpResourceClass;
-typedef struct _MrpResourcePriv MrpResourcePriv;
-
-#include <libplanner/mrp-calendar.h>
-
-struct _MrpResource {
- MrpObject parent;
- MrpResourcePriv *priv;
-};
-struct _MrpResourceClass {
- MrpObjectClass parent_class;
-};
+G_DECLARE_FINAL_TYPE (MrpResource, mrp_resource, MRP, RESOURCE, MrpObject)
/**
* MrpResourceType:
@@ -63,29 +47,22 @@ typedef enum {
MRP_RESOURCE_TYPE_MATERIAL
} MrpResourceType;
-GType mrp_resource_get_type (void) G_GNUC_CONST;
-MrpResource * mrp_resource_new (void);
-const gchar * mrp_resource_get_name (MrpResource *resource);
-void mrp_resource_set_name (MrpResource *resource,
- const gchar *name);
-const gchar * mrp_resource_get_short_name (MrpResource *resource);
-void mrp_resource_set_short_name (MrpResource *resource,
- const gchar *short_name);
-void mrp_resource_assign (MrpResource *resource,
- MrpTask *task,
- gint units);
-
-GList * mrp_resource_get_assignments (MrpResource *resource);
-
-GList * mrp_resource_get_assigned_tasks (MrpResource *resource);
-
-gint mrp_resource_compare (gconstpointer a,
- gconstpointer b);
-
-MrpCalendar * mrp_resource_get_calendar (MrpResource *resource);
-
-void mrp_resource_set_calendar (MrpResource *resource,
- MrpCalendar *calendar);
-
-
-#endif /* __MRP_RESOURCE_H__ */
+MrpResource *mrp_resource_new (void);
+const gchar *mrp_resource_get_name (MrpResource *resource);
+void mrp_resource_set_name (MrpResource *resource,
+ const gchar *name);
+const gchar *mrp_resource_get_short_name (MrpResource *resource);
+void mrp_resource_set_short_name (MrpResource *resource,
+ const gchar *short_name);
+void mrp_resource_assign (MrpResource *resource,
+ MrpTask *task,
+ gint units);
+GList *mrp_resource_get_assignments (MrpResource *resource);
+GList *mrp_resource_get_assigned_tasks (MrpResource *resource);
+gint mrp_resource_compare (gconstpointer a,
+ gconstpointer b);
+MrpCalendar *mrp_resource_get_calendar (MrpResource *resource);
+void mrp_resource_set_calendar (MrpResource *resource,
+ MrpCalendar *calendar);
+
+G_END_DECLS
diff --git a/libplanner/mrp-sql.c b/libplanner/mrp-sql.c
index 96538dff..9cbaa52d 100644
--- a/libplanner/mrp-sql.c
+++ b/libplanner/mrp-sql.c
@@ -30,6 +30,7 @@
#include <libgda/sql-parser/gda-sql-parser.h>
#include <libplanner/planner.h>
#include <libplanner/mrp-private.h>
+#include <libplanner/mrp-relation.h>
#include "mrp-storage-sql.h"
#include "mrp-sql.h"
diff --git a/libplanner/mrp-storage-module-factory.c b/libplanner/mrp-storage-module-factory.c
index 3d3e20ff..8fa82781 100644
--- a/libplanner/mrp-storage-module-factory.c
+++ b/libplanner/mrp-storage-module-factory.c
@@ -26,106 +26,80 @@
#include "mrp-storage-module-factory.h"
#include "mrp-storage-module.h"
-static void storage_module_factory_init (MrpStorageModuleFactory *factory);
-static void storage_module_factory_class_init (MrpStorageModuleFactoryClass *class);
-
-static gboolean storage_module_factory_load (GTypeModule *module);
-static void storage_module_factory_unload (GTypeModule *module);
-
-
static GHashTable *module_hash = NULL;
-static GTypeModuleClass *parent_class;
-
-GType
-mrp_storage_module_factory_get_type (void)
-{
- static GType object_type = 0;
-
- if (!object_type) {
- static const GTypeInfo object_info = {
- sizeof (MrpStorageModuleFactoryClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) storage_module_factory_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (MrpStorageModuleFactory),
- 0, /* n_preallocs */
- (GInstanceInitFunc) storage_module_factory_init,
- };
-
- object_type =
- g_type_register_static (G_TYPE_TYPE_MODULE,
- "MrpStorageModuleFactory",
- &object_info, 0);
- }
-
- return object_type;
-}
+typedef struct {
+ GModule *library;
+ gchar *name;
-static void
-storage_module_factory_init (MrpStorageModuleFactory *factory)
-{
-}
-
-static void
-storage_module_factory_class_init (MrpStorageModuleFactoryClass *klass)
-{
- /*GObjectClass *object_class = G_OBJECT_CLASS (klass);*/
- GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (klass);
+ /* Initialization and uninitialization. */
+ void (* init) (GTypeModule *module);
+ void (* exit) (MrpStorageModule *module);
+ MrpStorageModule *(* new) (void);
+} MrpStorageModuleFactoryPrivate;
- parent_class = G_TYPE_MODULE_CLASS (g_type_class_peek_parent (klass));
-
- module_class->load = storage_module_factory_load;
- module_class->unload = storage_module_factory_unload;
-}
+G_DEFINE_TYPE_WITH_PRIVATE (MrpStorageModuleFactory, mrp_storage_module_factory, G_TYPE_TYPE_MODULE)
static gboolean
-storage_module_factory_load (GTypeModule *module)
+mrp_storage_module_factory_load (GTypeModule *module)
{
MrpStorageModuleFactory *factory = MRP_STORAGE_MODULE_FACTORY (module);
+ MrpStorageModuleFactoryPrivate *priv = mrp_storage_module_factory_get_instance_private (factory);
- /*g_print ("Load '%s'\n", factory->name);*/
-
- factory->library = g_module_open (factory->name, 0);
- if (!factory->library) {
+ priv->library = g_module_open (priv->name, 0);
+ if (!priv->library) {
g_warning ("%s", g_module_error ());
return FALSE;
}
/* These must be implemented by all storage modules. */
- if (!g_module_symbol (factory->library, "module_init", (gpointer)&factory->init) ||
- !g_module_symbol (factory->library, "module_new", (gpointer)&factory->new) ||
- !g_module_symbol (factory->library, "module_exit", (gpointer)&factory->exit)) {
+ if (!g_module_symbol (priv->library, "module_init", (gpointer)&priv->init) ||
+ !g_module_symbol (priv->library, "module_new", (gpointer)&priv->new) ||
+ !g_module_symbol (priv->library, "module_exit", (gpointer)&priv->exit)) {
g_warning ("%s", g_module_error ());
- g_module_close (factory->library);
+ g_module_close (priv->library);
return FALSE;
}
- factory->init (module);
+ priv->init (module);
return TRUE;
}
static void
-storage_module_factory_unload (GTypeModule *module)
+mrp_storage_module_factory_unload (GTypeModule *module)
{
MrpStorageModuleFactory *factory = MRP_STORAGE_MODULE_FACTORY (module);
+ MrpStorageModuleFactoryPrivate *priv = mrp_storage_module_factory_get_instance_private (factory);
/*g_print ("Unload '%s'\n", factory->name);*/
/* FIXME: should pass the module here somehow. */
/*factory->exit (NULL); */
- g_module_close (factory->library);
- factory->library = NULL;
+ g_module_close (priv->library);
+ priv->library = NULL;
+
+ priv->init = NULL;
+ priv->exit = NULL;
+}
+
+static void
+mrp_storage_module_factory_class_init (MrpStorageModuleFactoryClass *klass)
+{
+ GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (klass);
+
+ module_class->load = mrp_storage_module_factory_load;
+ module_class->unload = mrp_storage_module_factory_unload;
+}
- factory->init = NULL;
- factory->exit = NULL;
+static void
+mrp_storage_module_factory_init (MrpStorageModuleFactory *factory)
+{
}
+
MrpStorageModuleFactory *
mrp_storage_module_factory_get (const gchar *name)
{
@@ -147,10 +121,11 @@ mrp_storage_module_factory_get (const gchar *name)
if (!factory) {
factory = g_object_new (MRP_TYPE_STORAGE_MODULE_FACTORY, NULL);
+ MrpStorageModuleFactoryPrivate *priv = mrp_storage_module_factory_get_instance_private
(factory);
g_type_module_set_name (G_TYPE_MODULE (factory), libname);
- factory->name = libname;
+ priv->name = libname;
- g_hash_table_insert (module_hash, factory->name, factory);
+ g_hash_table_insert (module_hash, priv->name, factory);
}
g_free (fullname);
@@ -166,8 +141,9 @@ MrpStorageModule *
mrp_storage_module_factory_create_module (MrpStorageModuleFactory *factory)
{
MrpStorageModule *module;
+ MrpStorageModuleFactoryPrivate *priv = mrp_storage_module_factory_get_instance_private (factory);
- module = factory->new ();
+ module = priv->new ();
return module;
}
diff --git a/libplanner/mrp-storage-module-factory.h b/libplanner/mrp-storage-module-factory.h
index 198645ee..a9f49f2f 100644
--- a/libplanner/mrp-storage-module-factory.h
+++ b/libplanner/mrp-storage-module-factory.h
@@ -20,50 +20,35 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __MRP_STORAGE_MODULE_FACTORY_H__
-#define __MRP_STORAGE_MODULE_FACTORY_H__
+#pragma once
#include <glib-object.h>
#include <gmodule.h>
#include <libplanner/mrp-storage-module.h>
#include <libplanner/mrp-project.h>
+G_BEGIN_DECLS
#define MRP_TYPE_STORAGE_MODULE_FACTORY (mrp_storage_module_factory_get_type ())
-#define MRP_STORAGE_MODULE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
MRP_TYPE_STORAGE_MODULE_FACTORY, MrpStorageModuleFactory))
-#define MRP_STORAGE_MODULE_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
MRP_TYPE_STORAGE_MODULE_FACTORY, MrpStorageModuleFactoryClass))
-#define MRP_IS_STORAGE_MODULE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
MRP_TYPE_STORAGE_MODULE_FACTORY))
-#define MRP_IS_STORAGE_MODULE_FACTORY_CLASS(klass) (G_TYPE_CHECK_TYPE ((obj),
MRP_TYPE_STORAGE_MODULE_FACTORY))
-#define MRP_STORAGE_MODULE_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
MRP_TYPE_STORAGE_MODULE_FACTORY, MrpStorageModuleFactoryClass))
+G_DECLARE_DERIVABLE_TYPE (MrpStorageModuleFactory, mrp_storage_module_factory, MRP, STORAGE_MODULE_FACTORY,
GTypeModule)
-typedef struct _MrpStorageModuleFactory MrpStorageModuleFactory;
-typedef struct _MrpStorageModuleFactoryClass MrpStorageModuleFactoryClass;
-
-struct _MrpStorageModuleFactory
+/*struct _MrpStorageModuleFactory
{
GTypeModule parent;
GModule *library;
gchar *name;
- /* Initialization and uninitialization. */
- void (* init) (GTypeModule *module);
- void (* exit) (MrpStorageModule *module);
- MrpStorageModule *(* new) (void);
-};
+};*/
struct _MrpStorageModuleFactoryClass
{
GTypeModuleClass parent_class;
};
-GType mrp_storage_module_factory_get_type (void) G_GNUC_CONST;
-
MrpStorageModuleFactory *mrp_storage_module_factory_get (const gchar *name);
MrpStorageModule *mrp_storage_module_factory_create_module (MrpStorageModuleFactory *factory);
-
-#endif /* __MRP_STORAGE_MODULE_FACTORY_H__ */
-
+G_END_DECLS
diff --git a/libplanner/mrp-storage-module.c b/libplanner/mrp-storage-module.c
index b39691fe..afebbd83 100644
--- a/libplanner/mrp-storage-module.c
+++ b/libplanner/mrp-storage-module.c
@@ -27,48 +27,17 @@
#include "mrp-project.h"
#include "mrp-private.h"
-static void storage_module_init (MrpStorageModule *module);
-static void storage_module_class_init (MrpStorageModuleClass *class);
+G_DEFINE_TYPE (MrpStorageModule, mrp_storage_module, G_TYPE_OBJECT)
-static GObjectClass *parent_class;
-
-GType
-mrp_storage_module_get_type (void)
-{
- static GType object_type = 0;
-
- if (!object_type) {
- static const GTypeInfo object_info = {
- sizeof (MrpStorageModuleClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) storage_module_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (MrpStorageModule),
- 0, /* n_preallocs */
- (GInstanceInitFunc) storage_module_init,
- };
-
- object_type = g_type_register_static (G_TYPE_OBJECT,
- "MrpStorageModule",
- &object_info, 0);
- }
-
- return object_type;
-}
static void
-storage_module_init (MrpStorageModule *module)
+mrp_storage_module_init (MrpStorageModule *module)
{
}
static void
-storage_module_class_init (MrpStorageModuleClass *klass)
+mrp_storage_module_class_init (MrpStorageModuleClass *klass)
{
- /*GObjectClass *object_class = G_OBJECT_CLASS (klass);*/
-
- parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
}
gboolean
diff --git a/libplanner/mrp-storage-module.h b/libplanner/mrp-storage-module.h
index 598df7ca..52e5ef14 100644
--- a/libplanner/mrp-storage-module.h
+++ b/libplanner/mrp-storage-module.h
@@ -21,32 +21,24 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __MRP_STORAGE_MODULE_H__
-#define __MRP_STORAGE_MODULE_H__
+#pragma once
#include <glib-object.h>
#include <libplanner/mrp-error.h>
#include <libplanner/mrp-project.h>
+G_BEGIN_DECLS
+
#define MRP_TYPE_STORAGE_MODULE (mrp_storage_module_get_type ())
+
+G_DECLARE_DERIVABLE_TYPE (MrpStorageModule, mrp_storage_module, MRP, STORAGE_MODULE, GObject)
+
#define MRP_STORAGE_MODULE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
MRP_TYPE_STORAGE_MODULE, MrpStorageModule))
#define MRP_STORAGE_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
MRP_TYPE_STORAGE_MODULE, MrpStorageModuleClass))
#define MRP_IS_STORAGE_MODULE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MRP_TYPE_STORAGE_MODULE))
#define MRP_IS_STORAGE_MODULE_CLASS(klass) (G_TYPE_CHECK_TYPE ((obj), MRP_TYPE_STORAGE_MODULE))
#define MRP_STORAGE_MODULE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MRP_TYPE_STORAGE_MODULE,
MrpStorageModuleClass))
-typedef struct _MrpStorageModule MrpStorageModule;
-typedef struct _MrpStorageModuleClass MrpStorageModuleClass;
-
-struct _MrpStorageModule
-{
- GObject parent;
-
- /* <private> */
-
- guint flags;
-};
-
struct _MrpStorageModuleClass
{
GObjectClass parent_class;
@@ -85,7 +77,6 @@ typedef enum {
MRP_STORAGE_SUPPORTS_PRIMARY)
} MrpStorageModuleFlags;
-GType mrp_storage_module_get_type (void) G_GNUC_CONST;
gboolean mrp_storage_module_load (MrpStorageModule *module,
const gchar *uri,
GError **error);
@@ -100,5 +91,4 @@ gboolean mrp_storage_module_from_xml (MrpStorageModule *module,
const gchar *str,
GError **error);
-
-#endif /* __MRP_STORAGE_MODULE_H__ */
+G_END_DECLS
diff --git a/libplanner/mrp-storage-mrproject.c b/libplanner/mrp-storage-mrproject.c
index 1a8faf72..aa6861bc 100644
--- a/libplanner/mrp-storage-mrproject.c
+++ b/libplanner/mrp-storage-mrproject.c
@@ -28,8 +28,8 @@
#include "mrp-storage-mrproject.h"
#include "mrp-parser.h"
-static void mpsm_init (MrpStorageMrproject *storage);
-static void mpsm_class_init (MrpStorageMrprojectClass *class);
+G_DEFINE_DYNAMIC_TYPE (MrpStorageMrproject, mrp_storage_mrproject, MRP_TYPE_STORAGE_MODULE)
+
static gboolean mpsm_load (MrpStorageModule *module,
const gchar *uri,
GError **error);
@@ -49,46 +49,16 @@ void module_init (GTypeModule *module);
MrpStorageModule *module_new (void *project);
void module_exit (void);
-
-
-static MrpStorageModuleClass *parent_class;
-GType mrp_storage_mrproject_type = 0;
-
-
-void
-mrp_storage_mrproject_register_type (GTypeModule *module)
-{
- static const GTypeInfo object_info = {
- sizeof (MrpStorageMrprojectClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) mpsm_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (MrpStorageMrproject),
- 0, /* n_preallocs */
- (GInstanceInitFunc) mpsm_init,
- };
-
- mrp_storage_mrproject_type = g_type_module_register_type (
- module,
- MRP_TYPE_STORAGE_MODULE,
- "MrpStorageMrproject",
- &object_info, 0);
-}
-
static void
-mpsm_init (MrpStorageMrproject *storage)
+mrp_storage_mrproject_init (MrpStorageMrproject *storage)
{
}
static void
-mpsm_class_init (MrpStorageMrprojectClass *klass)
+mrp_storage_mrproject_class_init (MrpStorageMrprojectClass *klass)
{
MrpStorageModuleClass *mrp_storage_module_class = MRP_STORAGE_MODULE_CLASS (klass);
- parent_class = MRP_STORAGE_MODULE_CLASS (g_type_class_peek_parent (klass));
-
mrp_storage_module_class->load = mpsm_load;
mrp_storage_module_class->save = mpsm_save;
mrp_storage_module_class->to_xml = mpsm_to_xml;
@@ -96,6 +66,11 @@ mpsm_class_init (MrpStorageMrprojectClass *klass)
mrp_storage_module_class->set_project = mpsm_set_project;
}
+static void
+mrp_storage_mrproject_class_finalize (MrpStorageMrprojectClass *klass)
+{
+}
+
G_MODULE_EXPORT void
module_init (GTypeModule *module)
{
diff --git a/libplanner/mrp-storage-mrproject.h b/libplanner/mrp-storage-mrproject.h
index acfcceb9..694a9c44 100644
--- a/libplanner/mrp-storage-mrproject.h
+++ b/libplanner/mrp-storage-mrproject.h
@@ -20,25 +20,18 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __MRP_STORAGE_MRPROJECT_H__
-#define __MRP_STORAGE_MRPROJECT_H__
+#pragma once
#include <glib-object.h>
#include "mrp-storage-module.h"
#include "mrp-types.h"
#include "mrp-project.h"
-extern GType mrp_storage_mrproject_type;
+G_BEGIN_DECLS
-#define MRP_TYPE_STORAGE_MRPROJECT mrp_storage_mrproject_type
-#define MRP_STORAGE_MRPROJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
MRP_TYPE_STORAGE_MRPROJECT, MrpStorageMrproject))
-#define MRP_STORAGE_MRPROJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
MRP_TYPE_STORAGE_MRPROJECT, MrpStorageMrprojectClass))
-#define MRP_IS_STORAGE_MRPROJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
MRP_TYPE_STORAGE_MRPROJECT))
-#define MRP_IS_STORAGE_MRPROJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), MRP_TYPE_STORAGE_MRPROJECT))
-#define MRP_STORAGE_MRPROJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
MRP_TYPE_STORAGE_MRPROJECT, MrpStorageMrprojectClass))
+#define MRP_TYPE_STORAGE_MRPROJECT (mrp_storage_mrproject_get_type ())
-typedef struct _MrpStorageMrproject MrpStorageMrproject;
-typedef struct _MrpStorageMrprojectClass MrpStorageMrprojectClass;
+G_DECLARE_FINAL_TYPE (MrpStorageMrproject, mrp_storage_mrproject, MRP, STORAGE_MRPROJECT, MrpStorageModule)
struct _MrpStorageMrproject
{
@@ -61,7 +54,4 @@ struct _MrpStorageMrprojectClass
MrpStorageModuleClass parent_class;
};
-
-void mrp_storage_mrproject_register_type (GTypeModule *module);
-
-#endif /* __MRP_STORAGE_MRPROJECT_H__ */
+G_END_DECLS
diff --git a/libplanner/mrp-storage-sql.c b/libplanner/mrp-storage-sql.c
index 1c448906..8e4985e1 100644
--- a/libplanner/mrp-storage-sql.c
+++ b/libplanner/mrp-storage-sql.c
@@ -31,8 +31,8 @@
#include "mrp-storage-sql.h"
#include "mrp-sql.h"
-static void storage_sql_init (MrpStorageSQL *storage);
-static void storage_sql_class_init (MrpStorageSQLClass *class);
+G_DEFINE_DYNAMIC_TYPE (MrpStorageSQL, mrp_storage_sql, MRP_TYPE_STORAGE_MODULE)
+
static gboolean storage_sql_load (MrpStorageModule *module,
const gchar *uri,
GError **error);
@@ -46,47 +46,17 @@ void module_init (GTypeModule *module);
MrpStorageModule *module_new (void *project);
void module_exit (void);
-
-
-static MrpStorageModuleClass *parent_class;
-GType mrp_storage_sql_type = 0;
-
-
-void
-mrp_storage_sql_register_type (GTypeModule *module)
-{
- static const GTypeInfo object_info = {
- sizeof (MrpStorageSQLClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) storage_sql_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (MrpStorageSQL),
- 0, /* n_preallocs */
- (GInstanceInitFunc) storage_sql_init,
- };
-
- mrp_storage_sql_type = g_type_module_register_type (
- module,
- MRP_TYPE_STORAGE_MODULE,
- "MrpStorageSQL",
- &object_info, 0);
-}
-
static void
-storage_sql_init (MrpStorageSQL *storage)
+mrp_storage_sql_init (MrpStorageSQL *storage)
{
mrp_sql_init();
}
static void
-storage_sql_class_init (MrpStorageSQLClass *klass)
+mrp_storage_sql_class_init (MrpStorageSQLClass *klass)
{
MrpStorageModuleClass *mrp_storage_module_class = MRP_STORAGE_MODULE_CLASS (klass);
- parent_class = MRP_STORAGE_MODULE_CLASS (g_type_class_peek_parent (klass));
-
mrp_storage_module_class->set_project = storage_sql_set_project;
mrp_storage_module_class->load = storage_sql_load;
mrp_storage_module_class->save = storage_sql_save;
@@ -94,6 +64,11 @@ storage_sql_class_init (MrpStorageSQLClass *klass)
mrp_storage_module_class->from_xml = NULL;
}
+static void
+mrp_storage_sql_class_finalize (MrpStorageSQLClass *klass)
+{
+}
+
G_MODULE_EXPORT void
module_init (GTypeModule *module)
{
diff --git a/libplanner/mrp-storage-sql.h b/libplanner/mrp-storage-sql.h
index 7a29b43f..43f9fc33 100644
--- a/libplanner/mrp-storage-sql.h
+++ b/libplanner/mrp-storage-sql.h
@@ -20,25 +20,20 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __MRP_STORAGE_SQL_H__
-#define __MRP_STORAGE_SQL_H__
+#pragma once
#include <glib-object.h>
#include "mrp-storage-module.h"
#include "mrp-types.h"
#include "mrp-project.h"
+G_BEGIN_DECLS
+
extern GType mrp_storage_sql_type;
-#define MRP_TYPE_STORAGE_SQL mrp_storage_sql_type
-#define MRP_STORAGE_SQL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MRP_TYPE_STORAGE_SQL,
MrpStorageSQL))
-#define MRP_STORAGE_SQL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MRP_TYPE_STORAGE_SQL,
MrpStorageSQLClass))
-#define MRP_IS_STORAGE_SQL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MRP_TYPE_STORAGE_SQL))
-#define MRP_IS_STORAGE_SQL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), MRP_TYPE_STORAGE_SQL))
-#define MRP_STORAGE_SQL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MRP_TYPE_STORAGE_SQL,
MrpStorageSQLClass))
+#define MRP_TYPE_STORAGE_SQL (mrp_storage_sql_get_type())
-typedef struct _MrpStorageSQL MrpStorageSQL;
-typedef struct _MrpStorageSQLClass MrpStorageSQLClass;
+G_DECLARE_FINAL_TYPE (MrpStorageSQL, mrp_storage_sql, MRP, STORAGE_SQL, MrpStorageModule)
struct _MrpStorageSQL {
MrpStorageModule parent;
@@ -49,7 +44,4 @@ struct _MrpStorageSQLClass {
MrpStorageModuleClass parent_class;
};
-
-void mrp_storage_sql_register_type (GTypeModule *module);
-
-#endif /* __MRP_STORAGE_SQL_H__ */
+G_END_DECLS
diff --git a/libplanner/mrp-task-manager.c b/libplanner/mrp-task-manager.c
index 15806993..8ffac5d3 100644
--- a/libplanner/mrp-task-manager.c
+++ b/libplanner/mrp-task-manager.c
@@ -33,8 +33,13 @@
#include "mrp-private.h"
#include "mrp-time.h"
#include "mrp-error.h"
+#include <libplanner/mrp-relation.h>
-struct _MrpTaskManagerPriv {
+struct _MrpTaskManager {
+ GObject parent_instance;
+};
+
+typedef struct {
MrpProject *project;
MrpTask *root;
@@ -48,7 +53,9 @@ struct _MrpTaskManagerPriv {
gboolean in_recalc;
GList *dependency_list;
-};
+} MrpTaskManagerPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (MrpTaskManager, mrp_task_manager, G_TYPE_OBJECT)
typedef struct {
MrpTaskTraverseFunc func;
@@ -61,17 +68,6 @@ enum {
PROP_PROJECT,
};
-static void task_manager_class_init (MrpTaskManagerClass *klass);
-static void task_manager_init (MrpTaskManager *tm);
-static void task_manager_finalize (GObject *object);
-static void task_manager_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void task_manager_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
static void
task_manager_task_duration_notify_cb (MrpTask *task,
GParamSpec *spec,
@@ -119,8 +115,6 @@ static void
task_manager_dump_task_tree (GNode *node);
-static GObjectClass *parent_class;
-
static mrptime
task_manager_calculate_task_start_from_finish (MrpTaskManager *manager,
MrpTask *task,
@@ -128,93 +122,25 @@ task_manager_calculate_task_start_from_finish (MrpTaskManager *manager,
gint *duration);
-GType
-mrp_task_manager_get_type (void)
-{
- static GType object_type = 0;
-
- if (!object_type) {
- static const GTypeInfo object_info = {
- sizeof (MrpTaskManagerClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) task_manager_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (MrpTaskManager),
- 0, /* n_preallocs */
- (GInstanceInitFunc) task_manager_init,
- };
-
- object_type = g_type_register_static (G_TYPE_OBJECT,
- "MrpTaskManager",
- &object_info,
- 0);
- }
-
- return object_type;
-}
-
static void
-task_manager_class_init (MrpTaskManagerClass *klass)
-{
- GObjectClass *object_class = (GObjectClass *) klass;
-
- parent_class = g_type_class_peek_parent (klass);
-
- object_class->finalize = task_manager_finalize;
- object_class->set_property = task_manager_set_property;
- object_class->get_property = task_manager_get_property;
-
- /* Properties. */
- g_object_class_install_property (
- object_class,
- PROP_PROJECT,
- g_param_spec_object ("project",
- "Project",
- "The project that this task manager is attached to",
- G_TYPE_OBJECT,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
-}
-
-static void
-task_manager_init (MrpTaskManager *man)
-{
- MrpTaskManagerPriv *priv;
-
- man->priv = g_new0 (MrpTaskManagerPriv, 1);
- priv = man->priv;
-
- priv->needs_recalc = TRUE;
- priv->needs_rebuild = TRUE;
-}
-
-static void
-task_manager_finalize (GObject *object)
+mrp_task_manager_finalize (GObject *object)
{
MrpTaskManager *manager = MRP_TASK_MANAGER (object);
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
- g_object_unref (manager->priv->root);
-
- g_free (manager->priv);
+ g_object_unref (priv->root);
- if (G_OBJECT_CLASS (parent_class)->finalize) {
- (* G_OBJECT_CLASS (parent_class)->finalize) (object);
- }
+ G_OBJECT_CLASS (mrp_task_manager_parent_class)->finalize (object);
}
static void
-task_manager_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+mrp_task_manager_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- MrpTaskManager *manager;
- MrpTaskManagerPriv *priv;
-
- manager = MRP_TASK_MANAGER (object);
- priv = manager->priv;
+ MrpTaskManager *manager = MRP_TASK_MANAGER (object);
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
switch (prop_id) {
case PROP_PROJECT:
@@ -233,18 +159,17 @@ task_manager_set_property (GObject *object,
}
static void
-task_manager_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+mrp_task_manager_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- MrpTaskManager *manager;
-
- manager = MRP_TASK_MANAGER (object);
+ MrpTaskManager *manager = MRP_TASK_MANAGER (object);
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
switch (prop_id) {
case PROP_PROJECT:
- g_value_set_object (value, manager->priv->project);
+ g_value_set_object (value, priv->project);
break;
default:
@@ -253,6 +178,36 @@ task_manager_get_property (GObject *object,
}
}
+static void
+mrp_task_manager_class_init (MrpTaskManagerClass *klass)
+{
+ GObjectClass *object_class = (GObjectClass *) klass;
+
+ object_class->finalize = mrp_task_manager_finalize;
+ object_class->set_property = mrp_task_manager_set_property;
+ object_class->get_property = mrp_task_manager_get_property;
+
+ /* Properties. */
+ g_object_class_install_property (
+ object_class,
+ PROP_PROJECT,
+ g_param_spec_object ("project",
+ "Project",
+ "The project that this task manager is attached to",
+ G_TYPE_OBJECT,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
+}
+
+static void
+mrp_task_manager_init (MrpTaskManager *man)
+{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (man);
+
+ priv->needs_recalc = TRUE;
+ priv->needs_rebuild = TRUE;
+}
+
MrpTaskManager *
mrp_task_manager_new (MrpProject *project)
{
@@ -319,26 +274,28 @@ mrp_task_manager_insert_task (MrpTaskManager *manager,
gint position,
MrpTask *task)
{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
+
g_return_if_fail (MRP_IS_TASK_MANAGER (manager));
g_return_if_fail (parent == NULL || MRP_IS_TASK (parent));
g_return_if_fail (MRP_IS_TASK (task));
if (parent == NULL) {
- parent = manager->priv->root;
+ parent = priv->root;
}
g_object_set (task,
- "project", manager->priv->project,
+ "project", priv->project,
NULL);
imrp_task_insert_child (parent, position, task);
/* FIXME: implement adding the task to the dependency graph instead. */
- manager->priv->needs_rebuild = TRUE;
+ priv->needs_rebuild = TRUE;
- manager->priv->needs_recalc = TRUE;
+ priv->needs_recalc = TRUE;
- imrp_project_task_inserted (manager->priv->project, task);
+ imrp_project_task_inserted (priv->project, task);
mrp_task_manager_recalc (manager, TRUE);
@@ -358,10 +315,12 @@ void
mrp_task_manager_remove_task (MrpTaskManager *manager,
MrpTask *task)
{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
+
g_return_if_fail (MRP_IS_TASK_MANAGER (manager));
g_return_if_fail (MRP_IS_TASK (task));
- if (task == manager->priv->root) {
+ if (task == priv->root) {
g_warning ("Can't remove root task");
return;
}
@@ -372,7 +331,7 @@ mrp_task_manager_remove_task (MrpTaskManager *manager,
imrp_task_remove_subtree (task);
- manager->priv->needs_rebuild = TRUE;
+ priv->needs_rebuild = TRUE;
mrp_task_manager_recalc (manager, FALSE);
}
@@ -398,17 +357,18 @@ task_manager_get_all_tasks_cb (GNode *node, GList **list)
GList *
mrp_task_manager_get_all_tasks (MrpTaskManager *manager)
{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
GList *tasks;
g_return_val_if_fail (MRP_IS_TASK_MANAGER (manager), NULL);
- if (manager->priv->root == NULL) {
+ if (priv->root == NULL) {
return NULL;
}
tasks = NULL;
- g_node_traverse (imrp_task_get_node (manager->priv->root),
+ g_node_traverse (imrp_task_get_node (priv->root),
G_PRE_ORDER,
G_TRAVERSE_ALL,
-1,
@@ -462,19 +422,20 @@ void
mrp_task_manager_set_root (MrpTaskManager *manager,
MrpTask *task)
{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
GList *tasks, *l;
MrpProject *project;
g_return_if_fail (MRP_IS_TASK_MANAGER (manager));
g_return_if_fail (task == NULL || MRP_IS_TASK (task));
- if (manager->priv->root != NULL) {
- imrp_task_remove_subtree (manager->priv->root);
+ if (priv->root != NULL) {
+ imrp_task_remove_subtree (priv->root);
}
- manager->priv->root = task;
+ priv->root = task;
- project = manager->priv->project;
+ project = priv->project;
tasks = mrp_task_manager_get_all_tasks (manager);
for (l = tasks; l; l = l->next) {
@@ -495,9 +456,11 @@ mrp_task_manager_set_root (MrpTaskManager *manager,
MrpTask *
mrp_task_manager_get_root (MrpTaskManager *manager)
{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
+
g_return_val_if_fail (MRP_IS_TASK_MANAGER (manager), NULL);
- return manager->priv->root;
+ return priv->root;
}
gboolean
@@ -508,6 +471,7 @@ mrp_task_manager_move_task (MrpTaskManager *manager,
gboolean before,
GError **error)
{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
MrpTask *old_parent;
g_return_val_if_fail (MRP_IS_TASK_MANAGER (manager), FALSE);
@@ -532,7 +496,7 @@ mrp_task_manager_move_task (MrpTaskManager *manager,
mrp_task_manager_rebuild (manager);
- imrp_project_task_moved (manager->priv->project, task);
+ imrp_project_task_moved (priv->project, task);
mrp_task_manager_recalc (manager, FALSE);
@@ -638,20 +602,23 @@ task_manager_dump_task_tree (GNode *node)
void
mrp_task_manager_dump_task_tree (MrpTaskManager *manager)
{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
+
g_return_if_fail (MRP_IS_TASK_MANAGER (manager));
- g_return_if_fail (manager->priv->root);
+ g_return_if_fail (priv->root);
- task_manager_dump_task_tree (imrp_task_get_node (manager->priv->root));
+ task_manager_dump_task_tree (imrp_task_get_node (priv->root));
}
void
mrp_task_manager_dump_task_list (MrpTaskManager *manager)
{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
GList *list, *l;
const gchar *name;
g_return_if_fail (MRP_IS_TASK_MANAGER (manager));
- g_return_if_fail (manager->priv->root);
+ g_return_if_fail (priv->root);
g_print ("All tasks: ");
list = mrp_task_manager_get_all_tasks (manager);
@@ -997,13 +964,11 @@ remove_task_from_dependency_graph (MrpTaskManager *manager,
MrpTask *task,
MrpTask *parent)
{
- MrpTaskManagerPriv *priv;
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
GList *list, *l;
MrpRelation *relation;
MrpTask *predecessor;
- priv = manager->priv;
-
/* Remove predecessors. */
list = imrp_task_peek_predecessors (task);
for (l = list; l; l = l->next) {
@@ -1024,13 +989,11 @@ add_task_to_dependency_graph (MrpTaskManager *manager,
MrpTask *task,
MrpTask *parent)
{
- MrpTaskManagerPriv *priv;
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
GList *list, *l;
MrpRelation *relation;
MrpTask *predecessor;
- priv = manager->priv;
-
if (task == priv->root) {
return;
}
@@ -1081,7 +1044,7 @@ task_manager_clean_graph_func (MrpTask *task,
static void
task_manager_build_dependency_graph (MrpTaskManager *manager)
{
- MrpTaskManagerPriv *priv;
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
GList *tasks;
GList *l;
GList *deps;
@@ -1089,8 +1052,6 @@ task_manager_build_dependency_graph (MrpTaskManager *manager)
MrpTaskGraphNode *node;
GList *queue;
- priv = manager->priv;
-
/* Build a directed, acyclic graph, where relation links and children ->
* parent are graph links (children must be calculated before
* parents). Then do topological sorting on the graph to get the order
@@ -1167,8 +1128,8 @@ task_manager_build_dependency_graph (MrpTaskManager *manager)
task_manager_unset_visited_func,
NULL);
- manager->priv->needs_rebuild = FALSE;
- manager->priv->needs_recalc = TRUE;
+ priv->needs_rebuild = FALSE;
+ priv->needs_recalc = TRUE;
}
/* Calculate the start time of the task by finding the latest finish of it's
@@ -1179,7 +1140,7 @@ task_manager_calculate_task_start (MrpTaskManager *manager,
MrpTask *task,
gint *duration)
{
- MrpTaskManagerPriv *priv;
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
MrpTask *tmp_task;
GList *predecessors, *l;
MrpRelation *relation;
@@ -1191,8 +1152,6 @@ task_manager_calculate_task_start (MrpTaskManager *manager,
mrptime dep_start;
MrpConstraint constraint;
- priv = manager->priv;
-
project_start = mrp_project_get_project_start (priv->project);
start = project_start;
@@ -1339,7 +1298,7 @@ task_manager_get_task_units_intervals (MrpTaskManager *manager,
MrpTask *task,
mrptime date)
{
- MrpTaskManagerPriv *priv;
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
MrpCalendar *calendar;
MrpDay *day;
GList *ivals, *l;
@@ -1377,8 +1336,6 @@ task_manager_get_task_units_intervals (MrpTaskManager *manager,
mrptime i_start_post, i_end_post, i_start_cmp, i_end_cmp;
#endif
- priv = manager->priv;
-
assignments = mrp_task_get_assignments (task);
array = g_ptr_array_new ();
@@ -1737,7 +1694,7 @@ task_manager_calculate_task_finish (MrpTaskManager *manager,
mrptime start,
gint *duration)
{
- MrpTaskManagerPriv *priv;
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
mrptime finish;
mrptime t;
mrptime t1, t2;
@@ -1750,8 +1707,6 @@ task_manager_calculate_task_finish (MrpTaskManager *manager,
MrpTaskType type;
MrpTaskSched sched;
- priv = manager->priv;
-
if (task == priv->root) {
g_warning ("Tried to get duration of root task.");
return 0;
@@ -1900,7 +1855,7 @@ task_manager_calculate_task_start_from_finish (MrpTaskManager *manager,
mrptime finish,
gint *duration)
{
- MrpTaskManagerPriv *priv;
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
mrptime start;
mrptime t;
mrptime t1, t2;
@@ -1914,8 +1869,6 @@ task_manager_calculate_task_start_from_finish (MrpTaskManager *manager,
MrpTaskType type;
MrpTaskSched sched;
- priv = manager->priv;
-
if (task == priv->root) {
g_warning ("Tried to get duration of root task.");
return 0;
@@ -2162,11 +2115,9 @@ static void
task_manager_do_forward_pass (MrpTaskManager *manager,
MrpTask *start_task)
{
- MrpTaskManagerPriv *priv;
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
GList *l;
- priv = manager->priv;
-
/* Do forward pass, start at the task and do all tasks that come after
* it in the dependency list. Note: we could try to skip tasks that are
* not dependent, but I don't think that's really worth it.
@@ -2192,7 +2143,7 @@ task_manager_do_forward_pass (MrpTaskManager *manager,
static void
task_manager_do_backward_pass (MrpTaskManager *manager)
{
- MrpTaskManagerPriv *priv;
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
GList *tasks, *l;
GList *successors, *s;
mrptime project_finish;
@@ -2201,8 +2152,6 @@ task_manager_do_backward_pass (MrpTaskManager *manager)
gboolean critical;
gboolean was_critical;
- priv = manager->priv;
-
project_finish = mrp_task_get_finish (priv->root);
tasks = g_list_reverse (g_list_copy (priv->dependency_list));
@@ -2287,12 +2236,10 @@ task_manager_do_backward_pass (MrpTaskManager *manager)
void
mrp_task_manager_set_block_scheduling (MrpTaskManager *manager, gboolean block)
{
- MrpTaskManagerPriv *priv;
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
g_return_if_fail (MRP_IS_TASK_MANAGER (manager));
- priv = manager->priv;
-
if (priv->block_scheduling == block) {
return;
}
@@ -2307,20 +2254,20 @@ mrp_task_manager_set_block_scheduling (MrpTaskManager *manager, gboolean block)
gboolean
mrp_task_manager_get_block_scheduling (MrpTaskManager *manager)
{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
+
g_return_val_if_fail (MRP_IS_TASK_MANAGER (manager), FALSE);
- return manager->priv->block_scheduling;
+ return priv->block_scheduling;
}
void
mrp_task_manager_rebuild (MrpTaskManager *manager)
{
- MrpTaskManagerPriv *priv;
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
g_return_if_fail (MRP_IS_TASK_MANAGER (manager));
- g_return_if_fail (manager->priv->root != NULL);
-
- priv = manager->priv;
+ g_return_if_fail (priv->root != NULL);
if (priv->block_scheduling) {
return;
@@ -2336,13 +2283,11 @@ void
mrp_task_manager_recalc (MrpTaskManager *manager,
gboolean force)
{
- MrpTaskManagerPriv *priv;
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
MrpProject *project;
g_return_if_fail (MRP_IS_TASK_MANAGER (manager));
- g_return_if_fail (manager->priv->root != NULL);
-
- priv = manager->priv;
+ g_return_if_fail (priv->root != NULL);
if (priv->block_scheduling) {
return;
@@ -2438,6 +2383,8 @@ task_manager_task_relation_added_cb (MrpTask *task,
MrpRelation *relation,
MrpTaskManager *manager)
{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
+
/* We get a signal on both the predecessor and the successor, it's
* enough with one rebuild.
*/
@@ -2450,7 +2397,7 @@ task_manager_task_relation_added_cb (MrpTask *task,
G_CALLBACK (task_manager_task_relation_notify_cb),
manager, 0);
- manager->priv->needs_rebuild = TRUE;
+ priv->needs_rebuild = TRUE;
mrp_task_manager_recalc (manager, FALSE);
}
@@ -2459,6 +2406,8 @@ task_manager_task_relation_removed_cb (MrpTask *task,
MrpRelation *relation,
MrpTaskManager *manager)
{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
+
/* We get a signal on both the predecessor and the successor, it's
* enough with one rebuild.
*/
@@ -2470,7 +2419,7 @@ task_manager_task_relation_removed_cb (MrpTask *task,
task_manager_task_relation_notify_cb,
manager);
- manager->priv->needs_rebuild = TRUE;
+ priv->needs_rebuild = TRUE;
mrp_task_manager_recalc (manager, FALSE);
}
@@ -2479,12 +2428,14 @@ task_manager_task_assignment_added_cb (MrpTask *task,
MrpAssignment *assignment,
MrpTaskManager *manager)
{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
+
g_signal_connect_object (assignment, "notify::units",
G_CALLBACK (task_manager_assignment_units_notify_cb),
manager, 0);
mrp_task_invalidate_cost (task);
- manager->priv->needs_rebuild = TRUE;
+ priv->needs_rebuild = TRUE;
mrp_task_manager_recalc (manager, FALSE);
}
@@ -2493,12 +2444,14 @@ task_manager_task_assignment_removed_cb (MrpTask *task,
MrpAssignment *assignment,
MrpTaskManager *manager)
{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
+
g_signal_handlers_disconnect_by_func (assignment,
task_manager_assignment_units_notify_cb,
manager);
mrp_task_invalidate_cost (task);
- manager->priv->needs_rebuild = TRUE;
+ priv->needs_rebuild = TRUE;
mrp_task_manager_recalc (manager, FALSE);
}
@@ -2567,13 +2520,14 @@ mrp_task_manager_check_predecessor (MrpTaskManager *manager,
MrpTask *predecessor,
GError **error)
{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
gboolean retval;
g_return_val_if_fail (MRP_IS_TASK_MANAGER (manager), FALSE);
g_return_val_if_fail (MRP_IS_TASK (task), FALSE);
g_return_val_if_fail (MRP_IS_TASK (predecessor), FALSE);
- if (manager->priv->needs_rebuild) {
+ if (priv->needs_rebuild) {
mrp_task_manager_rebuild (manager);
}
@@ -2587,7 +2541,7 @@ mrp_task_manager_check_predecessor (MrpTaskManager *manager,
}
mrp_task_manager_traverse (manager,
- manager->priv->root,
+ priv->root,
task_manager_unset_visited_func,
NULL);
@@ -2613,6 +2567,7 @@ mrp_task_manager_check_move (MrpTaskManager *manager,
MrpTask *parent,
GError **error)
{
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
gboolean retval;
g_return_val_if_fail (MRP_IS_TASK_MANAGER (manager), FALSE);
@@ -2630,7 +2585,7 @@ mrp_task_manager_check_move (MrpTaskManager *manager,
}
mrp_task_manager_traverse (manager,
- manager->priv->root,
+ priv->root,
task_manager_unset_visited_func,
NULL);
@@ -2783,13 +2738,11 @@ mrp_task_manager_calculate_task_work (MrpTaskManager *manager,
mrptime start,
mrptime finish)
{
- MrpTaskManagerPriv *priv;
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
gint work = 0;
GList *assignments;
MrpCalendar *calendar;
- priv = manager->priv;
-
if (task == priv->root) {
return 0;
}
@@ -2838,7 +2791,7 @@ mrp_task_manager_calculate_summary_duration (MrpTaskManager *manager,
mrptime start,
mrptime finish)
{
- MrpTaskManagerPriv *priv;
+ MrpTaskManagerPrivate *priv = mrp_task_manager_get_instance_private (manager);
mrptime t;
mrptime t1, t2;
gint duration = 0;
@@ -2847,8 +2800,6 @@ mrp_task_manager_calculate_summary_duration (MrpTaskManager *manager,
GList *ivals, *l;
MrpInterval *ival;
- priv = manager->priv;
-
if (task == priv->root) {
return 0;
}
diff --git a/libplanner/mrp-task-manager.h b/libplanner/mrp-task-manager.h
index 11c6eeaa..e0c0ebe8 100644
--- a/libplanner/mrp-task-manager.h
+++ b/libplanner/mrp-task-manager.h
@@ -21,73 +21,54 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __MRP_TASK_MANAGER_H__
-#define __MRP_TASK_MANAGER_H__
+#pragma once
#include <glib-object.h>
-
-#define MRP_TYPE_TASK_MANAGER (mrp_task_manager_get_type ())
-#define MRP_TASK_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MRP_TYPE_TASK_MANAGER,
MrpTaskManager))
-#define MRP_TASK_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MRP_TYPE_TASK_MANAGER,
MrpTaskManagerClass))
-#define MRP_IS_TASK_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MRP_TYPE_TASK_MANAGER))
-#define MRP_IS_TASK_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MRP_TYPE_TASK_MANAGER))
-#define MRP_TASK_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MRP_TYPE_TASK_MANAGER,
MrpTaskManagerClass))
-
-typedef struct _MrpTaskManager MrpTaskManager;
-typedef struct _MrpTaskManagerPriv MrpTaskManagerPriv;
-
#include <libplanner/mrp-project.h>
#include <libplanner/mrp-task.h>
-struct _MrpTaskManager {
- GObject parent;
- MrpTaskManagerPriv *priv;
-};
+G_BEGIN_DECLS
-typedef struct {
- GObjectClass parent_class;
-} MrpTaskManagerClass;
-
-
-GType mrp_task_manager_get_type (void) G_GNUC_CONST;
-MrpTaskManager *mrp_task_manager_new (MrpProject *project);
-GList *mrp_task_manager_get_all_tasks (MrpTaskManager *manager);
-void mrp_task_manager_insert_task (MrpTaskManager *manager,
- MrpTask *parent,
- gint position,
- MrpTask *task);
-void mrp_task_manager_remove_task (MrpTaskManager *manager,
- MrpTask *task);
-gboolean mrp_task_manager_move_task (MrpTaskManager *manager,
- MrpTask *task,
- MrpTask *sibling,
- MrpTask *parent,
- gboolean before,
- GError **error);
-void mrp_task_manager_set_root (MrpTaskManager *manager,
- MrpTask *task);
-MrpTask *mrp_task_manager_get_root (MrpTaskManager *manager);
-void mrp_task_manager_traverse (MrpTaskManager *manager,
- MrpTask *root,
- MrpTaskTraverseFunc func,
- gpointer user_data);
-void mrp_task_manager_set_block_scheduling (MrpTaskManager *manager,
- gboolean block);
-gboolean mrp_task_manager_get_block_scheduling (MrpTaskManager *manager);
-void mrp_task_manager_rebuild (MrpTaskManager *manager);
-void mrp_task_manager_recalc (MrpTaskManager *manager,
- gboolean force);
-gint mrp_task_manager_calculate_task_work (MrpTaskManager *manager,
- MrpTask *task,
- mrptime start,
- mrptime finish);
-gint mrp_task_manager_calculate_summary_duration (MrpTaskManager *manager,
- MrpTask *task,
- mrptime start,
- mrptime finish);
-void mrp_task_manager_dump_task_tree (MrpTaskManager *manager);
-void mrp_task_manager_dump_task_list (MrpTaskManager *manager);
+#define MRP_TYPE_TASK_MANAGER (mrp_task_manager_get_type ())
+G_DECLARE_FINAL_TYPE (MrpTaskManager, mrp_task_manager, MRP, TASK_MANAGER, GObject)
+MrpTaskManager *mrp_task_manager_new (MrpProject *project);
+GList *mrp_task_manager_get_all_tasks (MrpTaskManager *manager);
+void mrp_task_manager_insert_task (MrpTaskManager *manager,
+ MrpTask *parent,
+ gint position,
+ MrpTask *task);
+void mrp_task_manager_remove_task (MrpTaskManager *manager,
+ MrpTask *task);
+gboolean mrp_task_manager_move_task (MrpTaskManager *manager,
+ MrpTask *task,
+ MrpTask *sibling,
+ MrpTask *parent,
+ gboolean before,
+ GError **error);
+void mrp_task_manager_set_root (MrpTaskManager *manager,
+ MrpTask *task);
+MrpTask *mrp_task_manager_get_root (MrpTaskManager *manager);
+void mrp_task_manager_traverse (MrpTaskManager *manager,
+ MrpTask *root,
+ MrpTaskTraverseFunc func,
+ gpointer user_data);
+void mrp_task_manager_set_block_scheduling (MrpTaskManager *manager,
+ gboolean block);
+gboolean mrp_task_manager_get_block_scheduling (MrpTaskManager *manager);
+void mrp_task_manager_rebuild (MrpTaskManager *manager);
+void mrp_task_manager_recalc (MrpTaskManager *manager,
+ gboolean force);
+gint mrp_task_manager_calculate_task_work (MrpTaskManager *manager,
+ MrpTask *task,
+ mrptime start,
+ mrptime finish);
+gint mrp_task_manager_calculate_summary_duration (MrpTaskManager *manager,
+ MrpTask *task,
+ mrptime start,
+ mrptime finish);
+void mrp_task_manager_dump_task_tree (MrpTaskManager *manager);
+void mrp_task_manager_dump_task_list (MrpTaskManager *manager);
-#endif /* __MRP_TASK_MANAGER_H__ */
+G_END_DECLS
diff --git a/libplanner/mrp-task.c b/libplanner/mrp-task.c
index 4fae5f37..facd795f 100644
--- a/libplanner/mrp-task.c
+++ b/libplanner/mrp-task.c
@@ -66,6 +66,7 @@
#include "mrp-private.h"
#include "mrp-resource.h"
#include "mrp-error.h"
+#include "mrp-relation.h"
/* Properties */
enum {
@@ -98,7 +99,11 @@ enum {
LAST_SIGNAL
};
-struct _MrpTaskPriv {
+struct _MrpTask {
+ MrpObject parent_instance;
+};
+
+typedef struct {
guint critical : 1;
/* Used for topological order sorting. */
@@ -168,64 +173,22 @@ struct _MrpTaskPriv {
gfloat cost;
gboolean cost_cached;
-};
+} MrpTaskPrivate;
+G_DEFINE_TYPE_WITH_PRIVATE (MrpTask, mrp_task, MRP_TYPE_OBJECT)
-static void task_init (MrpTask *module);
-static void task_class_init (MrpTaskClass *class);
-static void task_finalize (GObject *object);
-static void task_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void task_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void task_removed (MrpObject *object);
static void task_assignment_removed_cb (MrpAssignment *assignment,
MrpTask *task);
static void task_remove_assignments (MrpTask *task);
static void task_remove_relations (MrpTask *task);
-static MrpObjectClass *parent_class;
static guint signals[LAST_SIGNAL];
-
-GType
-mrp_task_get_type (void)
-{
- static GType object_type = 0;
-
- if (!object_type) {
- static const GTypeInfo object_info = {
- sizeof (MrpTaskClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) task_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (MrpTask),
- 0, /* n_preallocs */
- (GInstanceInitFunc) task_init,
- };
-
- object_type = g_type_register_static (MRP_TYPE_OBJECT,
- "MrpTask",
- &object_info, 0);
- }
-
- return object_type;
-}
-
static void
-task_init (MrpTask *task)
+mrp_task_init (MrpTask *task)
{
- MrpTaskPriv *priv;
-
- priv = g_new0 (MrpTaskPriv, 1);
- task->priv = priv;
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
priv->name = g_strdup ("");
priv->node = g_node_new (task);
@@ -240,264 +203,10 @@ task_init (MrpTask *task)
}
static void
-task_class_init (MrpTaskClass *klass)
+mrp_task_finalize (GObject *object)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MrpObjectClass *mrp_object_class = MRP_OBJECT_CLASS (klass);
-
- parent_class = MRP_OBJECT_CLASS (g_type_class_peek_parent (klass));
-
- object_class->finalize = task_finalize;
- object_class->set_property = task_set_property;
- object_class->get_property = task_get_property;
-
- mrp_object_class->removed = task_removed;
-
- /**
- * MrpTask::task-moved:
- * @task: the object which received the signal.
- * @other_task: another #MrpTask.
- *
- * emitted when @other_task is moved.
- */
- signals[TASK_MOVED] =
- g_signal_new ("task_moved",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- mrp_marshal_VOID__OBJECT_INT,
- G_TYPE_NONE, 2, MRP_TYPE_TASK, G_TYPE_INT);
-
- /**
- * MrpTask::relation-added:
- * @task: the object which received the signal.
- * @relation: the added #MrpRelation.
- *
- * emitted when @relation is added.
- */
- signals[RELATION_ADDED] =
- g_signal_new ("relation_added",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- mrp_marshal_VOID__POINTER,
- G_TYPE_NONE, 1, G_TYPE_POINTER);
-
- /**
- * MrpTask::relation-removed:
- * @task: the object which received the signal.
- * @relation: the removed #MrpRelation
- *
- * emitted when @relation is removed.
- */
- signals[RELATION_REMOVED] =
- g_signal_new ("relation_removed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- mrp_marshal_VOID__POINTER,
- G_TYPE_NONE, 1, G_TYPE_POINTER);
-
- /**
- * MrpTask::assignment-added:
- * @task: the object which received the signal.
- * @assignment: the added #MrpAssignment.
- *
- * emitted when @assignment is added.
- */
- signals[ASSIGNMENT_ADDED] =
- g_signal_new ("assignment_added",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- mrp_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1, MRP_TYPE_ASSIGNMENT);
-
- /**
- * MrpTask::assignment-removed:
- * @task: the object which received the signal.
- * @assignment: the removed #MrpAssignment.
- *
- * emitted when @assignment is removed.
- */
- signals[ASSIGNMENT_REMOVED] =
- g_signal_new ("assignment_removed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- mrp_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1, MRP_TYPE_ASSIGNMENT);
-
- /**
- * MrpTask::child-added:
- * @task: the object which received the signal.
- *
- * emitted when a child is added.
- */
- signals[CHILD_ADDED] =
- g_signal_new ("child_added",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- mrp_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- /**
- * MrpTask::child-removed:
- * @task: the object which received the signal.
- *
- * emitted when a child is removed.
- */
- signals[CHILD_REMOVED] =
- g_signal_new ("child_removed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- mrp_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- g_object_class_install_property (
- object_class,
- PROP_NAME,
- g_param_spec_string ("name",
- "Name",
- "Name of the task",
- "",
- G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_NOTE,
- g_param_spec_string ("note",
- "Note",
- "Note attached to the task",
- "",
- G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_START,
- mrp_param_spec_time ("start",
- "Start time",
- "Task Start time",
- G_PARAM_READABLE));
-
- g_object_class_install_property (
- object_class,
- PROP_FINISH,
- mrp_param_spec_time ("finish",
- "Finish time",
- "Task finish time",
- G_PARAM_READABLE));
-
- g_object_class_install_property (
- object_class,
- PROP_LATEST_START,
- mrp_param_spec_time ("latest_start",
- "Latest start",
- "Latest task start time",
- G_PARAM_READABLE));
-
- g_object_class_install_property (
- object_class,
- PROP_LATEST_FINISH,
- mrp_param_spec_time ("latest_finish",
- "Latest finish",
- "Latest task finish time",
- G_PARAM_READABLE));
-
- g_object_class_install_property (
- object_class,
- PROP_DURATION,
- g_param_spec_int ("duration",
- "Duration",
- "Duration of the task",
- -1, G_MAXINT, 0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_WORK,
- g_param_spec_int ("work",
- "Work",
- "Task work",
- -1, G_MAXINT, 0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_CRITICAL,
- g_param_spec_boolean ("critical",
- "Critical",
- "In critical path",
- FALSE,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_TYPE,
- g_param_spec_enum ("type",
- "Type",
- "Task type",
- MRP_TYPE_TASK_TYPE,
- MRP_TASK_TYPE_NORMAL,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_SCHED,
- g_param_spec_enum ("sched",
- "Scheduling type",
- "Task scheduling type",
- MRP_TYPE_TASK_SCHED,
- MRP_TASK_SCHED_FIXED_WORK,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_CONSTRAINT,
- g_param_spec_boxed ("constraint",
- "Constraint",
- "Task scheduling constraint",
- MRP_TYPE_CONSTRAINT,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_PERCENT_COMPLETE,
- g_param_spec_int ("percent_complete",
- "Percent complete",
- "Percent completed of task",
- 0, 100, 0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_PRIORITY,
- g_param_spec_int ("priority",
- "Priority",
- "Priority of the task",
- 0, 9999, 0,
- G_PARAM_READWRITE));
-}
-
-static void
-task_finalize (GObject *object)
-{
- MrpTask *task;
- MrpTaskPriv *priv;
-
- task = MRP_TASK (object);
- priv = task->priv;
+ MrpTask *task = MRP_TASK (object);
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
g_free (priv->name);
g_free (priv->note);
@@ -511,36 +220,28 @@ task_finalize (GObject *object)
g_node_destroy (priv->node);
- g_free (priv);
- task->priv = NULL;
-
- if (G_OBJECT_CLASS (parent_class)->finalize) {
- (* G_OBJECT_CLASS (parent_class)->finalize) (object);
- }
+ G_OBJECT_CLASS (mrp_task_parent_class)->finalize (object);
}
static void
-task_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+mrp_task_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- MrpTask *task;
- MrpTaskPriv *priv;
+ MrpTask *task = MRP_TASK (object);
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
const gchar *str;
gint i_val;
MrpTaskType type;
gboolean changed = FALSE;
- task = MRP_TASK (object);
- priv = task->priv;
-
switch (prop_id) {
case PROP_NAME:
str = g_value_get_string (value);
if (!priv->name || strcmp (priv->name, str)) {
- g_free (task->priv->name);
+ g_free (priv->name);
priv->name = g_strdup (str);
changed = TRUE;
}
@@ -551,7 +252,7 @@ task_set_property (GObject *object,
str = g_value_get_string (value);
if (!priv->note || strcmp (priv->note, str)) {
- g_free (task->priv->note);
+ g_free (priv->note);
priv->note = g_strdup (str);
changed = TRUE;
}
@@ -652,115 +353,358 @@ task_set_property (GObject *object,
changed = TRUE;
}
- break;
+ break;
+
+ case PROP_PRIORITY:
+ i_val = g_value_get_int (value);
+
+ if (priv->priority != i_val) {
+ priv->priority = i_val;
+ changed = TRUE;
+ }
+
+ break;
+
+ default:
+ break;
+ }
+
+ if (changed) {
+ mrp_object_changed (MRP_OBJECT (object));
+ }
+}
+
+static void
+mrp_task_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ MrpTask *task = MRP_TASK (object);
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
+ switch (prop_id) {
+ case PROP_NAME:
+ g_value_set_string (value, priv->name);
+ break;
+ case PROP_NOTE:
+ g_value_set_string (value, priv->note);
+ break;
+ case PROP_START:
+ g_value_set_long (value, priv->start);
+ break;
+ case PROP_FINISH:
+ g_value_set_long (value, priv->finish);
+ break;
+ case PROP_LATEST_START:
+ g_value_set_long (value, priv->latest_start);
+ break;
+ case PROP_LATEST_FINISH:
+ g_value_set_long (value, priv->latest_finish);
+ break;
+ case PROP_DURATION:
+ g_value_set_int (value, priv->duration);
+ break;
+ case PROP_WORK:
+ g_value_set_int (value, priv->work);
+ break;
+ case PROP_CRITICAL:
+ g_value_set_boolean (value, priv->critical);
+ break;
+ case PROP_TYPE:
+ g_value_set_enum (value, priv->type);
+ break;
+ case PROP_SCHED:
+ g_value_set_enum (value, priv->sched);
+ break;
+ case PROP_CONSTRAINT:
+ g_value_set_boxed (value, &priv->constraint);
+ break;
+ case PROP_PERCENT_COMPLETE:
+ g_value_set_int (value, priv->percent_complete);
+ break;
+ case PROP_PRIORITY:
+ g_value_set_int (value, priv->priority);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+mrp_task_removed (MrpObject *object)
+{
+ MrpTask *task;
+
+ g_return_if_fail (MRP_IS_TASK (object));
+
+ task = MRP_TASK (object);
+
+ task_remove_assignments (task);
+ task_remove_relations (task);
+
+ if (MRP_OBJECT_CLASS (mrp_task_parent_class)->removed)
+ MRP_OBJECT_CLASS (mrp_task_parent_class)->removed (object);
+}
+
+static void
+mrp_task_class_init (MrpTaskClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ MrpObjectClass *mrp_object_class = MRP_OBJECT_CLASS (klass);
+
+ object_class->finalize = mrp_task_finalize;
+ object_class->set_property = mrp_task_set_property;
+ object_class->get_property = mrp_task_get_property;
+
+ mrp_object_class->removed = mrp_task_removed;
+
+ /**
+ * MrpTask::task-moved:
+ * @task: the object which received the signal.
+ * @other_task: another #MrpTask.
+ *
+ * emitted when @other_task is moved.
+ */
+ signals[TASK_MOVED] =
+ g_signal_new ("task_moved",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ mrp_marshal_VOID__OBJECT_INT,
+ G_TYPE_NONE, 2, MRP_TYPE_TASK, G_TYPE_INT);
+
+ /**
+ * MrpTask::relation-added:
+ * @task: the object which received the signal.
+ * @relation: the added #MrpRelation.
+ *
+ * emitted when @relation is added.
+ */
+ signals[RELATION_ADDED] =
+ g_signal_new ("relation_added",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ mrp_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1, G_TYPE_POINTER);
+
+ /**
+ * MrpTask::relation-removed:
+ * @task: the object which received the signal.
+ * @relation: the removed #MrpRelation
+ *
+ * emitted when @relation is removed.
+ */
+ signals[RELATION_REMOVED] =
+ g_signal_new ("relation_removed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ mrp_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1, G_TYPE_POINTER);
+
+ /**
+ * MrpTask::assignment-added:
+ * @task: the object which received the signal.
+ * @assignment: the added #MrpAssignment.
+ *
+ * emitted when @assignment is added.
+ */
+ signals[ASSIGNMENT_ADDED] =
+ g_signal_new ("assignment_added",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ mrp_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1, MRP_TYPE_ASSIGNMENT);
+
+ /**
+ * MrpTask::assignment-removed:
+ * @task: the object which received the signal.
+ * @assignment: the removed #MrpAssignment.
+ *
+ * emitted when @assignment is removed.
+ */
+ signals[ASSIGNMENT_REMOVED] =
+ g_signal_new ("assignment_removed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ mrp_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1, MRP_TYPE_ASSIGNMENT);
+
+ /**
+ * MrpTask::child-added:
+ * @task: the object which received the signal.
+ *
+ * emitted when a child is added.
+ */
+ signals[CHILD_ADDED] =
+ g_signal_new ("child_added",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ mrp_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ /**
+ * MrpTask::child-removed:
+ * @task: the object which received the signal.
+ *
+ * emitted when a child is removed.
+ */
+ signals[CHILD_REMOVED] =
+ g_signal_new ("child_removed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ mrp_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
- case PROP_PRIORITY:
- i_val = g_value_get_int (value);
+ g_object_class_install_property (
+ object_class,
+ PROP_NAME,
+ g_param_spec_string ("name",
+ "Name",
+ "Name of the task",
+ "",
+ G_PARAM_READWRITE));
- if (priv->priority != i_val) {
- priv->priority = i_val;
- changed = TRUE;
- }
+ g_object_class_install_property (
+ object_class,
+ PROP_NOTE,
+ g_param_spec_string ("note",
+ "Note",
+ "Note attached to the task",
+ "",
+ G_PARAM_READWRITE));
- break;
+ g_object_class_install_property (
+ object_class,
+ PROP_START,
+ mrp_param_spec_time ("start",
+ "Start time",
+ "Task Start time",
+ G_PARAM_READABLE));
- default:
- break;
- }
+ g_object_class_install_property (
+ object_class,
+ PROP_FINISH,
+ mrp_param_spec_time ("finish",
+ "Finish time",
+ "Task finish time",
+ G_PARAM_READABLE));
- if (changed) {
- mrp_object_changed (MRP_OBJECT (object));
- }
-}
+ g_object_class_install_property (
+ object_class,
+ PROP_LATEST_START,
+ mrp_param_spec_time ("latest_start",
+ "Latest start",
+ "Latest task start time",
+ G_PARAM_READABLE));
-static void
-task_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MrpTask *task;
- MrpTaskPriv *priv;
+ g_object_class_install_property (
+ object_class,
+ PROP_LATEST_FINISH,
+ mrp_param_spec_time ("latest_finish",
+ "Latest finish",
+ "Latest task finish time",
+ G_PARAM_READABLE));
- task = MRP_TASK (object);
- priv = task->priv;
+ g_object_class_install_property (
+ object_class,
+ PROP_DURATION,
+ g_param_spec_int ("duration",
+ "Duration",
+ "Duration of the task",
+ -1, G_MAXINT, 0,
+ G_PARAM_READWRITE));
- switch (prop_id) {
- case PROP_NAME:
- g_value_set_string (value, priv->name);
- break;
- case PROP_NOTE:
- g_value_set_string (value, priv->note);
- break;
- case PROP_START:
- g_value_set_long (value, priv->start);
- break;
- case PROP_FINISH:
- g_value_set_long (value, priv->finish);
- break;
- case PROP_LATEST_START:
- g_value_set_long (value, priv->latest_start);
- break;
- case PROP_LATEST_FINISH:
- g_value_set_long (value, priv->latest_finish);
- break;
- case PROP_DURATION:
- g_value_set_int (value, priv->duration);
- break;
- case PROP_WORK:
- g_value_set_int (value, priv->work);
- break;
- case PROP_CRITICAL:
- g_value_set_boolean (value, priv->critical);
- break;
- case PROP_TYPE:
- g_value_set_enum (value, priv->type);
- break;
- case PROP_SCHED:
- g_value_set_enum (value, priv->sched);
- break;
- case PROP_CONSTRAINT:
- g_value_set_boxed (value, &priv->constraint);
- break;
- case PROP_PERCENT_COMPLETE:
- g_value_set_int (value, priv->percent_complete);
- break;
- case PROP_PRIORITY:
- g_value_set_int (value, priv->priority);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
+ g_object_class_install_property (
+ object_class,
+ PROP_WORK,
+ g_param_spec_int ("work",
+ "Work",
+ "Task work",
+ -1, G_MAXINT, 0,
+ G_PARAM_READWRITE));
-static void
-task_removed (MrpObject *object)
-{
- MrpTask *task;
+ g_object_class_install_property (
+ object_class,
+ PROP_CRITICAL,
+ g_param_spec_boolean ("critical",
+ "Critical",
+ "In critical path",
+ FALSE,
+ G_PARAM_READWRITE));
- g_return_if_fail (MRP_IS_TASK (object));
+ g_object_class_install_property (
+ object_class,
+ PROP_TYPE,
+ g_param_spec_enum ("type",
+ "Type",
+ "Task type",
+ MRP_TYPE_TASK_TYPE,
+ MRP_TASK_TYPE_NORMAL,
+ G_PARAM_READWRITE));
- task = MRP_TASK (object);
+ g_object_class_install_property (
+ object_class,
+ PROP_SCHED,
+ g_param_spec_enum ("sched",
+ "Scheduling type",
+ "Task scheduling type",
+ MRP_TYPE_TASK_SCHED,
+ MRP_TASK_SCHED_FIXED_WORK,
+ G_PARAM_READWRITE));
- task_remove_assignments (task);
- task_remove_relations (task);
+ g_object_class_install_property (
+ object_class,
+ PROP_CONSTRAINT,
+ g_param_spec_boxed ("constraint",
+ "Constraint",
+ "Task scheduling constraint",
+ MRP_TYPE_CONSTRAINT,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_PERCENT_COMPLETE,
+ g_param_spec_int ("percent_complete",
+ "Percent complete",
+ "Percent completed of task",
+ 0, 100, 0,
+ G_PARAM_READWRITE));
- if (MRP_OBJECT_CLASS (parent_class)->removed) {
- (* MRP_OBJECT_CLASS (parent_class)->removed) (object);
- }
+ g_object_class_install_property (
+ object_class,
+ PROP_PRIORITY,
+ g_param_spec_int ("priority",
+ "Priority",
+ "Priority of the task",
+ 0, 9999, 0,
+ G_PARAM_READWRITE));
}
static void
task_assignment_removed_cb (MrpAssignment *assignment, MrpTask *task)
{
- MrpTaskPriv *priv;
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
g_return_if_fail (MRP_IS_TASK (task));
g_return_if_fail (MRP_IS_ASSIGNMENT (assignment));
- priv = task->priv;
-
priv->assignments = g_list_remove (priv->assignments, assignment);
g_signal_emit (task, signals[ASSIGNMENT_REMOVED], 0, assignment);
@@ -776,13 +720,14 @@ task_remove_relations (MrpTask *task)
MrpRelation *relation;
MrpTask *predecessor;
MrpTask *successor;
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
g_return_if_fail (MRP_IS_TASK (task));
/* Cut relations involving the task (make sure to be robust when
* removing during traversing).
*/
- l = task->priv->predecessors;
+ l = priv->predecessors;
while (l) {
next = l->next;
relation = l->data;
@@ -794,7 +739,7 @@ task_remove_relations (MrpTask *task)
l = next;
}
- l = task->priv->successors;
+ l = priv->successors;
while (l) {
next = l->next;
relation = l->data;
@@ -810,14 +755,12 @@ task_remove_relations (MrpTask *task)
static void
task_remove_assignments (MrpTask *task)
{
- MrpTaskPriv *priv;
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
GList *copy, *l;
MrpAssignment *assignment;
g_return_if_fail (MRP_IS_TASK (task));
- priv = task->priv;
-
copy = g_list_copy (priv->assignments);
for (l = copy; l; l = l->next) {
@@ -839,11 +782,8 @@ task_remove_assignments (MrpTask *task)
static gboolean
task_remove_subtree_cb (GNode *node, gpointer data)
{
- MrpTask *task;
- MrpTaskPriv *priv;
-
- task = node->data;
- priv = task->priv;
+ MrpTask *task = node->data;
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
task_remove_relations (task);
task_remove_assignments (task);
@@ -861,12 +801,13 @@ void
imrp_task_remove_subtree (MrpTask *task)
{
MrpTask *parent;
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
g_return_if_fail (MRP_IS_TASK (task));
parent = NULL;
- if (task->priv->node->parent) {
- parent = task->priv->node->parent->data;
+ if (priv->node->parent) {
+ parent = priv->node->parent->data;
}
g_object_ref (task);
@@ -874,7 +815,7 @@ imrp_task_remove_subtree (MrpTask *task)
/* Remove the tasks one by one using post order so we don't mess with
* the tree while traversing it.
*/
- g_node_traverse (task->priv->node,
+ g_node_traverse (priv->node,
G_POST_ORDER,
G_TRAVERSE_ALL,
-1,
@@ -892,11 +833,13 @@ imrp_task_remove_subtree (MrpTask *task)
void
imrp_task_detach (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_if_fail (MRP_IS_TASK (task));
/* FIXME: Do some extra checking. */
- g_node_unlink (task->priv->node);
+ g_node_unlink (priv->node);
}
void
@@ -906,6 +849,9 @@ imrp_task_reattach (MrpTask *task,
gboolean before)
{
GNode *node;
+ MrpTaskPrivate *task_priv= mrp_task_get_instance_private (task);
+ MrpTaskPrivate *sibling_priv = mrp_task_get_instance_private (sibling);
+ MrpTaskPrivate *parent_priv = mrp_task_get_instance_private (parent);
g_return_if_fail (MRP_IS_TASK (task));
g_return_if_fail (sibling == NULL || MRP_IS_TASK (sibling));
@@ -913,8 +859,8 @@ imrp_task_reattach (MrpTask *task,
/* FIXME: Do some extra checking. */
- if (parent->priv->type == MRP_TASK_TYPE_MILESTONE &&
- !parent->priv->node->children) {
+ if (parent_priv->type == MRP_TASK_TYPE_MILESTONE &&
+ !parent_priv->node->children) {
g_object_set (parent,
"type", MRP_TASK_TYPE_NORMAL,
"sched", MRP_TASK_SCHED_FIXED_WORK,
@@ -923,9 +869,9 @@ imrp_task_reattach (MrpTask *task,
if (sibling == NULL) {
if (before) {
- node = g_node_first_child (parent->priv->node);
+ node = g_node_first_child (parent_priv->node);
} else {
- node = g_node_last_child (parent->priv->node);
+ node = g_node_last_child (parent_priv->node);
}
if (node) {
@@ -935,21 +881,21 @@ imrp_task_reattach (MrpTask *task,
if (before) {
if (sibling != NULL) {
- g_node_insert_before (parent->priv->node,
- sibling->priv->node,
- task->priv->node);
+ g_node_insert_before (parent_priv->node,
+ sibling_priv->node,
+ task_priv->node);
} else {
- g_node_prepend (parent->priv->node,
- task->priv->node);
+ g_node_prepend (parent_priv->node,
+ task_priv->node);
}
} else {
if (sibling != NULL) {
- g_node_insert_after (parent->priv->node,
- sibling->priv->node,
- task->priv->node);
+ g_node_insert_after (parent_priv->node,
+ sibling_priv->node,
+ task_priv->node);
} else {
- g_node_append (parent->priv->node,
- task->priv->node);
+ g_node_append (parent_priv->node,
+ task_priv->node);
}
}
}
@@ -959,15 +905,18 @@ imrp_task_reattach_pos (MrpTask *task,
gint pos,
MrpTask *parent)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+ MrpTaskPrivate *parent_priv = mrp_task_get_instance_private (parent);
+
g_return_if_fail (MRP_IS_TASK (task));
g_return_if_fail (pos >= -1);
g_return_if_fail (MRP_IS_TASK (parent));
/* FIXME: Do some extra checking. */
- g_node_insert (parent->priv->node,
+ g_node_insert (parent_priv->node,
pos,
- task->priv->node);
+ priv->node);
}
/**
@@ -998,9 +947,11 @@ mrp_task_new (void)
const gchar *
mrp_task_get_name (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), NULL);
- return task->priv->name;
+ return priv->name;
}
/**
@@ -1023,20 +974,23 @@ imrp_task_insert_child (MrpTask *parent,
gint position,
MrpTask *child)
{
+ MrpTaskPrivate *parent_priv = mrp_task_get_instance_private (parent);
+ MrpTaskPrivate *child_priv = mrp_task_get_instance_private (child);
+
g_return_if_fail (MRP_IS_TASK (parent));
g_return_if_fail (MRP_IS_TASK (child));
- if (child->priv->duration == -1) {
- child->priv->duration = parent->priv->duration;
+ if (child_priv->duration == -1) {
+ child_priv->duration = parent_priv->duration;
}
- g_node_insert (parent->priv->node,
+ g_node_insert (parent_priv->node,
position,
- child->priv->node);
+ child_priv->node);
mrp_task_invalidate_cost (parent);
- if (parent->priv->type == MRP_TASK_TYPE_MILESTONE) {
+ if (parent_priv->type == MRP_TASK_TYPE_MILESTONE) {
g_object_set (parent,
"type", MRP_TASK_TYPE_NORMAL,
NULL);
@@ -1049,9 +1003,11 @@ static MrpRelation *
task_get_predecessor_relation (MrpTask *task,
MrpTask *predecessor)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
GList *l;
- for (l = task->priv->predecessors; l; l = l->next) {
+ for (l = priv->predecessors; l; l = l->next) {
MrpRelation *relation = l->data;
if (mrp_relation_get_successor (relation) == task &&
@@ -1067,9 +1023,11 @@ static MrpRelation *
task_get_successor_relation (MrpTask *task,
MrpTask *successor)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
GList *l;
- for (l = task->priv->successors; l; l = l->next) {
+ for (l = priv->successors; l; l = l->next) {
MrpRelation *relation = l->data;
if (mrp_relation_get_predecessor (relation) == task &&
@@ -1109,8 +1067,10 @@ mrp_task_has_relation_to (MrpTask *task_a, MrpTask *task_b)
gboolean
mrp_task_has_relation (MrpTask *task)
{
- return (task->priv->predecessors != NULL ||
- task->priv->successors != NULL);
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
+ return (priv->predecessors != NULL ||
+ priv->successors != NULL);
}
/**
@@ -1134,6 +1094,9 @@ mrp_task_add_predecessor (MrpTask *task,
glong lag,
GError **error)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+ MrpTaskPrivate *predecessor_priv = mrp_task_get_instance_private (predecessor);
+
MrpRelation *relation;
MrpProject *project;
MrpTaskManager *manager;
@@ -1223,8 +1186,8 @@ mrp_task_add_predecessor (MrpTask *task,
"lag", lag,
NULL);
- task->priv->predecessors = g_list_prepend (task->priv->predecessors, relation);
- predecessor->priv->successors = g_list_prepend (predecessor->priv->successors, relation);
+ priv->predecessors = g_list_prepend (priv->predecessors, relation);
+ predecessor_priv->successors = g_list_prepend (predecessor_priv->successors, relation);
g_signal_emit (task, signals[RELATION_ADDED], 0, relation);
g_signal_emit (predecessor, signals[RELATION_ADDED], 0, relation);
@@ -1246,6 +1209,9 @@ void
mrp_task_remove_predecessor (MrpTask *task,
MrpTask *predecessor)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+ MrpTaskPrivate *predecessor_priv = mrp_task_get_instance_private (predecessor);
+
MrpRelation *relation;
g_return_if_fail (MRP_IS_TASK (task));
@@ -1253,8 +1219,8 @@ mrp_task_remove_predecessor (MrpTask *task,
relation = task_get_predecessor_relation (task, predecessor);
- task->priv->predecessors = g_list_remove (task->priv->predecessors, relation);
- predecessor->priv->successors = g_list_remove (predecessor->priv->successors, relation);
+ priv->predecessors = g_list_remove (priv->predecessors, relation);
+ predecessor_priv->successors = g_list_remove (predecessor_priv->successors, relation);
/* Notify. */
mrp_object_removed (MRP_OBJECT (relation));
@@ -1345,9 +1311,11 @@ mrp_task_get_successor_relation (MrpTask *task, MrpTask *successor)
GList *
mrp_task_get_predecessor_relations (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), NULL);
- return task->priv->predecessors;
+ return priv->predecessors;
}
/**
@@ -1361,9 +1329,11 @@ mrp_task_get_predecessor_relations (MrpTask *task)
GList *
mrp_task_get_successor_relations (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), NULL);
- return task->priv->successors;
+ return priv->successors;
}
/**
@@ -1377,11 +1347,13 @@ mrp_task_get_successor_relations (MrpTask *task)
MrpTask *
mrp_task_get_parent (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
GNode *node;
g_return_val_if_fail (MRP_IS_TASK (task), NULL);
- node = task->priv->node->parent;
+ node = priv->node->parent;
return node ? node->data : NULL;
}
@@ -1396,11 +1368,13 @@ mrp_task_get_parent (MrpTask *task)
MrpTask *
mrp_task_get_first_child (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
GNode *node;
g_return_val_if_fail (MRP_IS_TASK (task), NULL);
- node = g_node_first_child (task->priv->node);
+ node = g_node_first_child (priv->node);
return node ? node->data : NULL;
}
@@ -1416,11 +1390,13 @@ mrp_task_get_first_child (MrpTask *task)
MrpTask *
mrp_task_get_next_sibling (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
GNode *node;
g_return_val_if_fail (MRP_IS_TASK (task), NULL);
- node = g_node_next_sibling (task->priv->node);
+ node = g_node_next_sibling (priv->node);
return node ? node->data : NULL;
}
@@ -1435,11 +1411,13 @@ mrp_task_get_next_sibling (MrpTask *task)
MrpTask *
mrp_task_get_prev_sibling (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
GNode *node;
g_return_val_if_fail (MRP_IS_TASK (task), NULL);
- node = g_node_prev_sibling (task->priv->node);
+ node = g_node_prev_sibling (priv->node);
return node ? node->data : NULL;
}
@@ -1454,9 +1432,11 @@ mrp_task_get_prev_sibling (MrpTask *task)
guint
mrp_task_get_n_children (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), 0);
- return g_node_n_children (task->priv->node);
+ return g_node_n_children (priv->node);
}
/**
@@ -1471,11 +1451,13 @@ mrp_task_get_n_children (MrpTask *task)
MrpTask *
mrp_task_get_nth_child (MrpTask *task, guint n)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
GNode *node;
g_return_val_if_fail (MRP_IS_TASK (task), 0);
- node = g_node_nth_child (task->priv->node, n);
+ node = g_node_nth_child (priv->node, n);
return node ? node->data : NULL;
}
@@ -1490,14 +1472,16 @@ mrp_task_get_nth_child (MrpTask *task, guint n)
gint
mrp_task_get_position (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
GNode *parent;
g_return_val_if_fail (MRP_IS_TASK (task), 0);
- g_return_val_if_fail (task->priv->node->parent != NULL, 0);
+ g_return_val_if_fail (priv->node->parent != NULL, 0);
- parent = task->priv->node->parent;
+ parent = priv->node->parent;
- return g_node_child_position (parent, task->priv->node);
+ return g_node_child_position (parent, priv->node);
}
/**
@@ -1510,13 +1494,11 @@ mrp_task_get_position (MrpTask *task)
void
imrp_task_add_assignment (MrpTask *task, MrpAssignment *assignment)
{
- MrpTaskPriv *priv;
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
g_return_if_fail (MRP_IS_TASK (task));
g_return_if_fail (MRP_IS_ASSIGNMENT (assignment));
- priv = task->priv;
-
priv->assignments = g_list_prepend (priv->assignments,
g_object_ref (assignment));
@@ -1541,9 +1523,11 @@ imrp_task_add_assignment (MrpTask *task, MrpAssignment *assignment)
mrptime
mrp_task_get_start (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), 0);
- return task->priv->start;
+ return priv->start;
}
/**
@@ -1557,9 +1541,11 @@ mrp_task_get_start (MrpTask *task)
mrptime
mrp_task_get_finish (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), 0);
- return task->priv->finish;
+ return priv->finish;
}
/**
@@ -1576,9 +1562,11 @@ mrp_task_get_finish (MrpTask *task)
mrptime
mrp_task_get_work_start (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), 0);
- return task->priv->work_start;
+ return priv->work_start;
}
/**
@@ -1593,7 +1581,8 @@ mrp_task_get_work_start (MrpTask *task)
mrptime
mrp_task_get_latest_start (MrpTask *task)
{
- return task->priv->latest_start;
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+ return priv->latest_start;
}
/**
@@ -1608,7 +1597,8 @@ mrp_task_get_latest_start (MrpTask *task)
mrptime
mrp_task_get_latest_finish (MrpTask *task)
{
- return task->priv->latest_finish;
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+ return priv->latest_finish;
}
/**
@@ -1623,9 +1613,11 @@ mrp_task_get_latest_finish (MrpTask *task)
gint
mrp_task_get_duration (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), 0);
- return task->priv->duration;
+ return priv->duration;
}
/**
@@ -1639,9 +1631,11 @@ mrp_task_get_duration (MrpTask *task)
gint
mrp_task_get_work (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), 0);
- return task->priv->work;
+ return priv->work;
}
/**
@@ -1655,9 +1649,11 @@ mrp_task_get_work (MrpTask *task)
gint
mrp_task_get_priority (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), 0);
- return task->priv->priority;
+ return priv->priority;
}
#ifdef WITH_SIMPLE_PRIORITY_SCHEDULING
@@ -1672,6 +1668,7 @@ mrp_task_get_priority (MrpTask *task)
gboolean
mrp_task_is_dominant (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
MrpConstraint constraint;
g_return_val_if_fail (MRP_IS_TASK (task), 0);
@@ -1681,7 +1678,7 @@ mrp_task_is_dominant (MrpTask *task)
return (FALSE);
}
- if (task->priv->priority != MRP_DOMINANT_PRIORITY) {
+ if (priv->priority != MRP_DOMINANT_PRIORITY) {
return (FALSE);
}
@@ -1699,9 +1696,11 @@ mrp_task_is_dominant (MrpTask *task)
GList *
mrp_task_get_unit_ivals (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), 0);
- return task->priv->unit_ivals;
+ return priv->unit_ivals;
}
/**
@@ -1716,16 +1715,18 @@ mrp_task_get_unit_ivals (MrpTask *task)
GList *
mrp_task_set_unit_ivals (MrpTask *task, GList *ivals)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), 0);
- if (task->priv->unit_ivals) {
- g_list_foreach (task->priv->unit_ivals, (GFunc) g_free, NULL);
- g_list_free (task->priv->unit_ivals);
- task->priv->unit_ivals = NULL;
+ if (priv->unit_ivals) {
+ g_list_foreach (priv->unit_ivals, (GFunc) g_free, NULL);
+ g_list_free (priv->unit_ivals);
+ priv->unit_ivals = NULL;
}
- task->priv->unit_ivals = ivals;
+ priv->unit_ivals = ivals;
- return task->priv->unit_ivals;
+ return priv->unit_ivals;
}
/**
@@ -1739,9 +1740,11 @@ mrp_task_set_unit_ivals (MrpTask *task, GList *ivals)
GList *
mrp_task_get_assignments (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), NULL);
- return task->priv->assignments;
+ return priv->assignments;
}
/**
@@ -1779,12 +1782,13 @@ gint mrp_task_get_nres (MrpTask *task)
MrpAssignment *
mrp_task_get_assignment (MrpTask *task, MrpResource *resource)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
GList *l;
g_return_val_if_fail (MRP_IS_TASK (task), NULL);
g_return_val_if_fail (MRP_IS_RESOURCE (resource), NULL);
- for (l = task->priv->assignments; l; l = l->next) {
+ for (l = priv->assignments; l; l = l->next) {
MrpAssignment *assignment = l->data;
if (mrp_assignment_get_resource (assignment) == resource) {
@@ -1807,12 +1811,13 @@ mrp_task_get_assignment (MrpTask *task, MrpResource *resource)
GList *
mrp_task_get_assigned_resources (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
GList *list = NULL;
GList *l;
g_return_val_if_fail (MRP_IS_TASK (task), NULL);
- for (l = task->priv->assignments; l; l = l->next) {
+ for (l = priv->assignments; l; l = l->next) {
MrpAssignment *assignment = l->data;
list = g_list_prepend (
@@ -1836,7 +1841,10 @@ mrp_task_get_assigned_resources (MrpTask *task)
gint
mrp_task_compare (gconstpointer a, gconstpointer b)
{
- return strcmp (MRP_TASK (a)->priv->name, MRP_TASK (b)->priv->name);
+ MrpTaskPrivate *priv_a = mrp_task_get_instance_private (MRP_TASK ((gpointer *)a));
+ MrpTaskPrivate *priv_b = mrp_task_get_instance_private (MRP_TASK ((gpointer *)b));
+
+ return strcmp (priv_a->name, priv_b->name);
}
/**
@@ -1848,10 +1856,12 @@ mrp_task_compare (gconstpointer a, gconstpointer b)
void
mrp_task_reset_constraint (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_if_fail (MRP_IS_TASK (task));
- if (task->priv->constraint.type != MRP_CONSTRAINT_ASAP) {
- task->priv->constraint.type = MRP_CONSTRAINT_ASAP;
+ if (priv->constraint.type != MRP_CONSTRAINT_ASAP) {
+ priv->constraint.type = MRP_CONSTRAINT_ASAP;
g_object_notify (G_OBJECT (task), "constraint");
}
}
@@ -1867,7 +1877,7 @@ mrp_task_reset_constraint (MrpTask *task)
gfloat
mrp_task_get_cost (MrpTask *task)
{
- MrpTaskPriv *priv;
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
GList *assignments, *l;
MrpResource *resource;
gfloat total = 0;
@@ -1876,8 +1886,6 @@ mrp_task_get_cost (MrpTask *task)
g_return_val_if_fail (MRP_IS_TASK (task), 0);
- priv = task->priv;
-
if (priv->cost_cached) {
return priv->cost;
}
@@ -1915,12 +1923,14 @@ mrp_task_get_cost (MrpTask *task)
void
mrp_task_invalidate_cost (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_if_fail (MRP_IS_TASK (task));
- task->priv->cost_cached = FALSE;
+ priv->cost_cached = FALSE;
- if (task->priv->node->parent) {
- mrp_task_invalidate_cost (task->priv->node->parent->data);
+ if (priv->node->parent) {
+ mrp_task_invalidate_cost (priv->node->parent->data);
}
}
@@ -1956,129 +1966,158 @@ mrp_constraint_get_type (void)
void
imrp_task_set_visited (MrpTask *task, gboolean visited)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_if_fail (MRP_IS_TASK (task));
- task->priv->visited = visited;
+ priv->visited = visited;
}
gboolean
imrp_task_get_visited (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), FALSE);
- return task->priv->visited;
+ return priv->visited;
}
void
imrp_task_set_start (MrpTask *task, mrptime start)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_if_fail (MRP_IS_TASK (task));
- task->priv->start = start;
+ priv->start = start;
}
void
imrp_task_set_work_start (MrpTask *task, mrptime work_start)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_if_fail (MRP_IS_TASK (task));
- task->priv->work_start = work_start;
+ priv->work_start = work_start;
}
void
imrp_task_set_finish (MrpTask *task, mrptime finish)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_if_fail (MRP_IS_TASK (task));
- task->priv->finish = finish;
+ priv->finish = finish;
}
void
imrp_task_set_duration (MrpTask *task, gint duration)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_if_fail (MRP_IS_TASK (task));
- task->priv->duration = duration;
+ priv->duration = duration;
}
void
imrp_task_set_work (MrpTask *task, gint work)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_if_fail (MRP_IS_TASK (task));
- task->priv->work = work;
+ priv->work = work;
}
void
imrp_task_set_latest_start (MrpTask *task,
mrptime time)
{
- task->priv->latest_start = time;
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+ priv->latest_start = time;
}
void
imrp_task_set_latest_finish (MrpTask *task,
mrptime time)
{
- task->priv->latest_finish = time;
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+ priv->latest_finish = time;
}
MrpConstraint
imrp_task_get_constraint (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
MrpConstraint c = { 0 };
g_return_val_if_fail (MRP_IS_TASK (task), c);
- return task->priv->constraint;
+ return priv->constraint;
}
void
imrp_task_set_constraint (MrpTask *task, MrpConstraint constraint)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_if_fail (MRP_IS_TASK (task));
- task->priv->constraint = constraint;
+ priv->constraint = constraint;
}
gint
imrp_task_get_depth (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), 0);
- return g_node_depth (task->priv->node);
+ return g_node_depth (priv->node);
}
GNode *
imrp_task_get_node (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), NULL);
- return task->priv->node;
+ return priv->node;
}
MrpTaskGraphNode *
imrp_task_get_graph_node (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), NULL);
- return task->priv->graph_node;
+ return priv->graph_node;
}
GList *
imrp_task_peek_predecessors (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), NULL);
- return task->priv->predecessors;
+ return priv->predecessors;
}
GList *
imrp_task_peek_successors (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), NULL);
- return task->priv->successors;
+ return priv->successors;
}
/**
@@ -2091,9 +2130,11 @@ imrp_task_peek_successors (MrpTask *task)
MrpTaskType
mrp_task_get_task_type (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), MRP_TASK_TYPE_NORMAL);
- return task->priv->type;
+ return priv->type;
}
/**
@@ -2106,9 +2147,11 @@ mrp_task_get_task_type (MrpTask *task)
MrpTaskSched
mrp_task_get_sched (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), MRP_TASK_SCHED_FIXED_WORK);
- return task->priv->sched;
+ return priv->sched;
}
/**
@@ -2121,9 +2164,11 @@ mrp_task_get_sched (MrpTask *task)
gshort
mrp_task_get_percent_complete (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), 0);
- return task->priv->percent_complete;
+ return priv->percent_complete;
}
/**
@@ -2136,7 +2181,9 @@ mrp_task_get_percent_complete (MrpTask *task)
gboolean
mrp_task_get_critical (MrpTask *task)
{
+ MrpTaskPrivate *priv = mrp_task_get_instance_private (task);
+
g_return_val_if_fail (MRP_IS_TASK (task), FALSE);
- return task->priv->critical;
+ return priv->critical;
}
diff --git a/libplanner/mrp-task.h b/libplanner/mrp-task.h
index 09e11b0c..61701dd4 100644
--- a/libplanner/mrp-task.h
+++ b/libplanner/mrp-task.h
@@ -21,27 +21,22 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __MRP_TASK_H__
-#define __MRP_TASK_H__
+#pragma once
#include <libplanner/mrp-object.h>
#include <libplanner/mrp-types.h>
#include <libplanner/mrp-time.h>
#include <libplanner/mrp-assignment.h>
+G_BEGIN_DECLS
+
#define MRP_TYPE_TASK (mrp_task_get_type ())
-#define MRP_TASK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MRP_TYPE_TASK, MrpTask))
-#define MRP_TASK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MRP_TYPE_TASK, MrpTaskClass))
-#define MRP_IS_TASK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MRP_TYPE_TASK))
-#define MRP_IS_TASK_CLASS(klass) (G_TYPE_CHECK_TYPE ((obj), MRP_TYPE_TASK))
-#define MRP_TASK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MRP_TYPE_TASK, MrpTaskClass))
+
+G_DECLARE_FINAL_TYPE (MrpTask, mrp_task, MRP, TASK, MrpObject)
#define MRP_TYPE_CONSTRAINT (mrp_constraint_get_type ())
#define MRP_TYPE_RELATION (mrp_relation_get_type ())
-typedef struct _MrpTaskClass MrpTaskClass;
-typedef struct _MrpTaskPriv MrpTaskPriv;
-
/**
* MrpUnitsInterval:
* @is_start: is start.
@@ -86,22 +81,9 @@ typedef struct {
#define MRP_DOMINANT_PRIORITY 9999
#endif
-#include <libplanner/mrp-relation.h>
+typedef struct _MrpRelation MrpRelation;
-struct _MrpTask
-{
- MrpObject parent;
- MrpTaskPriv *priv;
-};
-
-struct _MrpTaskClass
-{
- MrpObjectClass parent_class;
-};
-
-GType mrp_task_get_type (void) G_GNUC_CONST;
GType mrp_constraint_get_type (void) G_GNUC_CONST;
-GType mrp_relation_get_type (void) G_GNUC_CONST;
MrpTask *mrp_task_new (void);
const gchar *mrp_task_get_name (MrpTask *task);
void mrp_task_set_name (MrpTask *task,
@@ -170,5 +152,4 @@ MrpTaskSched mrp_task_get_sched (MrpTask *task);
gshort mrp_task_get_percent_complete (MrpTask *task);
gboolean mrp_task_get_critical (MrpTask *task);
-
-#endif /* __MRP_TASK_H__ */
+G_END_DECLS
diff --git a/libplanner/mrp-xml.c b/libplanner/mrp-xml.c
index 0e2b9b31..cb2239ff 100644
--- a/libplanner/mrp-xml.c
+++ b/libplanner/mrp-xml.c
@@ -88,7 +88,7 @@ xml_read_context (xmlParserCtxt *ctxt,
default:
ret_val = FALSE;
break;
- };
+ }
xmlFreeDoc (doc);
@@ -172,5 +172,5 @@ init (MrpFileModule *module, MrpApplication *application)
reader->read_string = xml_read_string;
- imrp_application_register_reader (application, reader);
+ mrp_application_register_reader (application, reader);
}
diff --git a/libplanner/mrp-xsl.c b/libplanner/mrp-xsl.c
index ee5ed56e..445439ef 100644
--- a/libplanner/mrp-xsl.c
+++ b/libplanner/mrp-xsl.c
@@ -230,7 +230,7 @@ init (MrpFileModule *module, MrpApplication *application)
writer->write = html_write;
- imrp_application_register_writer (application, writer);
+ mrp_application_register_writer (application, writer);
/* The older Planner/Mrproject writer registration */
@@ -243,6 +243,6 @@ init (MrpFileModule *module, MrpApplication *application)
writer->write = xml_planner_pre012_write;
- imrp_application_register_writer (application, writer);
+ mrp_application_register_writer (application, writer);
}
diff --git a/src/planner-gantt-chart.c b/src/planner-gantt-chart.c
index 55257382..15a0604b 100644
--- a/src/planner-gantt-chart.c
+++ b/src/planner-gantt-chart.c
@@ -30,6 +30,7 @@
#include <gdk/gdkkeysyms.h>
#include <glib/gi18n.h>
#include <libplanner/mrp-task.h>
+#include <libplanner/mrp-relation.h>
#include "planner-marshal.h"
#include "planner-conf.h"
#include "planner-gantt-chart.h"
diff --git a/src/planner-gantt-print.c b/src/planner-gantt-print.c
index b5c4a437..f8a724b9 100644
--- a/src/planner-gantt-print.c
+++ b/src/planner-gantt-print.c
@@ -27,6 +27,7 @@
#include <libplanner/mrp-project.h>
#include <libplanner/mrp-task.h>
#include <libplanner/mrp-resource.h>
+#include <libplanner/mrp-relation.h>
#include <glib/gi18n.h>
#include "planner-print-job.h"
#include "planner-format.h"
diff --git a/src/planner-predecessor-model.c b/src/planner-predecessor-model.c
index 75891618..735ee1d6 100644
--- a/src/planner-predecessor-model.c
+++ b/src/planner-predecessor-model.c
@@ -24,6 +24,7 @@
#include <config.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
+#include <libplanner/mrp-relation.h>
#include "planner-predecessor-model.h"
struct _PlannerPredecessorModelPriv {
diff --git a/src/planner-task-cmd.c b/src/planner-task-cmd.c
index deb01655..8f79f0f6 100644
--- a/src/planner-task-cmd.c
+++ b/src/planner-task-cmd.c
@@ -21,6 +21,7 @@
#include <config.h>
#include <glib/gi18n.h>
+#include <libplanner/mrp-relation.h>
#include "planner-task-cmd.h"
#include "planner-task-tree.h"
diff --git a/src/planner-task-dialog.c b/src/planner-task-dialog.c
index a379364d..1ba2c13e 100644
--- a/src/planner-task-dialog.c
+++ b/src/planner-task-dialog.c
@@ -32,6 +32,7 @@
#include <libplanner/mrp-project.h>
#include <libplanner/mrp-private.h>
#include "libplanner/mrp-paths.h"
+#include <libplanner/mrp-relation.h>
#include "planner-assignment-model.h"
#include "planner-predecessor-model.h"
#include "planner-task-cmd.h"
diff --git a/src/planner-task-tree.c b/src/planner-task-tree.c
index 82d1d54c..e3db94eb 100644
--- a/src/planner-task-tree.c
+++ b/src/planner-task-tree.c
@@ -40,7 +40,7 @@
#include "planner-gantt-model.h"
#include "planner-task-popup.h"
#include "planner-util.h"
-
+#include <libplanner/mrp-relation.h>
#define WARN_TASK_DIALOGS 10
#define MAX_TASK_DIALOGS 25
diff --git a/tests/task-test.c b/tests/task-test.c
index b93c9d8b..42e8ccaf 100644
--- a/tests/task-test.c
+++ b/tests/task-test.c
@@ -4,6 +4,7 @@
#include <string.h>
#include <stdlib.h>
#include "libplanner/mrp-project.h"
+#include "libplanner/mrp-relation.h"
#include "self-check.h"
#define DAY (60*60*8)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]