File: hints.c

package info (click to toggle)
zynjacku 5.2-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,292 kB
  • ctags: 1,584
  • sloc: sh: 9,039; ansic: 7,934; python: 3,138; makefile: 98
file content (204 lines) | stat: -rw-r--r-- 4,986 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*****************************************************************************
 *
 *   This file is part of zynjacku
 *
 *   Copyright (C) 2006,2007,2008,2009 Nedko Arnaudov <nedko@arnaudov.name>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; version 2 of the License
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *****************************************************************************/

#include <glib-object.h>
#include <lv2.h>

#include "hints.h"

//#define LOG_LEVEL LOG_LEVEL_DEBUG
#include "log.h"

struct zynjacku_hints
{
  gboolean dispose_has_run;

  guint count;
  GArray * names;
  GArray * values;
};

#define ZYNJACKU_HINTS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), ZYNJACKU_HINTS_TYPE, struct zynjacku_hints))

static void
zynjacku_hints_dispose(GObject * obj)
{
  struct zynjacku_hints * hints_ptr;

  hints_ptr = ZYNJACKU_HINTS_GET_PRIVATE(obj);

  LOG_DEBUG("zynjacku_hints_dispose() called.");

  if (hints_ptr->dispose_has_run)
  {
    /* If dispose did already run, return. */
    LOG_DEBUG("zynjacku_hints_dispose() already run!");
    return;
  }

  /* Make sure dispose does not run twice. */
  hints_ptr->dispose_has_run = TRUE;

  /* 
   * In dispose, you are supposed to free all types referenced from this
   * object which might themselves hold a reference to self. Generally,
   * the most simple solution is to unref all members on which you own a 
   * reference.
   */
  g_array_free(hints_ptr->names, TRUE);
  g_array_free(hints_ptr->values, TRUE);

  /* Chain up to the parent class */
  G_OBJECT_CLASS(g_type_class_peek_parent(G_OBJECT_GET_CLASS(obj)))->dispose(obj);
}

static void
zynjacku_hints_finalize(GObject * obj)
{
//  struct zynjacku_hints * self = ZYNJACKU_HINTS_GET_PRIVATE(obj);

  LOG_DEBUG("zynjacku_hints_finalize() called.");

  /*
   * Here, complete object destruction.
   * You might not need to do much...
   */
  //g_free(self->private);

  /* Chain up to the parent class */
  G_OBJECT_CLASS(g_type_class_peek_parent(G_OBJECT_GET_CLASS(obj)))->finalize(obj);
}

static void
zynjacku_hints_class_init(
  gpointer class_ptr,
  gpointer class_data_ptr)
{
  LOG_DEBUG("zynjacku_hints_class() called.");

  G_OBJECT_CLASS(class_ptr)->dispose = zynjacku_hints_dispose;
  G_OBJECT_CLASS(class_ptr)->finalize = zynjacku_hints_finalize;

  g_type_class_add_private(G_OBJECT_CLASS(class_ptr), sizeof(struct zynjacku_hints));
}

static void
zynjacku_hints_init(
  GTypeInstance * instance,
  gpointer g_class)
{
  struct zynjacku_hints * hints_ptr;

  LOG_DEBUG("zynjacku_hints_init() called.");

  hints_ptr = ZYNJACKU_HINTS_GET_PRIVATE(instance);

  hints_ptr->names = g_array_new(TRUE, TRUE, sizeof(gchar *));
  hints_ptr->values = g_array_new(TRUE, TRUE, sizeof(gchar *));
}

GType zynjacku_hints_get_type()
{
  static GType type = 0;
  if (type == 0)
  {
    type = g_type_register_static_simple(
      G_TYPE_OBJECT,
      "zynjacku_hints_type",
      sizeof(ZynjackuHintsClass),
      zynjacku_hints_class_init,
      sizeof(ZynjackuHints),
      zynjacku_hints_init,
      0);
  }

  return type;
}

guint
zynjacku_hints_get_count(
  ZynjackuHints * hints_obj_ptr)
{
  struct zynjacku_hints * hints_ptr;

  hints_ptr = ZYNJACKU_HINTS_GET_PRIVATE(hints_obj_ptr);

  return hints_ptr->count;
}

const gchar *
zynjacku_hints_get_name_at_index(
  ZynjackuHints * hints_obj_ptr,
  guint index)
{
  struct zynjacku_hints * hints_ptr;

  hints_ptr = ZYNJACKU_HINTS_GET_PRIVATE(hints_obj_ptr);

  return g_array_index(hints_ptr->names, gchar *, index);
}

const gchar *
zynjacku_hints_get_value_at_index(
  ZynjackuHints * hints_obj_ptr,
  guint index)
{
  struct zynjacku_hints * hints_ptr;

  hints_ptr = ZYNJACKU_HINTS_GET_PRIVATE(hints_obj_ptr);

  return g_array_index(hints_ptr->values, gchar *, index);
}

void
zynjacku_hints_set(
  ZynjackuHints * hints_obj_ptr,
  guint count,
  const gchar * const * names,
  const gchar * const * values)
{
  guint i;
  struct zynjacku_hints * hints_ptr;
  gchar * name;
  gchar * value;

  hints_ptr = ZYNJACKU_HINTS_GET_PRIVATE(hints_obj_ptr);

  for (i = 0 ; i < count ; i++)
  {
    name = g_strdup(names[i]);
    g_array_append_val(hints_ptr->names, name);

    if (values[i] == NULL)
    {
      value = NULL;
    }
    else
    {
      value = g_strdup(values[i]);
    }

    g_array_append_val(hints_ptr->values, value);
  }

  hints_ptr->count = count;
}