Syntax for C++ info

unsigned int (*info) (const char *res_name,

VCSAgResInfoOp resinfo_op, void **attr_val, char

**info_output, char ***opt_update_args, char

***opt_add_args);

You may select any name for the function.

resinfo_op

The resinfo_op parameter indicates whether to initialize or update the data in the ResourceInfo attribute. The values of this field and their significance are described in the following table:

Value of resinfo_op

Significance

1

Add non-default keys to the three default keys State, Msg, and TS and initialize the name-value data pairs in the ResourceInfo attribute.

This invocation indicates to the entry point that the current value of the ResourceInfo attribute contains only the basic three keys State, Msg, and TS.

2

Update only the non-default key-value data pairs in the ResourceInfo attribute, not the default keys State, Msg, and TS.

This invocation indicates that ResourceInfo attribute contains non-default keys in addition to the default keys and only the non-default keys are to be updated. Attempt to add keys with this invocation will result in errors.

info_output

The parameter info_output is a character string that stores the output of the info entry point. The output value could be any summarized data for the resource. The Msg key in the ResourceInfo attribute is updated with info_output. If the info entry point exits with success (0), the output stored in info_output is dumped into the Msg key of the ResourceInfo attribute.

The info entry point is responsible for allocating memory for info_output. The agent framework handles the deletion of any memory allocated to this argument. Since memory is allocated in the entry point and deleted in the agent framework, the entry point needs to pass the address of the allocated memory to the agent framework.

opt_update_args

The opt_update_args parameter is an array of character strings that represents the various name-value pairs in the ResourceInfo attribute. This argument is allocated memory in the info entry point, but the memory allocated for it will be freed in the agent framework. The ResourceInfo attribute is updated with these name-value pairs. The names in this array must already be present in the ResourceInfo attribute.

For example:

ResourceInfo = { State = Valid, Msg = "Info entry point output",

TS = "Wed May 28 10:34:11 2003", FileOwner = root,

FileGroup = root, FileSize = 100 }

A valid opt_update_args array for this ResourceInfo attribute would be:

opt_update_args = { "FileSize", "102" }

This array of name-value pairs updates the dynamic data stored in the ResourceInfo attribute.

An invalid opt_update_args array would be one that specifies a key not already present in the ResourceInfo attribute or one that specifies any of the keys: State, Msg, or TS. These three keys can only be updated by the agent framework and not by the entry point.

opt_add_args

opt_add_args is an array of character strings that represent the various name-value pairs to be added to the ResourceInfo attribute. The names in this array represent keys that are not already present in the ResourceInfo association list and have to be added to the attribute. This argument is allocated memory in the info entry point, but this memory is freed in the agent framework. The ResourceInfo attribute is populated with these name-value pairs.

For example:

ResourceInfo = { State = Valid, Msg = "Info entry point output",

TS = "Wed May 28 10:34:11 2003" }

A valid opt_add_args array for this would be:

opt_add_args = { "FileOwner", "root", "FileGroup", "root",

"FileSize", "100" }

This array of name-value pairs adds to and initializes the static and dynamic data stored in the ResourceInfo attribute.

An invalid opt_add_args array would be one that specifies a key that is already present in the ResourceInfo attribute, or one that specifies any of the keys State, Msg, or TS; these are keys that can be updated only by the agent framework, not by the entry point.

Example: info entry point implementation in C++

Set the VCSAgValidateAndSetEntryPoint() parameter to the name of the entry point's function (res_info).

Allocate the info output buffer in the entry point as shown in the example below. The buffer can be any size (the example uses 80), but the agent framework truncates it to 2048 bytes. For the optional name-value pairs, name and value each have a limit of 4096 bytes (the example uses 15).

Example V50 entry point:

extern "C" unsigned int res_info(const char *res_name, VCSAgResInfoOp resinfo_op, void **attr_val, char **info_output, char ***opt_update_args, char ***opt_add_args)

