~drizzle-trunk/drizzle/development

520.3.2 by mark
add parser and scheduling plugin files
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/scheduling.h>
549 by Monty Taylor
Took gettext.h out of header files.
22
#include <drizzled/gettext.h>
809 by Brian Aker
Refactor of scheduler plugin code to simplify around one structure. Also
23
#include <drizzled/connect.h>
24
960.1.1 by Monty Taylor
First pass at scheduler plugin.
25
Scheduler *thread_scheduler= NULL;
26
809 by Brian Aker
Refactor of scheduler plugin code to simplify around one structure. Also
27
static bool scheduler_inited= false; /* We must insist that only one of these plugins get loaded at a time */
28
520.3.2 by mark
add parser and scheduling plugin files
29
868 by Brian Aker
Adding Multi-threaded Scheduler into the system.
30
extern char *opt_scheduler;
31
960.1.4 by Monty Taylor
Changed get_thread_scheduler to returning a reference.
32
Scheduler &get_thread_scheduler()
960.1.1 by Monty Taylor
First pass at scheduler plugin.
33
{
960.1.4 by Monty Taylor
Changed get_thread_scheduler to returning a reference.
34
  assert(thread_scheduler != NULL);
35
  return *thread_scheduler;
960.1.1 by Monty Taylor
First pass at scheduler plugin.
36
}
37
520.3.2 by mark
add parser and scheduling plugin files
38
int scheduling_initializer(st_plugin_int *plugin)
39
{
868 by Brian Aker
Adding Multi-threaded Scheduler into the system.
40
  if (memcmp(plugin->plugin->name, opt_scheduler, strlen(opt_scheduler)))
41
    return 0;
42
43
  if (scheduler_inited)
809 by Brian Aker
Refactor of scheduler plugin code to simplify around one structure. Also
44
  {
868 by Brian Aker
Adding Multi-threaded Scheduler into the system.
45
    fprintf(stderr, "You cannot load more then one scheduler plugin\n");
46
    exit(1);
809 by Brian Aker
Refactor of scheduler plugin code to simplify around one structure. Also
47
  }
520.3.2 by mark
add parser and scheduling plugin files
48
810 by Brian Aker
Fix for making sure I_S has good information about which plugins are
49
  assert(plugin->plugin->init); /* Find poorly designed plugins */
960.1.1 by Monty Taylor
First pass at scheduler plugin.
50
51
  if (plugin->plugin->init((void *)&thread_scheduler))
520.3.2 by mark
add parser and scheduling plugin files
52
  {
960.1.1 by Monty Taylor
First pass at scheduler plugin.
53
    /* 
54
      TRANSLATORS> The leading word "scheduling" is the name
55
      of the plugin api, and so should not be translated. 
56
    */
57
    errmsg_printf(ERRMSG_LVL_ERROR, _("scheduling plugin '%s' init() failed"),
58
	                plugin->name.str);
59
      return 1;
520.3.2 by mark
add parser and scheduling plugin files
60
  }
809 by Brian Aker
Refactor of scheduler plugin code to simplify around one structure. Also
61
868 by Brian Aker
Adding Multi-threaded Scheduler into the system.
62
  scheduler_inited= true;
63
  /* We populate so we can find which plugin was initialized later on */
960.1.1 by Monty Taylor
First pass at scheduler plugin.
64
  plugin->data= (void *)thread_scheduler;
868 by Brian Aker
Adding Multi-threaded Scheduler into the system.
65
  plugin->state= PLUGIN_IS_READY;
809 by Brian Aker
Refactor of scheduler plugin code to simplify around one structure. Also
66
520.3.2 by mark
add parser and scheduling plugin files
67
  return 0;
68
69
}
70
71
int scheduling_finalizer(st_plugin_int *plugin)
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
72
{
809 by Brian Aker
Refactor of scheduler plugin code to simplify around one structure. Also
73
  /* We know which one we initialized since its data pointer is filled */
813 by Brian Aker
Cleanup to confirm shutdown of scheduler
74
  if (plugin->plugin->deinit && plugin->data)
520.3.2 by mark
add parser and scheduling plugin files
75
  {
960.1.1 by Monty Taylor
First pass at scheduler plugin.
76
    if (plugin->plugin->deinit((void *)thread_scheduler))
520.3.2 by mark
add parser and scheduling plugin files
77
    {
78
      /* TRANSLATORS: The leading word "scheduling" is the name
79
         of the plugin api, and so should not be translated. */
960.1.1 by Monty Taylor
First pass at scheduler plugin.
80
      errmsg_printf(ERRMSG_LVL_ERROR,
81
                    _("scheduling plugin '%s' deinit() failed"),
809 by Brian Aker
Refactor of scheduler plugin code to simplify around one structure. Also
82
                    plugin->name.str);
520.3.2 by mark
add parser and scheduling plugin files
83
    }
84
  }
85
86
  return 0;
87
}