~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/sleep/sleep.cc

  • Committer: Patrick Galbraith
  • Date: 2009-07-31 12:41:37 UTC
  • mto: (1154.1.2 staging)
  • mto: This revision was merged to the branch mainline in revision 1156.
  • Revision ID: patg@patrick-galbraiths-macbook-pro.local-20090731124137-22jool1jy44szs4g
Drizzle can now sleep!

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) 2009 Patrick Galbraith
 
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 <unistd.h>
 
21
#include <drizzled/server_includes.h>
 
22
#include <drizzled/sql_udf.h>
 
23
#include <drizzled/item/func.h>
 
24
#include <drizzled/function/str/strfunc.h>
 
25
 
 
26
#include <string>
 
27
 
 
28
using namespace std;
 
29
 
 
30
class Item_func_sleep : public Item_int_func
 
31
{
 
32
  String value;
 
33
 
 
34
public:
 
35
  int64_t val_int();
 
36
  Item_func_sleep() : Item_int_func()
 
37
  {
 
38
    unsigned_flag= true;
 
39
  }
 
40
 
 
41
  const char *func_name() const
 
42
  {
 
43
    return "sleep";
 
44
  }
 
45
 
 
46
  void fix_length_and_dec() {
 
47
    max_length=1;
 
48
  }
 
49
 
 
50
  bool check_argument_count(int n)
 
51
  {
 
52
    return (n == 1);
 
53
  }
 
54
 
 
55
};
 
56
 
 
57
int64_t Item_func_sleep::val_int()
 
58
{
 
59
  /* int time in seconds */
 
60
  uint dtime;
 
61
  /* string time */
 
62
  String *stime;
 
63
 
 
64
  if ((arg_count != 1) || ! (stime= args[0]->val_str(&value)))
 
65
  {
 
66
    null_value= true;
 
67
    return 0;
 
68
  }
 
69
 
 
70
  /* obtain int time */
 
71
  dtime= atoi(stime->c_ptr());
 
72
 
 
73
  /* sleep dtime seconds */
 
74
  sleep(dtime);
 
75
 
 
76
  null_value= false;
 
77
  return 0;
 
78
}
 
79
 
 
80
Create_function<Item_func_sleep>
 
81
  sleep_udf(string("sleep"));
 
82
 
 
83
static int sleep_plugin_init(PluginRegistry &registry)
 
84
{
 
85
  registry.add(&sleep_udf);
 
86
  return 0;
 
87
}
 
88
 
 
89
static int sleep_plugin_deinit(PluginRegistry &registry)
 
90
{
 
91
  registry.remove(&sleep_udf);
 
92
  return 0;
 
93
}
 
94
 
 
95
 
 
96
drizzle_declare_plugin(sleep)
 
97
{
 
98
  "sleep",
 
99
  "1.0",
 
100
  "Patrick Galbraith",
 
101
  "sleep()",
 
102
  PLUGIN_LICENSE_GPL,
 
103
  sleep_plugin_init, /* Plugin Init */
 
104
  sleep_plugin_deinit, /* Plugin Deinit */
 
105
  NULL,   /* status variables */
 
106
  NULL,   /* system variables */
 
107
  NULL    /* config options */
 
108
}
 
109
drizzle_declare_plugin_end;