The R Project SVN R

Rev

Rev 19502 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19502 Rev 26207
Line 1... Line 1...
1
/*
1
/*
2
 *  RProxy: Connector implementation between application and R language
2
 *  RProxy: Connector implementation between application and R language
3
 *  Copyright (C) 1999--2001 Thomas Baier
3
 *  Copyright (C) 1999--2001 Thomas Baier
4
 * 
4
 *
5
 *  This library is free software; you can redistribute it and/or
5
 *  This library is free software; you can redistribute it and/or
6
 *  modify it under the terms of the GNU Library General Public
6
 *  modify it under the terms of the GNU Library General Public
7
 *  License as published by the Free Software Foundation; either
7
 *  License as published by the Free Software Foundation; either
8
 *  version 2 of the License, or (at your option) any later version.
8
 *  version 2 of the License, or (at your option) any later version.
9
 * 
9
 *
10
 *  This library is distributed in the hope that it will be useful,
10
 *  This library is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 *  Library General Public License for more details.
13
 *  Library General Public License for more details.
14
 * 
14
 *
15
 *  You should have received a copy of the GNU Library General Public
15
 *  You should have received a copy of the GNU Library General Public
16
 *  License along with this library; if not, write to the Free
16
 *  License along with this library; if not, write to the Free
17
 *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
17
 *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18
 *  MA 02111-1307, USA
18
 *  MA 02111-1307, USA
19
 *
19
 *
20
 *  $Id: rproxy.c,v 1.13 2002/04/30 19:13:56 ripley Exp $
20
 *  $Id: rproxy.c,v 1.14 2003/09/13 15:14:09 murdoch Exp $
21
 */
21
 */
22
 
22
 
23
#define NONAMELESSUNION
23
#define NONAMELESSUNION
24
#include <windows.h>
24
#include <windows.h>
25
#include <stdio.h>
25
#include <stdio.h>
Line 33... Line 33...
33
 
33
 
34
#include <Defn.h>
34
#include <Defn.h>
35
#include <Graphics.h>
35
#include <Graphics.h>
36
#include <Rdevices.h>
36
#include <Rdevices.h>
37
 
37
 
38
// static connector information
38
/* static connector information */
39
#define CONNECTOR_NAME          "R Statistics Interpreter Connector"
39
#define CONNECTOR_NAME          "R Statistics Interpreter Connector"
40
#define CONNECTOR_DESCRIPTION   "Implements abstract connector interface to R"
40
#define CONNECTOR_DESCRIPTION   "Implements abstract connector interface to R"
41
#define CONNECTOR_COPYRIGHT     "(C) 1999-2001, Thomas Baier"
41
#define CONNECTOR_COPYRIGHT     "(C) 1999-2001, Thomas Baier"
42
#define CONNECTOR_LICENSE       "GNU General Public License version 2 or greater"
42
#define CONNECTOR_LICENSE       "GNU General Public License version 2 or greater"
43
#define CONNECTOR_VERSION_MAJOR "1"
43
#define CONNECTOR_VERSION_MAJOR "1"
44
#define CONNECTOR_VERSION_MINOR "0"
44
#define CONNECTOR_VERSION_MINOR "0"
45
 
45
 
46
// interpreter information here at the moment until I know better...
46
/* interpreter information here at the moment until I know better... */
47
#define INTERPRETER_NAME        "R"
47
#define INTERPRETER_NAME        "R"
48
#define INTERPRETER_DESCRIPTION "A Computer Language for Statistical Data Analysis"
48
#define INTERPRETER_DESCRIPTION "A Computer Language for Statistical Data Analysis"
49
#define INTERPRETER_COPYRIGHT   "(C) R Development Core Team"
49
#define INTERPRETER_COPYRIGHT   "(C) R Development Core Team"
50
#define INTERPRETER_LICENSE     "GNU General Public License version 2 or greater"
50
#define INTERPRETER_LICENSE     "GNU General Public License version 2 or greater"
51
 
51
 
Line 76... Line 76...
76
  *version = SC_PROXY_INTERFACE_VERSION;
76
  *version = SC_PROXY_INTERFACE_VERSION;
77
 
77
 
78
  return SC_PROXY_OK;
78
  return SC_PROXY_OK;
79
}
79
}
80
 
80
 
