Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / testclass.cc
1
2
3
4 #include <iostream>
5 #include <string.h>
6 #include <stdlib.h>
7
8 #include "objclass/objclass.h"
9
10 CLS_VER(1,0)
11 CLS_NAME(test)
12
13 cls_handle_t h_class;
14
15 cls_method_handle_t h_foo;
16
17 int foo_method(cls_method_context_t ctx, char *indata, int datalen,
18                                  char **outdata, int *outdatalen)
19 {
20    int i, r;
21
22    cls_log("hello world");
23    cls_log("indata=%s", indata);
24
25    *outdata = (char *)cls_alloc(128);
26    for (i=0; i<strlen(indata) + 1; i++) {
27      if (indata[i] == '0') {
28        (*outdata)[i] = '*';
29      } else {
30        (*outdata)[i] = indata[i];
31      }
32    }
33    *outdatalen = strlen(*outdata) + 1;
34    cls_log("outdata=%s", *outdata);
35
36    r = cls_call(ctx, "foo", "foo", *outdata, *outdatalen, outdata, outdatalen);
37
38    return r;
39 }
40
41 static cls_deps_t depend[] = {{"foo", "1.0"}, {"bar", "1.0"}, {NULL, NULL}};
42
43 extern "C" cls_deps_t *class_deps()
44 {
45    return depend;
46 };
47
48 void class_init()
49 {
50    cls_log("Loaded class test!");
51
52    cls_register("test", &h_class);
53    cls_register_method(h_class, "foo", foo_method, &h_foo);
54
55    return;
56 }
57