restructure code
This commit is contained in:
parent
bddeabe365
commit
6dbff67bee
@ -8,9 +8,11 @@ PKG_CHECK_MODULES(GLIB2 REQUIRED glib-2.0)
|
||||
PKG_CHECK_MODULES(GOBJECT2 REQUIRED gobject-2.0)
|
||||
|
||||
SET(SOURCES
|
||||
"include/edapi/commander.h"
|
||||
"include/edapi/journal/entry.h"
|
||||
"include/edapi/journal/file.h"
|
||||
"include/edapi/journal/journal.h"
|
||||
"src/commander.c"
|
||||
"src/journal/entry.c"
|
||||
"src/journal/file.c"
|
||||
"src/journal/journal.c"
|
||||
|
25
lib/include/edapi/commander.h
Normal file
25
lib/include/edapi/commander.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef EDAPI_COMMANDER_H
|
||||
#define EDAPI_COMMANDER_H
|
||||
|
||||
#include <edapi/journal/entry.h>
|
||||
#include <edapi/error.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
G_DECLARE_FINAL_TYPE(EDCommander, ed_commander, ED, COMMANDER, GObject);
|
||||
|
||||
#define ED_TYPE_COMMANDER ed_commander_get_type()
|
||||
|
||||
EDCommander *ed_commander_new(void);
|
||||
|
||||
EDCommander *ed_commander_new_from_entry(EDJournalEntry *entry);
|
||||
|
||||
gchar const *ed_commander_get_name(EDCommander *self);
|
||||
gchar const *ed_commander_get_fid(EDCommander *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
@ -2,6 +2,7 @@
|
||||
#define EDAPI_JOURNAL_FILE_H
|
||||
|
||||
#include <edapi/journal/entry.h>
|
||||
#include <edapi/commander.h>
|
||||
#include <edapi/error.h>
|
||||
|
||||
#include <glib.h>
|
||||
@ -43,7 +44,7 @@ EDErrorCode ed_journal_file_load(EDJournalFile *self, GError **error);
|
||||
|
||||
GDateTime *ed_journal_file_get_datetime(EDJournalFile *self);
|
||||
|
||||
gchar const *ed_journal_file_get_commander(EDJournalFile *self);
|
||||
EDCommander *ed_journal_file_get_commander(EDJournalFile *self);
|
||||
|
||||
gchar const *ed_journal_file_get_gameversion(EDJournalFile *self);
|
||||
|
||||
|
97
lib/src/commander.c
Normal file
97
lib/src/commander.c
Normal file
@ -0,0 +1,97 @@
|
||||
#include <edapi/commander.h>
|
||||
|
||||
#include <edapi/util.h>
|
||||
|
||||
typedef struct {
|
||||
gchar *name;
|
||||
gchar *fid;
|
||||
} EDCommanderPrivate;
|
||||
|
||||
struct _EDCommander {
|
||||
GObject parent;
|
||||
};
|
||||
|
||||
struct _EDCommanderClass {
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED(
|
||||
EDCommander,
|
||||
ed_commander,
|
||||
G_TYPE_OBJECT,
|
||||
0,
|
||||
G_ADD_PRIVATE(EDCommander)
|
||||
);
|
||||
|
||||
static void ed_commander_dispose(GObject *obj)
|
||||
{
|
||||
G_OBJECT_CLASS(ed_commander_parent_class)->dispose(obj);
|
||||
}
|
||||
|
||||
static void ed_commander_finalize(GObject *obj)
|
||||
{
|
||||
EDCommander *self = ED_COMMANDER(obj);
|
||||
EDCommanderPrivate *p = ed_commander_get_instance_private(self);
|
||||
|
||||
g_free(p->name);
|
||||
p->name = NULL;
|
||||
|
||||
g_free(p->fid);
|
||||
p->fid = NULL;
|
||||
|
||||
G_OBJECT_CLASS(ed_commander_parent_class)->finalize(obj);
|
||||
}
|
||||
|
||||
static void ed_commander_class_init(EDCommanderClass *klass)
|
||||
{
|
||||
G_OBJECT_CLASS(klass)->dispose = ed_commander_dispose;
|
||||
G_OBJECT_CLASS(klass)->finalize = ed_commander_finalize;
|
||||
}
|
||||
|
||||
static void ed_commander_init(EDCommander *self)
|
||||
{
|
||||
}
|
||||
|
||||
EDCommander *ed_commander_new(void)
|
||||
{
|
||||
return g_object_new(ED_TYPE_COMMANDER, NULL);
|
||||
}
|
||||
|
||||
EDCommander *ed_commander_new_from_entry(EDJournalEntry *entry)
|
||||
{
|
||||
return_if_true(entry == NULL, NULL);
|
||||
|
||||
if (!ed_journal_entry_is(entry, ED_JOURNAL_ENTRY_COMMANDER)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gchar const *cmdr = NULL;
|
||||
gchar const *fid = NULL;
|
||||
|
||||
cmdr = ed_journal_entry_get_string(entry, "Name");
|
||||
fid = ed_journal_entry_get_string(entry, "FID");
|
||||
|
||||
return_if_true(S_EMPTY(cmdr) || S_EMPTY(fid), NULL);
|
||||
|
||||
EDCommander *self = ed_commander_new();
|
||||
return_if_true(self == NULL, NULL);
|
||||
|
||||
EDCommanderPrivate *p = ed_commander_get_instance_private(self);
|
||||
|
||||
p->name = g_strdup(cmdr);
|
||||
p->fid = g_strdup(fid);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
gchar const *ed_commander_get_name(EDCommander *self)
|
||||
{
|
||||
EDCommanderPrivate *p = ed_commander_get_instance_private(self);
|
||||
return p->name;
|
||||
}
|
||||
|
||||
gchar const *ed_commander_get_fid(EDCommander *self)
|
||||
{
|
||||
EDCommanderPrivate *p = ed_commander_get_instance_private(self);
|
||||
return p->fid;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
#include <edapi/journal/file.h>
|
||||
#include <edapi/journal/entry.h>
|
||||
#include <edapi/commander.h>
|
||||
#include <edapi/util.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
@ -11,7 +12,7 @@ typedef struct {
|
||||
GDateTime *timestamp;
|
||||
gint part;
|
||||
GList *entries;
|
||||
gchar *commander;
|
||||
EDCommander *commander;
|
||||
gchar *gameversion;
|
||||
|
||||
EDJournalEntry *first;
|
||||
@ -41,6 +42,7 @@ static void ed_journal_file_dispose(GObject *obj)
|
||||
|
||||
g_clear_object(&p->first);
|
||||
g_clear_object(&p->last);
|
||||
g_clear_object(&p->commander);
|
||||
|
||||
G_OBJECT_CLASS(ed_journal_file_parent_class)->dispose(obj);
|
||||
}
|
||||
@ -64,9 +66,6 @@ static void ed_journal_file_finalize(GObject *obj)
|
||||
p->timestamp = NULL;
|
||||
}
|
||||
|
||||
g_free(p->commander);
|
||||
p->commander = NULL;
|
||||
|
||||
g_free(p->gameversion);
|
||||
p->gameversion = NULL;
|
||||
|
||||
@ -248,14 +247,8 @@ ed_journal_file_parse_commander(EDJournalFile *self,
|
||||
EDJournalFilePrivate *p,
|
||||
EDJournalEntry *e)
|
||||
{
|
||||
gchar const *cmdr = ed_journal_entry_get_string(
|
||||
e, "Name");
|
||||
|
||||
if (!S_EMPTY(cmdr)) {
|
||||
g_free(p->commander);
|
||||
p->commander = g_strdup(cmdr);
|
||||
}
|
||||
|
||||
p->commander = ed_commander_new_from_entry(e);
|
||||
return ed_error_success;
|
||||
}
|
||||
|
||||
@ -563,7 +556,7 @@ GDateTime *ed_journal_file_get_datetime(EDJournalFile *self)
|
||||
return p->timestamp;
|
||||
}
|
||||
|
||||
gchar const *ed_journal_file_get_commander(EDJournalFile *self)
|
||||
EDCommander *ed_journal_file_get_commander(EDJournalFile *self)
|
||||
{
|
||||
return_if_true(self == NULL, NULL);
|
||||
EDJournalFilePrivate *p = ed_journal_file_get_instance_private(self);
|
||||
|
@ -134,8 +134,11 @@ static void test_valid_peek(void **state)
|
||||
assert_int_equal(ret, ed_error_success);
|
||||
|
||||
char const *sval = NULL;
|
||||
EDCommander *cmdr = NULL;
|
||||
|
||||
sval = ed_journal_file_get_commander(file);
|
||||
cmdr = ed_journal_file_get_commander(file);
|
||||
assert_non_null(cmdr);
|
||||
sval = ed_commander_get_name(cmdr);
|
||||
assert_non_null(sval);
|
||||
assert_string_equal(sval, "DeiMuata");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user