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.
Note You must first install Visual C++ on the system on which the agent will be built.
Example: VCSAgStartup and C++ entry points
Create the following directory for the agent sources: %VCS_HOME%\src\agent\FileOnOff:
C:\> md %VCS_HOME%\src\agent\FileOnOff
C:\> cp %VCS_HOME%\src\agent\Sample\* %VCS_HOME%\src\
C:\> cd %VCS_HOME%\src\agent\FileOnOff
sample.C
and modify the VCSAgStartup()
function// This example implements online, offline, and
// monitor entry points using C++.
VCSAG_LOG_INIT("VCSAgStartup");
VCSAgInitEntryPointStruct(V50);
VCSAgSetEntryPoint(VCSAgEPMonitor, res_monitor);
VCSAgSetEntryPoint(VCSAgEPOnline, res_online);
VCSAgSetEntryPoint(VCSAgEPOffline, res_offline);
// 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
unsigned int res_online(const char *res_name,
VCSAG_RES_LOG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,
ret = VCSAgGetEncodedArgList(VCSAgUTF8, attr_val, VCSAgUCS2,
VCSAG_LOG_MSG(VCS_NOTICE, 1001, VCS_DEFAULT_FLAGS,
L"Unable to get the arguments");
hFile = CreateFile((WCHAR *)new_args[0], 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" );
VCSAG_RES_LOG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,
L"Online successful."); CloseHandle(hFile);
VCSAgDelEncodedArgList((void**)new_args);
// This is a C++ implementation of the offline
// entry point for the FileOnOff resource type.
// This function takes offline aFileOnOff
// resource by deleting the corresponding file. It
// is assumed that the complete pathname of the
// file will be passed as the first
unsigned int res_offline(const char *res_name,
VCSAG_LOG_INIT("res_offline");
VCSAG_RES_LOG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,
ret = VCSAgGetEncodedArgList(VCSAgUTF8, attr_val,
VCSAgUCS2,(void ***)&new_args);
VCSAG_LOG_MSG(VCS_NOTICE, 1001, VCS_DEFAULT_FLAGS,
L"Unable to get the arguments");
if (!DeleteFile((WCHAR *)new_args[0]))
VCSAG_LOG_MSG(VCS_ERROR, 1003, VCS_DEFAULT_FLAGS,
L"Unable to delete the file" );
VCSAG_RES_LOG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,
VCSAgDelEncodedArgList((void**)new_args);
res_monitor()
function.
See Example: Using VCSAgStartup() and script entry points on Windows.
sample.C
and build the agent by invoking nmake
. (Makefile
is provided.)
C:\> md %VCS_HOME%\bin\FileOnOff
C:\> copy sample.dll %VCS_HOME%\bin\FileOnOff\FileOnOff.dll