Symantec logo

Example: Using C++ and script entry points on Windows

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


  Note   To build an agent, you must first install Visual C++ on the system on which the agent will be built.


 Example: implementing agent using VCSAgStartup, C++ and script entry points

  1. Create a directory for the agent:

C:\> md %VCS_HOME%\src\agent\FileOnOff

  1. Copy the contents of the sample agent directory to the directory you created in the previous step:

C:\> copy %VCS_HOME%\src\agent\Sample\* %VCS_HOME%\src\

agent\FileOnOff

  1. Change to the new directory:

C:\> cd %VCS_HOME%\src\agent\FileOnOff

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

void VCSAgStartup()

{

VCSAG_LOG_INIT("VCSAgStartup");

VCSAgSetLogCategory(10051);

VCSAgInitEntryPointStruct(V50);

VCSAgSetEntryPoint(VCSAgEPMonitor, res_monitor);

}

  1. Modify the res_monitor() function:

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

// point for the FileOnOff resource type. This function

// determines the status of a FileOnOff resource

// by checking if the corresponding file exists. It

// is assumed that the complete pathname of the file will

// be passed as the first ArgList attribute.

VCSAgResState res_monitor(const char *res_name, void

**attr_val,int *conf_level) {

// Initialize the OUT parameters.

VCSAgResState state;

WCHAR **new_args = NULL;

DWORD ret, attrs;

VCSAG_LOG_INIT("res_monitor");

VCSAG_RES_LOG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,

L"Inside monitor.";

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");

state = VCSAgResUnknown;

goto exit;

}

attrs = GetFileAttributes(new_args[0]);

if (attrs == 0xffffffff)

{

state = VCSAgResOffline;

*conf_level = 0;

}

else

{

state = VCSAgResOnline;

*conf_level = 100;

}

VCSAG_RES_LOG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS, L"Monitor

successful.");

exit:

if(new_args)

VCSAgDelEncodedArgList((void**)new_args);

return state;

}

  1. Compile sample.C and build the agent by invoking nmake. (Makefile is provided.)

C:\> nmake

  1. Create the following directory:

    C:\Program Files\VERITAS\cluster server\bin\FileOnOff:

C:\> md %VCS_HOME%\bin\FileOnOff

  1. Place the sample.dll as the FileOnOff agent library.

C:\> copy sample.dll

%VCS_HOME%\bin\FileOnOff\FileOnOff.dll

  1. Implement the online and offline entry points.

    See Example: Using C++ entry points on Windows.