File: myx_grt_private.c

package info (click to toggle)
mysql-query-browser 1.2.5beta-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 63,792 kB
  • ctags: 46,485
  • sloc: pascal: 249,299; ansic: 80,111; cpp: 72,467; sh: 25,271; objc: 20,015; yacc: 10,755; java: 9,917; xml: 4,580; php: 2,806; python: 1,566; sql: 1,563; makefile: 1,452; perl: 3
file content (155 lines) | stat: -rw-r--r-- 4,941 bytes parent folder | download | duplicates (4)
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
/* Copyright (c) 2004, 2005 MySQL AB
  
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
  
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.
  
   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
 */


#include "myx_grt_private.h"

//----------------------------------------------------------------------------------------------------------------------

/*
 * @brief return the loader struct for the required type
 *
 * @param grt - the GRT environment
 * @param type - type of module loader to look up
 * @return NULL if error, the loader if it's found.
 */
MYX_GRT_MODULE_LOADER *myx_grt_get_loader_of_type(MYX_GRT *grt, MYX_GRT_MODULE_TYPE type)
{
  unsigned int i;
  for (i= 0; i < grt->loaders_num; i++)
  {
    if (grt->loaders[i]->loader_type == type)
      return grt->loaders[i];
  }
  return NULL;
}

//----------------------------------------------------------------------------------------------------------------------

/*
 * @brief myx_grt_add_module -- adds a module to the list of modules of the GRT
 *
 * @param grt grt to add module
 * @param module to add. Must not be freed
 * @return MYX_GRT_NO_ERROR
 */
MYX_GRT_ERROR myx_grt_add_module(MYX_GRT *grt, MYX_GRT_MODULE *module)
{  
  if (grt->options & MYX_GRT_VERBOSE)
    myx_grt_printf(grt, "GRT registering module %s\n", module->name);

  grt->modules= g_realloc(grt->modules, sizeof(MYX_GRT_MODULE*)*(grt->modules_num+1));
  grt->modules[grt->modules_num++]= module;
  
  myx_grt_notify_listeners(grt, GRT_MODULE_ADD_NOTIFICATION, module);

  return MYX_GRT_NO_ERROR;
}

//----------------------------------------------------------------------------------------------------------------------

/**
 * Searchs the internal module list and returns the first module with the given name (if there is one).
 *
 * @param grt The runtime to operate on.
 * @param name The name of the module to look for.
 * @return The module reference if one could be found. Otherwise NULL.
 */
MYX_GRT_MODULE* myx_grt_find_module(MYX_GRT *grt, char* name)
{
  MYX_GRT_MODULE* Result = NULL;
  unsigned int I;
  for (I = 0; I < grt->modules_num; ++I)
    if (strcmp(grt->modules[I]->name, name) == 0)
    {
      Result = grt->modules[I];
      break;
    };

  return Result;
}

//----------------------------------------------------------------------------------------------------------------------

/*
 * Removes the given module from the list of modules in the given runtime.
 *
 * @param grt grt to add module
 * @param module to add. Must not be freed
 */
void myx_grt_remove_module(MYX_GRT *grt, MYX_GRT_MODULE *module)
{
  unsigned int I;
  for (I = 0; I < grt->modules_num; ++I)
    if (grt->modules[I] == module)
    {
      if (I < grt->modules_num - 1)
        memcpy(grt->modules[I], grt->modules[I + 1], sizeof(MYX_GRT_MODULE*) * (grt->modules_num - I - 1));
      grt->modules = g_realloc(grt->modules, sizeof(MYX_GRT_MODULE*) * (--grt->modules_num));
      break;
    };
}

//----------------------------------------------------------------------------------------------------------------------

void myx_grt_parse_function_spec(const char *spec, MYX_GRT_FUNCTION *func)
{
  char *tmp= g_strdup(spec);

  func->name= g_strdup(strtok(tmp, ":"));
  func->param_struct_name= g_strdup(strtok(NULL, ":"));
  func->return_struct_name= g_strdup(strtok(NULL, ":"));

  g_free(tmp);
}

//----------------------------------------------------------------------------------------------------------------------



void myx_grt_add_listener(MYX_GRT *grt, void (*callback)(MYX_GRT*,char*,void*,void*),
                          char *name, void *userdata)
{
  MYX_GRT_LISTENER *listener;
  
  listener= g_new0(MYX_GRT_LISTENER, 1);
  
  listener->wanted_name= g_strdup(name);
  listener->userdata= userdata;
  listener->callback= callback;
  
  listener->next= grt->listeners;
  grt->listeners= listener;
}



void myx_grt_notify_listeners(MYX_GRT *grt, char *name, void *argument)
{
  MYX_GRT_LISTENER *listener= grt->listeners;
  
  while (listener)
  {
    if (!listener->wanted_name || strcmp(name, listener->wanted_name)==0)
    {
      (*listener->callback)(grt, name, argument, listener->userdata);
    }
    
    listener= listener->next;
  }
}