Print this page
XXX keith II
   1 /*
   2  * Copyright (c) 2012 Joyent, Inc.  All rights reserved.
   3  */
   4 
   5 #ifndef _V8PLUS_GLUE_H
   6 #define _V8PLUS_GLUE_H
   7 
   8 #include <stdarg.h>
   9 #include <libnvpair.h>
  10 #include "v8plus_errno.h"
  11 
  12 #ifdef  __cplusplus
  13 extern "C" {
  14 #endif  /* __cplusplus */
  15 


  16 #define V8PLUS_ARG_F_NOEXTRA    0x01
  17 
  18 #define V8PLUS_ERRMSG_LEN       512
  19 #define V8PLUS_JSF_COOKIE       ".__v8plus_jsfunc_cookie"
  20 
  21 typedef enum v8plus_type {
  22         V8PLUS_TYPE_NONE = 0,           /* N/A */
  23         V8PLUS_TYPE_STRING,             /* char * */
  24         V8PLUS_TYPE_NUMBER,             /* double */
  25         V8PLUS_TYPE_BOOLEAN,            /* boolean_t */
  26         V8PLUS_TYPE_JSFUNC,             /* v8plus_jsfunc_t */
  27         V8PLUS_TYPE_OBJECT,             /* nvlist_t * */
  28         V8PLUS_TYPE_NULL,               /* -- */
  29         V8PLUS_TYPE_UNDEFINED,          /* -- */
  30         V8PLUS_TYPE_INVALID,            /* data_type_t */
  31         V8PLUS_TYPE_ANY,                /* nvpair_t * */
  32         V8PLUS_TYPE_STRNUMBER64,        /* uint64_t */
  33         V8PLUS_TYPE_INL_OBJECT          /* ... */
  34 } v8plus_type_t;
  35 


 146 
 147 extern void v8plus_defer(void *, void *, v8plus_worker_f, v8plus_completion_f);
 148 
 149 /*
 150  * Call an opaque JavaScript function from C.  The caller is responsible for
 151  * freeing the returned list.  The first argument is not const because it is
 152  * possible for the JS code to modify the function represented by the cookie.
 153  */
 154 extern nvlist_t *v8plus_call(v8plus_jsfunc_t, const nvlist_t *);
 155 
 156 /*
 157  * Call the named JavaScript function in the context of the JS object
 158  * represented by the native object.  Calling and return conventions are the
 159  * same as for the C interfaces; i.e., the nvlist will be converted into JS
 160  * objects and the return value or exception will be in the "res" or "err"
 161  * members of the nvlist that is returned, respectively.  If an internal
 162  * error occurs, NULL is returned and _v8plus_errno set accordingly.  The
 163  * results of calling a method implemented in C via this interface are
 164  * undefined.
 165  *
 166  * This can be used in concert with JS code to emit events asynchronously;
 167  * see the documentation.








 168  */
 169 extern nvlist_t *v8plus_method_call(void *, const char *, const nvlist_t *);


 170 
 171 /*
 172  * These methods are analogous to strerror(3c) and similar functions; they
 173  * translate among error names, codes, and default messages.  There is
 174  * normally little need for these functions in C methods, as everything
 175  * necessary to construct a JavaScript exception is done by v8+, but these
 176  * may be useful in the construction of supplementary exception decorations
 177  * for debugging purposes.
 178  */
 179 extern const char *v8plus_strerror(v8plus_errno_t);
 180 extern const char *v8plus_errname(v8plus_errno_t);
 181 extern const char *v8plus_excptype(v8plus_errno_t);
 182 
 183 /*
 184  * Provided by C code.  See README.md.
 185  */
 186 extern const v8plus_c_ctor_f v8plus_ctor;
 187 extern const v8plus_c_dtor_f v8plus_dtor;
 188 extern const char *v8plus_js_factory_name;
 189 extern const char *v8plus_js_class_name;
 190 extern const v8plus_method_descr_t v8plus_methods[];
 191 extern const uint_t v8plus_method_count;
 192 extern const v8plus_static_descr_t v8plus_static_methods[];
 193 extern const uint_t v8plus_static_method_count;
 194 






 195 #ifdef  __cplusplus
 196 }
 197 #endif  /* __cplusplus */
 198 
 199 #endif  /* _V8PLUS_GLUE_H */
   1 /*
   2  * Copyright (c) 2012 Joyent, Inc.  All rights reserved.
   3  */
   4 
   5 #ifndef _V8PLUS_GLUE_H
   6 #define _V8PLUS_GLUE_H
   7 
   8 #include <stdarg.h>
   9 #include <libnvpair.h>
  10 #include "v8plus_errno.h"
  11 
  12 #ifdef  __cplusplus
  13 extern "C" {
  14 #endif  /* __cplusplus */
  15 
  16 #define __UNUSED        __attribute__((__unused__))
  17 
  18 #define V8PLUS_ARG_F_NOEXTRA    0x01
  19 
  20 #define V8PLUS_ERRMSG_LEN       512
  21 #define V8PLUS_JSF_COOKIE       ".__v8plus_jsfunc_cookie"
  22 
  23 typedef enum v8plus_type {
  24         V8PLUS_TYPE_NONE = 0,           /* N/A */
  25         V8PLUS_TYPE_STRING,             /* char * */
  26         V8PLUS_TYPE_NUMBER,             /* double */
  27         V8PLUS_TYPE_BOOLEAN,            /* boolean_t */
  28         V8PLUS_TYPE_JSFUNC,             /* v8plus_jsfunc_t */
  29         V8PLUS_TYPE_OBJECT,             /* nvlist_t * */
  30         V8PLUS_TYPE_NULL,               /* -- */
  31         V8PLUS_TYPE_UNDEFINED,          /* -- */
  32         V8PLUS_TYPE_INVALID,            /* data_type_t */
  33         V8PLUS_TYPE_ANY,                /* nvpair_t * */
  34         V8PLUS_TYPE_STRNUMBER64,        /* uint64_t */
  35         V8PLUS_TYPE_INL_OBJECT          /* ... */
  36 } v8plus_type_t;
  37 


 148 
 149 extern void v8plus_defer(void *, void *, v8plus_worker_f, v8plus_completion_f);
 150 
 151 /*
 152  * Call an opaque JavaScript function from C.  The caller is responsible for
 153  * freeing the returned list.  The first argument is not const because it is
 154  * possible for the JS code to modify the function represented by the cookie.
 155  */
 156 extern nvlist_t *v8plus_call(v8plus_jsfunc_t, const nvlist_t *);
 157 
 158 /*
 159  * Call the named JavaScript function in the context of the JS object
 160  * represented by the native object.  Calling and return conventions are the
 161  * same as for the C interfaces; i.e., the nvlist will be converted into JS
 162  * objects and the return value or exception will be in the "res" or "err"
 163  * members of the nvlist that is returned, respectively.  If an internal
 164  * error occurs, NULL is returned and _v8plus_errno set accordingly.  The
 165  * results of calling a method implemented in C via this interface are
 166  * undefined.
 167  *
 168  * These methods can be used in concert with JS code to emit events
 169  * asynchronously; see the documentation.
 170  *
 171  * Note: As JavaScript functions must be called from the event loop thread,
 172  * v8plus_method_call() contains logic to determine whether we are in the
 173  * correct context or not.  If we are running on some other thread we will
 174  * queue the request and sleep, waiting for the event loop thread to make the
 175  * call.  In the simple case, where we are already in the correct thread,
 176  * we make the call directly.  v8plus_method_call_direct() assumes we are
 177  * on the correct thread and always makes the call directly.
 178  */
 179 extern nvlist_t *v8plus_method_call(void *, const char *, const nvlist_t *);
 180 extern nvlist_t *v8plus_method_call_direct(void *, const char *,
 181     const nvlist_t *);
 182 
 183 /*
 184  * These methods are analogous to strerror(3c) and similar functions; they
 185  * translate among error names, codes, and default messages.  There is
 186  * normally little need for these functions in C methods, as everything
 187  * necessary to construct a JavaScript exception is done by v8+, but these
 188  * may be useful in the construction of supplementary exception decorations
 189  * for debugging purposes.
 190  */
 191 extern const char *v8plus_strerror(v8plus_errno_t);
 192 extern const char *v8plus_errname(v8plus_errno_t);
 193 extern const char *v8plus_excptype(v8plus_errno_t);
 194 
 195 /*
 196  * Provided by C code.  See README.md.
 197  */
 198 extern const v8plus_c_ctor_f v8plus_ctor;
 199 extern const v8plus_c_dtor_f v8plus_dtor;
 200 extern const char *v8plus_js_factory_name;
 201 extern const char *v8plus_js_class_name;
 202 extern const v8plus_method_descr_t v8plus_methods[];
 203 extern const uint_t v8plus_method_count;
 204 extern const v8plus_static_descr_t v8plus_static_methods[];
 205 extern const uint_t v8plus_static_method_count;
 206 
 207 /*
 208  * Private methods.
 209  */
 210 extern boolean_t v8plus_in_event_thread(void);
 211 extern void v8plus_crossthread_init(void);
 212 
 213 #ifdef  __cplusplus
 214 }
 215 #endif  /* __cplusplus */
 216 
 217 #endif  /* _V8PLUS_GLUE_H */