summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Contreras <felipe.contreras@gmail.com>2010-06-13 12:07:05 +0300
committerFelipe Contreras <felipe.contreras@gmail.com>2010-06-14 03:13:33 +0300
commit62291575830a516869f224b77e7d4d566667ddcf (patch)
tree362283822aae78d689cc3f1bcc3eb12f293a82d3
parent6d8d5d2f5ede85d5b03555bc28d23e3729e49015 (diff)
Add pn_ns
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
-rw-r--r--Makefile2
-rw-r--r--pn_ns.c122
-rw-r--r--pn_ns.h30
3 files changed, 153 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index c1548e1..4978e49 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ QUIET_CLEAN = @echo ' CLEAN '$@;
endif
test: test.o pn_core.o pn_session.o pn_node.o \
- pn_trans.o pn_cmd_node.o \
+ pn_trans.o pn_cmd_node.o pn_ns.o \
pn_log.o pn_printf.o
test: override CFLAGS += $(GIO_CFLAGS)
test: override LIBS += $(GIO_LIBS)
diff --git a/pn_ns.c b/pn_ns.c
new file mode 100644
index 0000000..1a91acc
--- /dev/null
+++ b/pn_ns.c
@@ -0,0 +1,122 @@
+#include "pn_ns.h"
+
+#include "pn_cmd_node.h"
+#include "pn_session.h"
+
+static void *parent_class;
+
+struct pn_ns_priv {
+ struct pn_session *session;
+};
+
+enum {
+ PROP_SESSION = 1,
+};
+
+struct pn_ns *
+pn_ns_new(struct pn_session *session)
+{
+ return g_object_new(PN_NS_TYPE,
+ "session", session,
+ NULL);
+}
+
+void
+pn_ns_free(struct pn_ns *ns)
+{
+ if (!ns)
+ return;
+ g_object_unref(ns);
+}
+
+/* GObject stuff */
+
+static void
+instance_init(GTypeInstance *instance,
+ void *g_class)
+{
+ struct pn_ns *self = PN_NS(instance);
+ struct pn_ns_priv *priv = self->priv;
+
+ self->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE(instance, PN_NS_TYPE, struct pn_ns_priv);
+}
+
+static void
+get_property(GObject *object,
+ unsigned property_id,
+ GValue *value,
+ GParamSpec *spec)
+{
+ struct pn_ns *self = PN_NS(object);
+ struct pn_ns_priv *priv = self->priv;
+
+ switch (property_id) {
+ case PROP_SESSION:
+ g_value_set_object(value, priv->session);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, spec);
+ }
+}
+
+static void
+set_property(GObject *object,
+ unsigned property_id,
+ const GValue *value,
+ GParamSpec *spec)
+{
+ struct pn_ns *self = PN_NS(object);
+ struct pn_ns_priv *priv = self->priv;
+
+ switch (property_id) {
+ case PROP_SESSION:
+ priv->session = g_value_get_object(value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, spec);
+ }
+}
+
+static void
+class_init(void *g_class,
+ void *class_data)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(g_class);
+
+ gobject_class->get_property = get_property;
+ gobject_class->set_property = set_property;
+
+ {
+ GParamSpec *param_spec;
+
+ param_spec = g_param_spec_object("session", "Session", "The Session",
+ PN_SESSION_TYPE,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+ g_object_class_install_property(gobject_class, PROP_SESSION, param_spec);
+ }
+
+ parent_class = g_type_class_peek_parent(g_class);
+ g_type_class_add_private(g_class, sizeof(struct pn_ns_priv));
+}
+
+GType
+pn_ns_get_type(void)
+{
+ static gsize init_type;
+
+ if (g_once_init_enter(&init_type)) {
+ GType type;
+ GTypeInfo type_info = {
+ .class_size = sizeof(struct pn_ns_class),
+ .class_init = class_init,
+ .instance_size = sizeof(struct pn_ns),
+ .instance_init = instance_init,
+ };
+
+ type = g_type_register_static(PN_CMD_NODE_TYPE, "PnNs", &type_info, 0);
+
+ g_once_init_leave(&init_type, type);
+ }
+
+ return init_type;
+}
diff --git a/pn_ns.h b/pn_ns.h
new file mode 100644
index 0000000..be93a07
--- /dev/null
+++ b/pn_ns.h
@@ -0,0 +1,30 @@
+#ifndef PN_NS_H
+#define PN_NS_H
+
+#include <glib-object.h>
+
+#include "pn_cmd_node.h"
+
+struct pn_ns {
+ struct pn_cmd_node parent;
+
+ struct pn_ns_priv *priv;
+};
+
+struct pn_ns_class {
+ struct pn_cmd_node_class parent_class;
+};
+
+#define PN_NS_TYPE (pn_ns_get_type())
+#define PN_NS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PN_NS_TYPE, struct pn_ns))
+#define PN_NS_CLASS(c) (G_TYPE_CHECK_CLASS_CAST((c), PN_NS_TYPE, struct pn_ns_class))
+#define PN_NS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PN_NS_TYPE, struct pn_ns_class))
+
+struct pn_session;
+
+struct pn_ns *pn_ns_new(struct pn_session *session);
+void pn_ns_free(struct pn_ns *ns);
+
+GType pn_ns_get_type(void);
+
+#endif /* PN_NS_H */