SomVaBuf create: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
{{DISPLAYTITLE:somVaBuf_create}} | |||
Creates a SOM buffer (somVaBuf) for variable arguments from which the va_list will be built. | Creates a SOM buffer (somVaBuf) for variable arguments from which the va_list will be built. | ||
==Syntax== | ==Syntax== | ||
| Line 109: | Line 110: | ||
==Related== | ==Related== | ||
===Functions=== | ===Functions=== | ||
* somVaBuf_add | * [[somVaBuf_add]] | ||
* somVaBuf_get_valist | * [[somVaBuf_get_valist]] | ||
* somVaBuf_destroy | * [[somVaBuf_destroy]] | ||
* somvalistGetTarget | * [[somvalistGetTarget]] | ||
* somvalistSetTarget | * [[somvalistSetTarget]] | ||
[[Category:SOM Kernel]] | [[Category:SOM Kernel]] | ||
Latest revision as of 03:36, 13 October 2017
Creates a SOM buffer (somVaBuf) for variable arguments from which the va_list will be built.
Syntax
char *vb; int size; somVaBuf rc; rc = somVaBuf_create(vb, size);
Parameters
- vb (char *)
- Pointer to user-allocated memory or NULL.
- size (int)
- Size of memory pointed at by vb, or else zero.
Return Code
- rc (somVaBuf)
- If successful, somVaBuf is returned; otherwise, a NULL value is returned.
Remarks
This function allocates, if necessary, and initializes a somVaBuf data structure. Memory is allocated if:
- The size parameter is less than the size of the somVaBuf structure,
- The size parameter is zero, or
- The vb parameter is NULL.
Note: Because the somVaBuf data structure is opaque, users cannot determine its size. Although this function accepts a user-allocated buffer, it is recommended that a NULL value be passed as the first argument.
Example Code
C Sample
#include <somobj.h>
void f1(SOMObject obj, Environment *ev)
{
char *msg;
va_list start_val;
somVaBuf vb;
char *msg1 = "Good Morning";
vb = (somVaBuf)somVaBuf_create(NULL, 0);
somVaBuf_add(vb, (char *)&obj, tk_pointer);
/* target for _set_msg */
somVaBuf_add(vb, (char *)&ev, tk_pointer);
/* next argument */
somVaBuf_add(vb, (char *)&msg1, tk_pointer);
/* final argument */
somVaBuf_get_valist(vb, &start_val);
/* dispatch _set_msg on object */
SOMObject_somDispatch(
obj, /* target for somDispatch */
0, /* says ignore dispatched method result */
somIdFromString("_set_msg"), /* the somId for _set_msg */
start_val); /* target and args for _set_msg */
/* dispatch _get_msg on obj: */
/* Get a fresh copy of the va_list */
somVaBuf_get_valist(vb, &start_val);
SOMObject_somDispatch(
obj,
(somToken *)&msg,
/* address to store dispatched result */
somIdFromString("_get_msg"),
start_val); /* target and arguments for _get_msg */
printf("%s\n", msg);
somVaBuf_destroy(vb);
}
C++ Sample
#include <somobj.h>
void f1(SOMObject obj, Environment *ev)
{
char *msg;
va_list start_val;
somVaBuf vb;
char *msg1 = "Good Morning";
vb = (somVaBuf)somVaBuf_create(NULL, 0);
somVaBuf_add(vb, (char *)&obj, tk_pointer);
/* target for _set_msg */
somVaBuf_add(vb, (char *)&ev, tk_pointer);
/* next argument */
somVaBuf_add(vb, (char *)&msg1, tk_pointer);
/* final argument */
somVaBuf_get_valist(vb, &start_val);
/* dispatch _set_msg on obj: */
obj->SOMObject_somDispatch(
0, /* says ignore the dispatched method result */
somIdFromString("_set_msg"), /* the somId for _set_msg */
start_val); /* the target and arguments for _set_msg */
/* dispatch _get_msg on obj: */
/* Get a fresh copy of the va_list */
somVaBuf_get_valist(vb, &start_val);
obj->SOMObject_somDispatch(
(somToken *)&msg,
/* address to hold dispatched method result */
somIdFromString("_get_msg"),
start_val); /* the target and arguments for _get_msg */
printf("%s\n", msg);
somVaBuf_destroy(vb);
}