summaryrefslogtreecommitdiffstats
path: root/src/test/testclass.cc
blob: 22a97be6dcbb44109130bebbb27614060d54fc91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <string.h>
#include <stdlib.h>

#include "objclass/objclass.h"

CLS_VER(1,0)
CLS_NAME(test)

cls_handle_t h_class;

cls_method_handle_t h_foo;

int foo_method(cls_method_context_t ctx, char *indata, int datalen,
				 char **outdata, int *outdatalen)
{
   int i, r;

   cls_log("hello world");
   cls_log("indata=%s", indata);

   *outdata = (char *)cls_alloc(128);
   for (i=0; i<strlen(indata) + 1; i++) {
     if (indata[i] == '0') {
       (*outdata)[i] = '*';
     } else {
       (*outdata)[i] = indata[i];
     }
   }
   *outdatalen = strlen(*outdata) + 1;
   cls_log("outdata=%s", *outdata);

   r = cls_call(ctx, "foo", "foo", *outdata, *outdatalen, outdata, outdatalen);

   return r;
}

static cls_deps_t depend[] = {{"foo", "1.0"}, {"bar", "1.0"}, {NULL, NULL}};

extern "C" cls_deps_t *class_deps()
{
   return depend;
};

void class_init()
{
   cls_log("Loaded class test!");

   cls_register("test", &h_class);
   cls_register_method(h_class, "foo", foo_method, &h_foo);

   return;
}