Symantec logo

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

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 script versions of online and offline entry points. This example implements the VCSAgStartup, online, offline, and monitor entry points only.

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

  1. Create a directory for the agent:
  2. Copy the contents from the sample agent to the directory you created in the previous step:
  3. Change to the new directory:
  4. 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 the res_monitor() function:

// Function: res_monitor

// 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, int *conf_level)

{

VCSAgResState state;

WCHAR **new_args = NULL;

DWORD ret, attrs;

wchar_t *pathName = NULL;

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;

}

state = VCSAgResUnknown;

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;

}

attrs = GetFileAttributes(pathName);

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 agent.C and build the agent by invoking make. (Makefile is provided.)

    make

  2. Create a directory for the agent:
  3. Install the FileOnOff agent built in step 6.

make install AGENT=FileOnOff


  Note   Implement the online and offline entry points as instructed in step 3 on page 135.