~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/gearman_udf/gman_do.cc

  • Committer: Monty Taylor
  • Date: 2008-08-01 22:33:44 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080801223344-vzhlflfmtijp1imv
First pass at gettexizing the error messages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2009 Sun Microsystems
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
 
 
16
 
#include "config.h"
17
 
#include "gman_do.h"
18
 
#include "function_map.h"
19
 
 
20
 
using namespace std;
21
 
 
22
 
extern "C"
23
 
{
24
 
  static void *_do_malloc(size_t size, void *arg)
25
 
  {
26
 
    Item_func_gman_do *item= (Item_func_gman_do *)arg;
27
 
    return item->realloc(size);
28
 
  }
29
 
}
30
 
 
31
 
Item_func_gman_do::~Item_func_gman_do()
32
 
{
33
 
  if (options & GMAN_DO_OPTIONS_CLIENT)
34
 
    gearman_client_free(&client);
35
 
}
36
 
 
37
 
String *Item_func_gman_do::val_str(String *str)
38
 
{
39
 
  String *function;
40
 
  String *res;
41
 
  const char *unique;
42
 
  const char *workload;
43
 
  size_t workload_size;
44
 
  size_t result_size;
45
 
  gearman_return_t ret;
46
 
  char job_handle[GEARMAN_JOB_HANDLE_SIZE];
47
 
 
48
 
  if (arg_count < 1 || arg_count > 3 || !(function= args[0]->val_str(str)))
49
 
  {
50
 
    null_value= 1;
51
 
    return NULL;
52
 
  }
53
 
 
54
 
  if (arg_count > 1 && (res= args[1]->val_str(str)) != NULL)
55
 
  {
56
 
    workload= res->ptr();
57
 
    workload_size= res->length();
58
 
  }
59
 
  else
60
 
  {
61
 
    workload= NULL;
62
 
    workload_size= 0;
63
 
  }
64
 
 
65
 
  if (arg_count == 3 && (res= args[2]->val_str(str)) != NULL)
66
 
    unique= res->ptr();
67
 
  else
68
 
    unique= NULL;
69
 
 
70
 
  if (!(options & GMAN_DO_OPTIONS_CLIENT))
71
 
  {
72
 
    if (!GetFunctionMap().get(string(function->ptr()), &client))
73
 
    {
74
 
      null_value= 1;
75
 
      return NULL;
76
 
    }
77
 
 
78
 
    gearman_client_set_workload_malloc_fn(&client, _do_malloc, this);
79
 
    options= (gman_do_options_t)(options | GMAN_DO_OPTIONS_CLIENT);
80
 
  }
81
 
 
82
 
  if (options & GMAN_DO_OPTIONS_BACKGROUND)
83
 
  {
84
 
    if (options & GMAN_DO_OPTIONS_HIGH)
85
 
    {
86
 
      ret= gearman_client_do_high_background(&client, function->ptr(), unique,
87
 
                                             workload, workload_size,
88
 
                                             job_handle);
89
 
    }
90
 
    else if (options & GMAN_DO_OPTIONS_LOW)
91
 
    {
92
 
      ret= gearman_client_do_low_background(&client, function->ptr(), unique,
93
 
                                            workload, workload_size,
94
 
                                            job_handle);
95
 
    }
96
 
    else
97
 
    {
98
 
      ret= gearman_client_do_background(&client, function->ptr(), unique,
99
 
                                        workload, workload_size, job_handle);
100
 
    }
101
 
 
102
 
    if (ret == GEARMAN_SUCCESS)
103
 
    {
104
 
      result_size= strlen(job_handle);
105
 
      buffer.realloc(result_size);
106
 
      buffer.length(result_size);
107
 
      memcpy(buffer.ptr(), job_handle, result_size);
108
 
    }
109
 
  }
110
 
  else
111
 
  {
112
 
    if (options & GMAN_DO_OPTIONS_HIGH)
113
 
    {
114
 
      (void) gearman_client_do_high(&client, function->ptr(), unique, workload,
115
 
                                    workload_size, &result_size, &ret);
116
 
    }
117
 
    else if (options & GMAN_DO_OPTIONS_LOW)
118
 
    {
119
 
      (void) gearman_client_do_low(&client, function->ptr(), unique, workload,
120
 
                                   workload_size, &result_size, &ret);
121
 
    }
122
 
    else
123
 
    {
124
 
      (void) gearman_client_do(&client, function->ptr(), unique, workload,
125
 
                               workload_size, &result_size, &ret);
126
 
    }
127
 
  }
128
 
 
129
 
  if (ret != GEARMAN_SUCCESS)
130
 
  {
131
 
    null_value= 1;
132
 
    return NULL;
133
 
  }
134
 
 
135
 
  null_value= 0;
136
 
  return &buffer;
137
 
}
138
 
 
139
 
void *Item_func_gman_do::realloc(size_t size)
140
 
{
141
 
  buffer.realloc(size);
142
 
  buffer.length(size);
143
 
  return buffer.ptr();
144
 
}