Cisco Cisco Configuration Engine 3.5 Entwickleranleitung

Seite von 344
4-13
Cisco Configuration Engine Software Development Kit API Reference and Programmer Guide 3.5
OL-17661-02
Chapter 4      Namespace Mapping Service
Mapping Algorithm
Example 4-1
Mapping event strings in C++
#include <stdio.h>
#include <iostream.h>
#include “nsm_client.h”
void main()
{
NSMClient *nsmc = new NSMClient ("./nsm.conf");
NSMResult *result = new NSMResult();
if (nsmc != NULL && result != NULL) {
nsmc->attach(“config”);
nsmc->resolve(*result, “/config/california”, “cisco.cns.config.load”,
NSMClient::PUBLISH, NSMClient::GROUP);
nsmc->detach();
// Retrieve the event strings and, post to the event bus---or, as in this example, 
// output to screen.
for (NSMResultIterator iter(*result); !iter.isEnd(); iter.advance())
{
cout << iter.value() << endl;
}
delete result;
delete nsmc;
}
}
Example 4-2
Mapping event strings in Java
import com.cisco.cns.nsm.client.*;
public class PublishSample
{
public static void main(String args[])
{
NSMClient nsmc = new NSMClient(“./nsm.conf”);
NSMResult result = new NSMResult();
if (nsmc != null && result != null) {
nsmc.attach(“config”);
nsmc.resolve(result, “/config/california”, “cisco.cns.config.load”, 
NSCMLient.PUBLISH, NSMClient.GROUP);
nsmc.detach();
// Retrieve the event strings and post to the event bus, or, as in this example, 
output to screen.
NSMResultIterator iter = new NSMResultIterator(result);
for (; !iter.isEnd(); iter.advance())
System.out.prntln((String)iter.value());
}
}
}
The NSMServer will retrieve the appropriate namespace mappings from the directory. These event 
strings will be contained in the result NSMResult object. The NSMResult object can hold an unlimited 
number of individual event strings. To retrieve all of the event strings in NSMResult, use the 
NSMResultIterator to cycle through the events.