Debian Codegraph @

examples/mqueue-cpp/mqueue_glue.cpp

raw
1 //
2 // mqueue_glue.cpp
3 //
4 // The mqueue-cpp extension module to show how to embed external C++
5 // library in Gauche.
6 // This file works as a 'glue' between the external C++ library
7 // (mqueue.h, mqueue.cpp) and Gauche extension. If you're writing
8 // a bridge for the third party C++ library, the contents of this
9 // file is the stuff you're supposed to write.
10 //
11
12 #include "mqueue_glue.h"
13
14 ScmClass *MQueueClass;
15
16 static void mqueue_print(ScmObj obj, ScmPort *out, ScmWriteContext *ctx)
17 {
18 MQueue *q = MQUEUE_UNBOX(obj);
19 const char *queue_name = q->getName().c_str();
20 Scm_Printf(out, "#<mqueue \"%s\">", queue_name);
21 }
22
23 static void mqueue_cleanup(ScmObj obj)
24 {
25 MQueue *q;
26 q = MQUEUE_UNBOX(obj);
27 delete q;
28 }
29
30 void Scm_Init_mqueue_cpp()
31 {
32 ScmModule *mod;
33
34 /* Register this DSO to Gauche */
35 SCM_INIT_EXTENSION(mqueue_cpp);
36
37 /* Create example.mqueue-cpp module */
38 mod = SCM_FIND_MODULE("example.mqueue-cpp", SCM_FIND_MODULE_CREATE);
39
40 /* Create the foreign pointer class <mqueue-cpp>.
41 The flag SCM_FOREIGN_POINTER_KEEP_IDENTITY makes Gauche to keep
42 one-to-one mapping between the foreign object pointer (MQueue*)
43 and its wrapping ScmObj. With this flag, you can assume that
44 when mqueue_cleanup is called, no other ScmForeignPointer object
45 is pointing to the same MQueue*, thus you can delete it safely. */
46 MQueueClass =
47 Scm_MakeForeignPointerClass(mod, "<mqueue>",
48 mqueue_print,
49 mqueue_cleanup,
50 SCM_FOREIGN_POINTER_KEEP_IDENTITY|SCM_FOREIGN_POINTER_MAP_NULL);
51
52 /* Initialize stub functions */
53 Scm_Init_mqueue_lib();
54 }