~gearman-developers/gearman-interface/gearman-interface

« back to all changes in this revision

Viewing changes to ruby/libdrizzle.i

  • Committer: Monty Taylor
  • Date: 2009-07-21 20:41:39 UTC
  • Revision ID: mordred@inaugust.com-20090721204139-rcyse999id1lbu1h
Python worker initial import.

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
 *  drizzle-interface: Interface Wrappers for Drizzle
 
5
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation; either version 2 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; if not, write to the Free Software
 
19
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
20
 */
 
21
 
 
22
%module libdrizzle
 
23
 
 
24
%include "interface/globals.i"
 
25
 
 
26
%typemap(in) (const char *query, size_t size) {
 
27
 
 
28
  $1 = STR2CSTR($input);
 
29
  $2 = (size_t)RSTRING($input)->len;
 
30
 }
 
31
 
 
32
 
 
33
%include "interface/libdrizzle/drizzle.i"
 
34
%include "interface/libdrizzle/con.i"
 
35
%include "interface/libdrizzle/client.i"
 
36
%include "interface/libdrizzle/server.i"
 
37
%include "interface/libdrizzle/query.i"
 
38
%include "interface/libdrizzle/result.i"
 
39
%include "interface/libdrizzle/result_client.i"
 
40
%include "interface/libdrizzle/result_client_buffered.i"
 
41
%include "interface/libdrizzle/result_client_unbuffered.i"
 
42
%include "interface/libdrizzle/result_server.i"
 
43
%include "interface/libdrizzle/column.i"
 
44
%include "interface/libdrizzle/column_server.i"
 
45
 
 
46
%{
 
47
 
 
48
#define D_exception(code,msg) do { drizzle_raise_exception(code, msg); SWIG_fail; } while(0);
 
49
#define D_exception_err(code,err) do { drizzle_raise_exception(code, err.message); SWIG_fail; } while(0);
 
50
 
 
51
#define getExceptionMethod(excptype,eparent) \
 
52
  SWIGINTERN VALUE \
 
53
get ## excptype () { \
 
54
  static int init ## excptype = 0 ; \
 
55
  static VALUE rb_e ## excptype ; \
 
56
  VALUE rb_eparent = drizzle_get_exception (eparent); \
 
57
  if (! init ## excptype ) { \
 
58
    init ## excptype = 1; \
 
59
    rb_e ## excptype = rb_define_class(#excptype , rb_eparent); \
 
60
  } \
 
61
  return rb_e ## excptype ; \
 
62
}
 
63
 
 
64
SWIGINTERN VALUE getDrizzleException() {
 
65
  static int initDrizzleException = 0 ;
 
66
  static VALUE rb_eDrizzleException;
 
67
  if (! initDrizzleException ) {
 
68
    initDrizzleException = 1;
 
69
    rb_eDrizzleException = rb_define_class("DrizzleException", rb_eRuntimeError);
 
70
  }
 
71
  return rb_eDrizzleException ;
 
72
}
 
73
 
 
74
VALUE drizzle_get_exception(drizzle_exception excpcode);
 
75
 
 
76
getExceptionMethod(SubDrizzleException,DrizzleException);
 
77
 
 
78
void drizzle_raise_exception(drizzle_exception excpcode, const char * msg) {
 
79
  rb_raise(drizzle_get_exception(excpcode),msg);
 
80
}
 
81
 
 
82
VALUE drizzle_get_exception(drizzle_exception excpcode) {
 
83
 
 
84
 VALUE exception;
 
85
 
 
86
 switch (excpcode) {
 
87
 case DrizzleException:
 
88
   exception = getDrizzleException();
 
89
   break;
 
90
 default:
 
91
   exception = rb_eRuntimeError;
 
92
   break;
 
93
 }
 
94
 return exception;
 
95
}
 
96
 
 
97
 %}
 
98