Symantec logo

Example: Using C++ entry points on UNIX

The example in this section shows how to build the FileOnOff agent using your own VCSAgStartup entry point and the C++ version of online, offline, and monitor entry points. This example implements the VCSAgStartup, online, offline, and monitor entry points only.

 Example: VCSAgStartup and C++ entry points

  1. Edit the file agent.C and modify the VCSAgStartup() function
    (the last several lines) to match the following example:

// Description: This functions registers the entry points //

void VCSAgStartup()

{

VCSAG_LOG_INIT("VCSAgStartup");

VCSAgSetLogCategory(10051);

VCSAgInitEntryPointStruct(V50);

VCSAgSetEntryPoint(VCSAgEPMonitor, res_monitor);

VCSAgSetEntryPoint(VCSAgEPOnline, res_online);

VCSAgSetEntryPoint(VCSAgEPOffline, res_offline);

VCSAgSetEntryPoint(VCSAgEPClean, res_clean);

}

  1. Modify res_online():

// This is a C++ implementation of the online entry

// point for the FileOnOff resource type. This function

// brings online a FileOnOff resource by creating the

// corresponding file. It is assumed that the complete

// pathname of the file will be passed as the first

// ArgList attribute.

unsigned int res_online(const char *res_name, void **attr_val) {

WCHAR **new_args = NULL;

DWORD ret;

HANDLE hFile = NULL;

wchar_t *pathName = NULL;

VCSAG_LOG_INIT("res_online");

VCSAG_RES_LOG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS, L"Inside

online.");

ret = VCSAgGetEncodedArgList(VCSAgUTF8, attr_val, VCSAgUCS2,

(void ***)&new_args);

if (ret)

{

VCSAG_LOG_MSG(VCS_NOTICE, 1001, VCS_DEFAULT_FLAGS,

L"Unable to get the arguments");

goto exit;

}

int index_of_attr = -1;

ret = vcsag_get_attr_value((wchar_t**)new_args, L"PathName",

&pathName, index_of_attr, 1);

if(ret !=VCSAG_SUCCESS)

{

goto exit;

}

hFile = CreateFile(pathName,

GENERIC_READ | GENERIC_WRITE,0, NULL,

OPEN_ALWAYS,

res_ATTRIBUTE_NORMAL, (HANDLE)NULL);

if (!hFile || hFile == INVALID_HANDLE_VALUE)

{

VCSAG_LOG_MSG(VCS_ERROR, 1002, VCS_DEFAULT_FLAGS,

L"Unable to create the file"

);

}

else

{

VCSAG_RES_LOG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS, L"Online

successful.");

CloseHandle(hFile);

}

exit:

if(new_args)

VCSAgDelEncodedArgList((void**)new_args);

return 0;

}

  1. Modify res_offline():

// Function: res_offline

// Description: This function deletes the file //

unsigned int res_offline(const char *res_name, void **attr_val)

{

WCHAR **new_args = NULL;

DWORD ret;

wchar_t *pathName = NULL;

VCSAG_LOG_INIT("res_offline");

VCSAG_RES_LOG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS, L"Inside

offline.");

ret = VCSAgGetEncodedArgList(VCSAgUTF8, attr_val, VCSAgUCS2,

(void ***)&new_args);

if (ret)

{

VCSAG_LOG_MSG(VCS_NOTICE, 1001, VCS_DEFAULT_FLAGS,

L"Unable to get the arguments");

goto exit;

}

int index_of_attr = -1;

ret = vcsag_get_attr_value((wchar_t**)new_args, L"PathName",

&pathName, index_of_attr, 1);

if(ret !=VCSAG_SUCCESS)

{

goto exit;

}

if (!DeleteFile(pathName))

{

VCSAG_LOG_MSG(VCS_ERROR, 1003, VCS_DEFAULT_FLAGS,

L"Unable to delete the file");

}

else

{

VCSAG_RES_LOG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS, L"offline

successful.");

}

exit:

if(new_args)

VCSAgDelEncodedArgList((void**)new_args);

return 0;

}

  1. Modify res_monitor(), as shown on step 5.
  2. Compile agent.C and build the agent by invoking make. (Makefile is provided.)

make

  1. Create the directory for the agent binaries:

  1. Install the FileOnOff agent built in step 5.

    make install AGENT=FileOnOff