You can use the STAF C APIs, but I recommend that you use the STAF C++ 
APIs, if you can, as they are easier to use and are documented.  Note that 
the STAF C unmarshalling APIs are not well documented -- you may have to 
look at the source code for STAF to get more information. 

However, if you really need to use only C, the following STAF Help forum 
entry has an example in C using the STAF C unmarshalling APIs:

  http://sourceforge.net/projects/staf/forums/forum/104046/topic/1674306

Here is the example written in C provided in this forum entry that shows 
how to unmarshall a STAF service result:

// Somewhere, you'll need to be sure to include these
#include "STAF.h"
#include "STAFString.h"
#include "STAFDataTypes.h"

// Note: NO error checking has been done.

char *request = "GET WAIT";
char *result = 0;
unsigned int resultLen = 0;
STAFString_t resultString;
STAFRC_t rc = 0;
STAFObject_t context = 0;
STAFObject_t entryMap = 0;
STAFString_t typeKey = 0;
STAFObject_t typeObj;
STAFString_t typeString;
STAFString_t messageKey = 0;
STAFObject_t messageObj;
STAFString_t messageString;
char *printableString = 0;
unsigned int psLen = 0;

// Submit request. I'm assuming the STAF handle was already obtained.

rc = STAFSubmit(handle, "local", "QUEUE", request, strlen(request), 
&result, &resultLen);

// Convert result to a STAFString

rc = STAFStringConstructFromCurrentCodePage(&resultString, result, 
resultLen, 0);

// Free result provided by STAF

rc = STAFFree(handle, result);

// Unmarshall the result string and then get rid of the STAFString_t

rc = STAFObjectUnmarshallFromString(&context, resultString, 0, 
kSTAFUnmarshallingDefaults);

rc = STAFStringDestruct(&resultString, 0);

// Get the root object from the context. In this case, we know it will
// be a map of the map class STAF/Service/Queue/Entry.

rc = STAFObjectMarshallingContextGetRootObject(context, &entryMap);

// Let's generate the keys we need to access the map. Normally, this would
// be done in some init() type function and the keys would be stored
// globally so that you don't need to do this all the time.

rc = STAFStringConstructFromCurrentCodePage(&typeKey, "type", 
strlen("type"), 0);
rc = STAFStringConstructFromCurrentCodePage(&messageKey, "message", 
strlen("message"), 0);

// Get the value objects for the type and message keys

rc = STAFObjectMapGet(entryMap, typeKey, &typeObj);
rc = STAFObjectMapGet(entryMap, messageKey, &messageObj);

// Let's get rid of the type and message keys now. As noted above, these
// would likely be global in a normal program, so you wouldn't need to do
// this step (at least not here).

rc = STAFStringDestruct(&typeKey, 0);
rc = STAFStringDestruct(&messageKey, 0);

// Get the string for the Type object

rc = STAFObjectGetStringValue(typeObj, &typeString);

// Note: The message may not be a string, but this will get us a printable
// value. If it is a string, you get the string, otherwise, you get
// an indication of the type of the object.

rc = STAFObjectGetStringValue(messageObj, &messageString);

// Now print out the strings and get rid of the STAFStrings

rc = STAFStringToCurrentCodePage(typeString, &printableString, &psLen, 0);

printf("Message type: %s\n", printableString);

rc = STAFStringFreeBuffer(printableString, 0);
rc = STAFStringDestruct(&typeString, 0);

rc = STAFStringToCurrentCodePage(messageString, &printableString, &psLen, 
0);

printf("Message: %s\n", printableString);

rc = STAFStringFreeBuffer(printableString, 0);
rc = STAFStringDestruct(&messageString, 0);

// Now we have to get rid of all the objects we obtained

rc = STAFObjectDestruct(&typeObj);
rc = STAFObjectDestruct(&messageObj);
rc = STAFObjectDestruct(&entryMap);
rc = STAFObjectDestruct(&context); 


If using C++, see sections "6.2.9 Data Structure and Marshalling APIs", 
"6.3.2 STAFObject", "6.3. STAFObjectIterator", and "6.3.4 
STAFMapClassDefinition" in the STAF V3 User's Guide for more information 
on the C/C++ APIs provided by STAF for defining, manipulating, and 
marshalling data structures. 

Also, section "6.6 Handling Marshalled Structured Data (Unmarshalling)" in 
the STAF V3 Migration Guide at 
http://staf.sourceforge.net/current/stafmigrate.html#Header_UnMarshalling 
has a C++ example.

And the STAF source code itself performs unmarshalling in C++.

--------------------------------------------------------------
Sharon Lucas
IBM Austin,   luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313




From:   "Dedhia, Hardik" <hardik.ded...@netapp.com>
To:     <staf-users@lists.sourceforge.net>
Date:   06/16/2011 12:41 PM
Subject:        [staf-users] Regarding STAFString Utility for C



Hi everyone,
 
I’m net to the STAF infrastructure and would like explore the use of STAF 
API for C.
 
Could you direct me to a few examples – especially in un marshalling 
results using STAF C API.
 
It would be really helpful for me!
 
Thanks,
 
Hardik.
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users


------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

Reply via email to