The following example illustrates the use of the Windows-based primitives within an agent for FileOnOff.
/* @(#)src/agent/w2k/FileOnOff/FileOnOff.C 2.4 01/04/03 11:57:11 - */
static const char sccsid[] = "@(#)VCS:src/agent/w2k/FileOnOff/FileOnOff.C 2.4";
* START COPYRIGHT-NOTICE: 1998, 2003
* Copyright 2006 Symantec Corporation.
WCHAR *ConvertToUnicodeString(const char *attr_val)
int num_bytes = 0, num_written = 0;
// Call the API to convert the UTF-8 encoded string into a
VCSAgEncodeString(VCSAgUTF8, /* convert from UTF8 */
VCSAgUCS2, /* to the UCS2 format */
///////////////////////////////////////////////////////////////////////////////
// Description: Determine if the given file is online (file exists)
// or offline (file does not exist).
///////////////////////////////////////////////////////////////////////////////
VCSAgResState res_monitor(const char *res_name, void **attr_val,
VCSAG_LOG_INIT("res_monitor");
// Temporary variables for sample code
// Dummy structure defined for the purpose of example code
/*****************************************************************
* Sample code for using the new AGFW APIs
*****************************************************************/
// Allocate 32 bytes of type WCHAR for mymem
// Memory allocation succeeded
VCSAgStrlcpyW(mymem, L"copy ", 32);
VCSAgStrlcatW(mymem, L"concatenate", 32);
VCSAG_LOGDBG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,
L"Sample string is %s", mymem);
L"Testing VCSAgSnprintfW...temp_number is
VCSAG_LOGDBG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,
L"Sample string is %s", mymem);
// Delete memory allocated to mymem
VCSAG_LOG_MSG(VCS_NOTICE, 1005, VCS_DEFAULT_FLAGS,
L"Failed to allocate memory for mymem");
// Allocating memory for a struct now
inst1 = VCSAgNew(struct mystruct, 1);
// Memory allocation succeeded
VCSAG_LOGDBG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,
L"Sample string is %s", inst1->b);
// Delete memory allocated to inst1
VCSAG_LOG_MSG(VCS_NOTICE, 1006, VCS_DEFAULT_FLAGS,
L"Failed to allocate memory for inst1");
// Allocating memory for an array of pointers
// Here, there will be four entries in the array
// Memory allocation succeeded
myptr[0] = VCSAgNew(WCHAR, 16);
VCSAgStrlcpyW(myptr[0], L"One", 16);
myptr[1] = VCSAgNew(WCHAR, 16);
VCSAgStrlcpyW(myptr[1], L"Two", 16);
VCSAG_LOGDBG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,
L"Contents of myptr: %s and %s",
// Call the function that uses the VCSAgEncodeString API
szPath = ConvertToUnicodeString((char *)attr_val[0]);
VCSAG_LOGDBG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,
L"Encoded string is %s", szPath);
// Sample usage of VCSAgGetEncodedArgList API
ret = VCSAgGetEncodedArgList(VCSAgUTF8, attr_val,
VCSAgUCS2, (void ***)&new_args);
VCSAG_LOG_MSG(VCS_NOTICE, 1007, VCS_DEFAULT_FLAGS,
L"Failed to encode the ArgList entries");
VCSAG_LOGDBG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,
L"The encoded arg list values are:");
while (new_args[indx] != NULL) {
VCSAG_LOGDBG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,
L"arg %d is %s", indx, new_args[indx]);
// Sample usage of API to delete the encoded
VCSAgDelEncodedArgList((void **)new_args);
/*****************************************************************
* End of sample code for using the new AGFW APIs
*****************************************************************/
VCSAG_RES_LOG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,
VCSAgDelString((void *)szPath);