~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/scheduling.cc

  • Committer: Lee
  • Date: 2008-10-30 22:02:01 UTC
  • mto: (572.1.2 devel)
  • mto: This revision was merged to the branch mainline in revision 573.
  • Revision ID: lbieber@lbieber-desktop-20081030220201-elb6qprbzpn7c5a4
add my name to the AUTHORS file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Mark Atwood
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
22
 
#include <algorithm>
23
 
 
24
 
#include "drizzled/plugin/scheduler.h"
25
 
 
26
 
#include "drizzled/gettext.h"
27
 
#include "drizzled/errmsg_print.h"
28
 
 
29
 
namespace drizzled
30
 
{
31
 
 
32
 
extern size_t my_thread_stack_size;
33
 
 
34
 
std::vector<plugin::Scheduler *> all_schedulers;
35
 
 
36
 
/* Globals (TBK) */
37
 
static plugin::Scheduler *scheduler= NULL;
38
 
 
39
 
 
40
 
class FindSchedulerByName : public std::unary_function<plugin::Scheduler *, bool>
41
 
{
42
 
  const std::string *name;
43
 
public:
44
 
  FindSchedulerByName(const std::string *name_arg)
45
 
    : name(name_arg) {}
46
 
  result_type operator() (argument_type sched)
47
 
  {
48
 
    return (bool)((name->compare(sched->getName()) == 0));
49
 
  }
50
 
};
51
 
 
52
 
 
53
 
bool plugin::Scheduler::addPlugin(plugin::Scheduler *sched)
54
 
{
55
 
  std::vector<plugin::Scheduler *>::iterator iter=
56
 
    std::find_if(all_schedulers.begin(), all_schedulers.end(), 
57
 
            FindSchedulerByName(&sched->getName()));
58
 
 
59
 
  if (iter != all_schedulers.end())
60
 
  {
61
 
    errmsg_printf(error::ERROR,
62
 
                  _("Attempted to register a scheduler %s, but a scheduler "
63
 
                    "has already been registered with that name.\n"),
64
 
                    sched->getName().c_str());
65
 
    return true;
66
 
  }
67
 
 
68
 
  sched->deactivate();
69
 
  all_schedulers.push_back(sched);
70
 
 
71
 
  return false;
72
 
}
73
 
 
74
 
 
75
 
void plugin::Scheduler::removePlugin(plugin::Scheduler *sched)
76
 
{
77
 
  all_schedulers.erase(std::find(all_schedulers.begin(),
78
 
                            all_schedulers.end(),
79
 
                            sched));
80
 
}
81
 
 
82
 
 
83
 
bool plugin::Scheduler::setPlugin(const std::string& name)
84
 
{
85
 
  std::vector<plugin::Scheduler *>::iterator iter=
86
 
    std::find_if(all_schedulers.begin(), all_schedulers.end(), 
87
 
            FindSchedulerByName(&name));
88
 
 
89
 
  if (iter != all_schedulers.end())
90
 
  {
91
 
    if (scheduler != NULL)
92
 
      scheduler->deactivate();
93
 
    scheduler= *iter;
94
 
    scheduler->activate();
95
 
    return false;
96
 
  }
97
 
 
98
 
  errmsg_printf(error::WARN,
99
 
                _("Attempted to configure %s as the scheduler, which did "
100
 
                  "not exist.\n"), name.c_str());
101
 
  return true;
102
 
}
103
 
 
104
 
 
105
 
plugin::Scheduler *plugin::Scheduler::getScheduler()
106
 
{
107
 
  return scheduler;
108
 
}
109
 
 
110
 
} /* namespace drizzled */
 
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/scheduling.h>
 
22
#include <drizzled/gettext.h>
 
23
 
 
24
int scheduling_initializer(st_plugin_int *plugin)
 
25
{
 
26
  scheduling_t *p;
 
27
 
 
28
  p= (scheduling_t *) malloc(sizeof(scheduling_t));
 
29
  if (p == NULL) return 1;
 
30
  memset(p, 0, sizeof(scheduling_t));
 
31
 
 
32
  plugin->data= (void *)p;
 
33
 
 
34
  if (plugin->plugin->init)
 
35
  {
 
36
    if (plugin->plugin->init((void *)p))
 
37
    {
 
38
      /* TRANSLATORS: The leading word "scheduling" is the name
 
39
         of the plugin api, and so should not be translated. */
 
40
      sql_print_error(_("scheduling plugin '%s' init() failed"),
 
41
                      plugin->name.str);
 
42
      goto err;
 
43
    }
 
44
  }
 
45
  return 0;
 
46
 
 
47
err:
 
48
  free(p);
 
49
  return 1;
 
50
}
 
51
 
 
52
int scheduling_finalizer(st_plugin_int *plugin)
 
53
 
54
  scheduling_t *p= (scheduling_t *) plugin->data;
 
55
 
 
56
  if (plugin->plugin->deinit)
 
57
  {
 
58
    if (plugin->plugin->deinit((void *)p))
 
59
    {
 
60
      /* TRANSLATORS: The leading word "scheduling" is the name
 
61
         of the plugin api, and so should not be translated. */
 
62
      sql_print_error(_("scheduling plugin '%s' deinit() failed"),
 
63
                      plugin->name.str);
 
64
    }
 
65
  }
 