{

struct stat stat_buf;

int i;

char **args = NULL;

char *out = new char [80];

*info_output = out;

VCSAgSnprintf(out, 80,"Output of info entry point - updates

the \"Msg\" key in ResourceInfo attribute");

// Use the stat system call on the file to get its

// information The attr_val array will look like "PathName"

// "1" "<pathname value>" ... Assuming that PathName is the

// first attribute in the attr_val array, the value

// of this attribute will be in index 2 of this attr_val

// array

if (attr_val[2]) {

if ((strlen((CHAR *)(attr_val[2])) != 0) &&

(stat((CHAR *)(attr_val[2]), &stat_buf) == 0)) {

if (resinfo_op == VCSAgResInfoAdd) {

// Add and initialize all the static and

// dynamic keys in the ResourceInfo attribute

args = new char * [7];

for (i = 0; i < 6; i++) {

args[i] = new char [15];

}

// All the static information - file owner

// and group

VCSAgSnprintf(args[0], 15, "%s", "Owner");

VCSAgSnprintf(args[1], 15, "%d",

stat_buf.st_uid);

VCSAgSnprintf(args[2], 15, "%s", "Group");

VCSAgSnprintf(args[3], 15, "%d", stat_buf.st_gid);

// Initialize the dynamic information for the file

VCSAgSnprintf(args[4], 15, "%s", "FileSize");

VCSAgSnprintf(args[5], 15, "%d",

stat_buf.st_size);

args[6] = NULL;

*opt_add_args = args;

}

else {

// Simply update the dynamic keys in the

// ResourceInfo attribute. In this case, the

// dynamic info on the file

args = new char * [3];

for (i = 0; i < 2; i++) {

args[i] = new char [15];

}

VCSAgSnprintf(args[0], 15, "%s", "FileSize");

VCSAgSnprintf(args[1], 15, "%d",

stat_buf.st_size);

args[2] = NULL;

*opt_update_args = args;

}

}

else {

// Set the output to indicate the error

VCSAgSnprintf(out, 80, "Stat on the file %s failed",

attr_val[2]);

return 1;

}

}

else {

// Set the output to indicate the error

VCSAgSnprintf(out, 80, "Error in arglist values passed to

the info entry point");

return 1;

}

// Successful completion of the info entry point

return 0;

} // End of entry point definition

The following example is for a V40 entry point:

extern "C" unsigned int

res_info(const char *res_name, VCSAgResInfoOp resinfo_op,

void **attr_val, char **info_output, char

***opt_update_args, char ***opt_add_args) {

struct stat stat_buf;

int i;

char **args = NULL;

char *out = new char [80];

*info_output = out;

VCSAgSnprintf(out, 80,

"Output of info entry point...updates the "Msg" key in ResourceInfo attribute");

// Use the stat system call on the file to get its information

if ((attr_val) && (*attr_val)) {

if ((stat((CHAR *)(*attr_val), &stat_buf) == 0) &&

(strlen((CHAR *)(*attr_val)) != 0)) {

if (resinfo_op == VCSAgResInfoAdd) {

// Add and initialize all the static and

// dynamic keys in the ResourceInfo attribute

args = new char * [7];

for (i = 0; i < 6; i++) {

args[i] = new char [15];

}

// All the static information - file owner and group

VCSAgSnprintf(args[0], 15, "%s", "Owner");

VCSAgSnprintf(args[1], 15, "%d", stat_buf.st_uid);

VCSAgSnprintf(args[2], 15, "%s", "Group");

VCSAgSnprintf(args[3], 15, "%d", stat_buf.st_gid);

// Initialize the dynamic information for the file

VCSAgSnprintf(args[4], 15, "%s", "FileSize");

VCSAgSnprintf(args[5], 15, "%d", stat_buf.st_size);

args[6] = NULL;

*opt_add_args = args;

}

else {

// Simply update the dynamic keys in the ResourceInfo

// attribute. In this case, the dynamic info on the file

args = new char * [3];

for (i = 0; i < 2; i++) {

args[i] = new char [15];

}

VCSAgSnprintf(args[0], 15, "%s", "FileSize");

VCSAgSnprintf(args[1], 15, "%d", stat_buf.st_size);

args[2] = NULL;

*opt_update_args = args;

}

}

else {

// Set the output to indicate the error

VCSAgSnprintf(out, 80, "Stat on the file %s failed",

*attr_val);

return 1;

}

}

else {

// Set the output to indicate the error

VCSAgSnprintf(out, 80,

"Error in arglist values passed to the info entry

point");

return 1;

}

// Successful completion of the info entry point

return 0;

}