root/examples/mqueue-cpp/mqueue_glue.cpp

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mqueue_print
  2. mqueue_cleanup
  3. Scm_Init_mqueue_cpp

   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 extern void Scm_Init_mqueue_lib(ScmModule*);
  31 
  32 void Scm_Init_mqueue_cpp()
  33 {
  34     ScmModule *mod;
  35 
  36     /* Register this DSO to Gauche */
  37     SCM_INIT_EXTENSION(mqueue_cpp);
  38 
  39     /* Create example.mqueue-cpp module */
  40     mod = SCM_MODULE(SCM_FIND_MODULE("example.mqueue-cpp", TRUE));
  41     
  42     /* Create the foreign pointer class <mqueue-cpp>.
  43        The flag SCM_FOREIGN_POINTER_KEEP_IDENTITY makes Gauche to keep
  44        one-to-one mapping between the foreign object pointer (MQueue*)
  45        and its wrapping ScmObj.  With this flag, you can assume that
  46        when mqueue_cleanup is called, no other ScmForeignPointer object
  47        is pointing to the same MQueue*, thus you can delete it safely. */
  48     MQueueClass =
  49         Scm_MakeForeignPointerClass(mod, "<mqueue>",
  50                                     mqueue_print,
  51                                     mqueue_cleanup,
  52                                     SCM_FOREIGN_POINTER_KEEP_IDENTITY|SCM_FOREIGN_POINTER_MAP_NULL);
  53 
  54     /* Initialize stub functions */
  55     Scm_Init_mqueue_lib(mod);
  56 }

/* [<][>][^][v][top][bottom][index][help] */