66
 
 
67
  if (p) free(p);
 
68
 
 
69
  return 0;
 
70
}
 
71
 
 
72
/* The plugin_foreach() iterator requires that we
 
73
   convert all the parameters of a plugin api entry point
 
74
   into just one single void ptr, plus the session.
 
75
   So we will take all the additional paramters of scheduling_do1,
 
76
   and marshall them into a struct of this type, and
 
77
   then just pass in a pointer to it.
 
78
*/
 
79
typedef struct scheduling_do1_parms_st
 
80
{
 
81
  void *parm1;
 
82
  void *parm2;
 
83
} scheduling_do1_parms_t;
 
84
 
 
85
/* This gets called by plugin_foreach once for each loaded scheduling plugin */
 
86
static bool scheduling_do1_iterate (Session *session, plugin_ref plugin, void *p)
 
87
{
 
88
  scheduling_t *l= plugin_data(plugin, scheduling_t *);
 
89
  scheduling_do1_parms_t *parms= (scheduling_do1_parms_t *) p;
 
90
 
 
91
  /* call this loaded scheduling plugin's scheduling_func1 function pointer */
 
92
  if (l && l->scheduling_func1)
 
93
  {
 
94
    if (l->scheduling_func1(session, parms->parm1, parms->parm2))
 
95
    {
 
96
      /* TRANSLATORS: The leading word "scheduling" is the name
 
97
         of the plugin api, and so should not be translated. */
 
98
      sql_print_error(_("scheduling plugin '%s' scheduling_func1() failed"),
 
99
                      (char *)plugin_name(plugin));
 
100
      return true;
 
101
    }
 
102
  }
 
103
  return false;
 
104
}
 
105
 
 
106
/* This is the scheduling_do1 entry point.
 
107
   This gets called by the rest of the Drizzle server code */
 
108
bool scheduling_do1 (Session *session, void *parm1, void *parm2)
 
109
{
 
110
  scheduling_do1_parms_t parms;
 
111
  bool foreach_rv;
 
112
  
 
113
  /* marshall the parameters so they will fit into the foreach */
 
114
  parms.parm1= parm1;
 
115
  parms.parm2= parm2;
 
116
 
 
117
  /* call scheduling_do1_iterate
 
118
     once for each loaded scheduling plugin */
 
119
  foreach_rv= plugin_foreach(session,
 
120
                             scheduling_do1_iterate,
 
121
                             DRIZZLE_SCHEDULING_PLUGIN,
 
122
                             (void *) &parms);
 
123
  return foreach_rv;
 
124
}
 
125
 
 
126
/* The plugin_foreach() iterator requires that we
 
127
   convert all the parameters of a plugin api entry point
 
128
   into just one single void ptr, plus the session.
 
129
   So we will take all the additional paramters of scheduling_do2,
 
130
   and marshall them into a struct of this type, and
 
131
   then just pass in a pointer to it.
 
132
*/
 
133
typedef struct scheduling_do2_parms_st
 
134
{
 
135
  void *parm3;
 
136
  void *parm4;
 
137
} scheduling_do2_parms_t;
 
138
 
 
139
/* This gets called by plugin_foreach once for each loaded scheduling plugin */
 
140
static bool scheduling_do2_iterate (Session *session, plugin_ref plugin, void *p)
 
141
{
 
142
  scheduling_t *l= plugin_data(plugin, scheduling_t *);
 
143
  scheduling_do2_parms_t *parms= (scheduling_do2_parms_t *) p;
 
144
 
 
145
  /* call this loaded scheduling plugin's scheduling_func1 function pointer */
 
146
  if (l && l->scheduling_func2)
 
147
  {
 
148
    if (l->scheduling_func2(session, parms->parm3, parms->parm4))
 
149
    {
 
150
      /* TRANSLATORS: The leading word "scheduling" is the name
 
151
         of the plugin api, and so should not be translated. */
 
152
      sql_print_error(_("scheduling plugin '%s' scheduling_func2() failed"),
 
153
                      (char *)plugin_name(plugin));
 
154
 
 
155
      return true;
 
156
    }
 
157
  }
 
158
  return false;
 
159
}
 
160
 
 
161
/* This is the scheduling_do2 entry point.
 
162
   This gets called by the rest of the Drizzle server code */
 
163
bool scheduling_do2 (Session *session, void *parm3, void *parm4)
 
164
{
 
165
  scheduling_do2_parms_t parms;
 
166
  bool foreach_rv;
 
167
 
 
168
  /* marshall the parameters so they will fit into the foreach */
 
169
  parms.parm3= parm3;
 
170
  parms.parm4= parm4;
 
171
 
 
172
  /* call scheduling_do2_iterate
 
173
     once for each loaded scheduling plugin */
 
174
  foreach_rv= plugin_foreach(session,
 
175
                             scheduling_do2_iterate,
 
176
                             DRIZZLE_SCHEDULING_PLUGIN,
 
177
                             (void *) &parms);
 
178
  return foreach_rv;
 
179
}