~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/protocol.cc

Created Protocol plugin interface and changed libdrizzleclient to be a plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Mark Atwood
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/protocol.h>
 
22
#include <drizzled/gettext.h>
 
23
#include <drizzled/connect.h>
 
24
 
 
25
typedef Protocol *(protocol_factory_t)(void);
 
26
 
 
27
protocol_factory_t *protocol_factory;
 
28
 
 
29
static bool protocol_inited= false; /* We must insist that only one of these plugins get loaded at a time */
 
30
 
 
31
 
 
32
extern char *opt_protocol;
 
33
 
 
34
Protocol *get_protocol()
 
35
{
 
36
  assert(protocol_factory != NULL);
 
37
  return (protocol_factory)();
 
38
}
 
39
 
 
40
int protocol_initializer(st_plugin_int *plugin)
 
41
{
 
42
  if (memcmp(plugin->plugin->name, opt_protocol, strlen(opt_protocol)))
 
43
    return 0;
 
44
 
 
45
  if (protocol_inited)
 
46
  {
 
47
    fprintf(stderr, "You cannot load more then one protocol plugin\n");
 
48
    exit(1);
 
49
  }
 
50
 
 
51
  assert(plugin->plugin->init); /* Find poorly designed plugins */
 
52
 
 
53
  if (plugin->plugin->init((void *)&protocol_factory))
 
54
  {
 
55
    /* 
 
56
      TRANSLATORS> The leading word "protocol" is the name
 
57
      of the plugin api, and so should not be translated. 
 
58
    */
 
59
    errmsg_printf(ERRMSG_LVL_ERROR, _("protocol plugin '%s' init() failed"),
 
60
                        plugin->name.str);
 
61
      return 1;
 
62
  }
 
63
 
 
64
  protocol_inited= true;
 
65
 
 
66
  return 0;
 
67
 
 
68
}
 
69
 
 
70
int protocol_finalizer(st_plugin_int *plugin)
 
71
{
 
72
  /* We know which one we initialized since its data pointer is filled */
 
73
  if (plugin->plugin->deinit && protocol_inited)
 
74
  {
 
75
    if (plugin->plugin->deinit(NULL))
 
76
    {
 
77
      /* TRANSLATORS: The leading word "protocol" is the name
 
78
         of the plugin api, and so should not be translated. */
 
79
      errmsg_printf(ERRMSG_LVL_ERROR,
 
80
                    _("protocol plugin '%s' deinit() failed"),
 
81
                    plugin->name.str);
 
82
    }
 
83
  }
 
84
 
 
85
  return 0;
 
86
}