81
// 00-02-18 | baier | R_init(), R_Proxy_init() now take parameter-string
81
/* 00-02-18 | baier | R_init(), R_Proxy_init() now take parameter-string */
82
int SYSCALL R_init (R_Proxy_Object_Impl* object,char const* parameters)
82
int SYSCALL R_init (R_Proxy_Object_Impl* object,char const* parameters)
83
{
83
{
84
  int lRc = SC_PROXY_ERR_UNKNOWN;
84
  int lRc = SC_PROXY_ERR_UNKNOWN;
85
 
85
 
86
  if (object == NULL)
86
  if (object == NULL)
87
    {
87
    {
88
      return SC_PROXY_ERR_INVALIDARG;
88
      return SC_PROXY_ERR_INVALIDARG;
89
    }
89
    }
90
  
90
 
91
  if (object->state != ps_none)
91
  if (object->state != ps_none)
92
    {
92
    {
93
      return SC_PROXY_ERR_INITIALIZED;
93
      return SC_PROXY_ERR_INITIALIZED;
94
    }
94
    }
95
 
95
 
Line 109... Line 109...
109
 
109
 
110
  if (object == NULL)
110
  if (object == NULL)
111
    {
111
    {
112
      return SC_PROXY_ERR_INVALIDARG;
112
      return SC_PROXY_ERR_INVALIDARG;
113
    }
113
    }
114
  
114
 
115
  if (object->state != ps_initialized)
115
  if (object->state != ps_initialized)
116
    {
116
    {
117
      return SC_PROXY_ERR_NOTINITIALIZED;
117
      return SC_PROXY_ERR_NOTINITIALIZED;
118
    }
118
    }
119
 
119
 
Line 139... Line 139...
139
  (object->ref_count)++;
139
  (object->ref_count)++;
140
 
140
 
141
  return SC_PROXY_OK;
141
  return SC_PROXY_OK;
142
}
142
}
143
 
143
 
144
// 00-06-19 | baier | release graphics device
144
/* 00-06-19 | baier | release graphics device */
145
int SYSCALL R_release (R_Proxy_Object_Impl* object)
145
int SYSCALL R_release (R_Proxy_Object_Impl* object)
146
{
146
{
147
  if (object == NULL)
147
  if (object == NULL)
148
    {
148
    {
149
      return SC_PROXY_ERR_INVALIDARG;
149
      return SC_PROXY_ERR_INVALIDARG;
150
    }
150
    }
151
 
151
 
152
  // reference count must not be 0 here
152
  /* reference count must not be 0 here */
153
  assert (object->ref_count > 0);
153
  assert (object->ref_count > 0);
154
 
154
 
155
  (object->ref_count)--;
155
  (object->ref_count)--;
156
 
156
 
157
  if (object->ref_count > 0)
157
  if (object->ref_count > 0)
Line 161... Line 161...
161
 
161
 
162
  if (object->state != ps_none)
162
  if (object->state != ps_none)
163
    {
163
    {
164
      return SC_PROXY_ERR_INITIALIZED;
164
      return SC_PROXY_ERR_INITIALIZED;
165
    }
165
    }
166
  
166
 
167
  if (__output_device)
167
  if (__output_device)
168
    {
168
    {
169
      __output_device->vtbl->release (__output_device);
169
      __output_device->vtbl->release (__output_device);
170
      __output_device = NULL;
170
      __output_device = NULL;
171
    }
171
    }
Line 175... Line 175...
175
      __graphics_device->vtbl->release (__graphics_device);
175
      __graphics_device->vtbl->release (__graphics_device);
176
      __graphics_device = NULL;
176
      __graphics_device = NULL;
177
    }
177
    }
178
 
178
 
179
  free (object);
179
  free (object);
180
  
180
 
181
  return SC_PROXY_OK;
181
  return SC_PROXY_OK;
182
}
182
}
183
 
183
 
184
int SYSCALL R_set_symbol (R_Proxy_Object_Impl* object,
184
int SYSCALL R_set_symbol (R_Proxy_Object_Impl* object,
185
			  char const* symbol,
185
			  char const* symbol,
186
			  BDX_Data* data)
186
			  BDX_Data* data)
187
{
187
{
188
  int lRc = 0;
188
  int lRc = 0;
189
 
189
 
190
  // check parameters
190
  /* check parameters */
191
  if ((object == NULL)
191
  if ((object == NULL)
192
      || (symbol == NULL)
192
      || (symbol == NULL)
193
      || (strlen (symbol) == 0)
193
      || (strlen (symbol) == 0)
194
      || (data == NULL))
194
      || (data == NULL))
195
    {
195
    {
196
      return SC_PROXY_ERR_INVALIDARG;
196
      return SC_PROXY_ERR_INVALIDARG;
197
    }
197
    }
198
  
198
 
199
  if (data->version != BDX_VERSION)
199
  if (data->version != BDX_VERSION)
200
    {
200
    {
201
      return SC_PROXY_ERR_INVALIDFORMAT;
201
      return SC_PROXY_ERR_INVALIDFORMAT;
202
    }
202
    }
203
  
203
 
204
  lRc = R_Proxy_set_symbol (symbol,data);
204
  lRc = R_Proxy_set_symbol (symbol,data);
205
 
205
 
206
  return lRc;
206
  return lRc;
207
}
207
}
208
 
208
 
Line 210... Line 210...
210
			  char const* symbol,
210
			  char const* symbol,
211
			  BDX_Data** data)
211
			  BDX_Data** data)
212
{
212
{
213
  int lRc = 0;
213
  int lRc = 0;
214
 
214
 
215
  // check parameters
215
  /* check parameters */
216
  if ((object == NULL)
216
  if ((object == NULL)
217
      || (symbol == NULL)
217
      || (symbol == NULL)
218
      || (strlen (symbol) == 0)
218
      || (strlen (symbol) == 0)
219
      || (data == NULL))
219
      || (data == NULL))
220
    {
220
    {
Line 245... Line 245...
245
 
245
 
246
  if (object->state != ps_initialized)
246
  if (object->state != ps_initialized)
247
    {
247
    {
248
      return SC_PROXY_ERR_NOTINITIALIZED;
248
      return SC_PROXY_ERR_NOTINITIALIZED;
249
    }
249
    }
250
  
250
 
251
  return R_Proxy_evaluate (command,data);
251
  return R_Proxy_evaluate (command,data);
252
}
252
}
253
 
253
 
254
int SYSCALL R_evaluate_noreturn (R_Proxy_Object_Impl* object,
254
int SYSCALL R_evaluate_noreturn (R_Proxy_Object_Impl* object,
255
				 char const* command)
255
				 char const* command)
Line 263... Line 263...
263
 
263
 
264
  if (object->state != ps_initialized)
264
  if (object->state != ps_initialized)
265
    {
265
    {
266
      return SC_PROXY_ERR_NOTINITIALIZED;
266
      return SC_PROXY_ERR_NOTINITIALIZED;
267
    }
267
    }
268
  
268
 
269
  return R_Proxy_evaluate_noreturn (command);
269
  return R_Proxy_evaluate_noreturn (command);
270
}
270
}
271
 
271
 
272
 
272
 
273
int SYSCALL R_query_types (R_Proxy_Object_Impl* object,
273
int SYSCALL R_query_types (R_Proxy_Object_Impl* object,
Line 310... Line 310...
310
 
310
 
311
  if (data->version != BDX_VERSION)
311
  if (data->version != BDX_VERSION)
312
    {
312
    {
313
      return SC_PROXY_ERR_INVALIDFORMAT;
313
      return SC_PROXY_ERR_INVALIDFORMAT;
314
    }
314
    }
315
  
315
 
316
  assert (data != NULL);
316
  assert (data != NULL);
317
  assert (data->version == BDX_VERSION);
317
  assert (data->version == BDX_VERSION);
318
 
318
 
319
  bdx_free (data);
319
  bdx_free (data);
320
  //  free (data);
320
  /*  free (data); */
321
 
321
 
322
  return SC_PROXY_OK;
322
  return SC_PROXY_OK;
323
}
323
}
324
 
324
 
325
// 00-06-19 | baier | only set if version matches
325
/* 00-06-19 | baier | only set if version matches */
326
int SYSCALL R_set_output_device (R_Proxy_Object_Impl* object,
326
int SYSCALL R_set_output_device (R_Proxy_Object_Impl* object,
327
				 struct _SC_CharacterDevice* device)
327
				 struct _SC_CharacterDevice* device)
328
{
328
{
329
  unsigned long lCurrentVersion = 0;
329
  unsigned long lCurrentVersion = 0;
330
 
330
 
Line 428... Line 428...
428
      *information = "";
428
      *information = "";
429
    }
429
    }
430
 
430
 
431
  return SC_PROXY_OK;
431
  return SC_PROXY_OK;
432
}
432
}
433
// 01-01-25 | baier | new parameters
433
/* 01-01-25 | baier | new parameters */
434
int R_Proxy_Graphics_Driver (NewDevDesc* pDD,
434
int R_Proxy_Graphics_Driver (NewDevDesc* pDD,
435
			     char* pDisplay,
435
			     char* pDisplay,
436
			     double pWidth,
436
			     double pWidth,
437
			     double pHeight,
437
			     double pHeight,
438
			     double pPointSize,
438
			     double pPointSize,
Line 451... Line 451...
451
      return SC_PROXY_ERR_INVALIDARG;
451
      return SC_PROXY_ERR_INVALIDARG;
452
    }
452
    }
453
 
453
 
454
  if (__graphics_device)
454
  if (__graphics_device)
455
    {
455
    {
456
      // remove the graphics device from the set of drivers
456
      /* remove the graphics device from the set of drivers */
457
      // @TB
457
      /* @TB */
458
      __graphics_device->vtbl->release (__graphics_device);
458
      __graphics_device->vtbl->release (__graphics_device);
459
      __graphics_device = NULL;
459
      __graphics_device = NULL;
460
    }
460
    }
461
 
461
 
462
  if (device == NULL)
462
  if (device == NULL)
Line 476... Line 476...
476
    }
476
    }
477
 
477
 
478
  __graphics_device = device;
478
  __graphics_device = device;
479
  __graphics_device->vtbl->retain (device);
479
  __graphics_device->vtbl->retain (device);
480
 
480
 
481
  // add the graphics device to the set of drivers
481
  /* add the graphics device to the set of drivers */
482
  {
482
  {
483
    NewDevDesc* lDev = (NewDevDesc*) calloc (1, sizeof (NewDevDesc));
483
    NewDevDesc* lDev = (NewDevDesc*) calloc (1, sizeof (NewDevDesc));
484
    GEDevDesc *lDD;
484
    GEDevDesc *lDD;
485
 
485
 
486
    /* Do this for early redraw attempts */
486
    /* Do this for early redraw attempts */
Line 504... Line 504...
504
    GEinitDisplayList(lDD);
504
    GEinitDisplayList(lDD);
505
  }
505
  }
506
  return SC_PROXY_OK;
506
  return SC_PROXY_OK;
507
}
507
}
508
 
508
 
509
// global object table
509
/* global object table */
510
SC_Proxy_Object_Vtbl global_proxy_object_vtbl =
510
SC_Proxy_Object_Vtbl global_proxy_object_vtbl =
511
{
511
{
512
  (SC_PROXY_GET_VERSION) R_get_version,
512
  (SC_PROXY_GET_VERSION) R_get_version,
513
  (SC_PROXY_INIT) R_init,
513
  (SC_PROXY_INIT) R_init,
514
  (SC_PROXY_TERMINATE) R_terminate,
514
  (SC_PROXY_TERMINATE) R_terminate,
Line 533... Line 533...
533
 
533
 
534
  if (obj == NULL)
534
  if (obj == NULL)
535
    {
535
    {
536
      return SC_PROXY_ERR_INVALIDARG;
536
      return SC_PROXY_ERR_INVALIDARG;
537
    }
537
    }
538
  
538
 
539
  if (version != SC_PROXY_INTERFACE_VERSION)
539
  if (version != SC_PROXY_INTERFACE_VERSION)
540
    {
540
    {
541
      return SC_PROXY_ERR_INVALIDINTERFACEVERSION;
541
      return SC_PROXY_ERR_INVALIDINTERFACEVERSION;
542
    }
542
    }
543
 
543
 
544
  proxy_object = (R_Proxy_Object_Impl*) malloc (sizeof (R_Proxy_Object_Impl));
544
  proxy_object = (R_Proxy_Object_Impl*) malloc (sizeof (R_Proxy_Object_Impl));
545
  
545
 
546
  proxy_object->vtbl = &global_proxy_object_vtbl;
546
  proxy_object->vtbl = &global_proxy_object_vtbl;
547
  proxy_object->state = ps_none;
547
  proxy_object->state = ps_none;
548
  proxy_object->ref_count = 1;
548
  proxy_object->ref_count = 1;
549
 
549
 
550
  *obj = (SC_Proxy_Object*) proxy_object;
550
  *obj = (SC_Proxy_Object*) proxy_object;