Sample code for NCS_NodeNumToName()
#ifdef __MWERKS__
#pragma ANSI_strict off
#pragma warn_padding off
#endif
#include <ncssdk.h>
#ifdef __MWERKS__
#pragma warn_padding reset
#pragma ANSI_strict reset
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CASE_RET(id) case id: return #id;
static char const* strNCSError( NCS_RETURN error_code) {
switch ( error_code) {
CASE_RET( NCS_SUCCESS)
CASE_RET( NCS_ERROR_INVALID_HANDLE)
CASE_RET( NCS_ERROR_INVALID_PARAMETER)
CASE_RET( NCS_FAILURE)
CASE_RET( NCS_BUSY)
CASE_RET( NCS_ERROR_TOO_MANY_HANDLES)
CASE_RET( NCS_UNKNOWN)
CASE_RET( NCS_BAD_PARAMETER)
CASE_RET( NCS_ALLOC_ERROR)
CASE_RET( NCS_NODE_NOT_FOUND)
CASE_RET( NCS_IP_DUPLICATE)
CASE_RET( NCS_RESOURCE_ONLINE)
CASE_RET( NCS_RESOURCE_NOT_FOUND)
CASE_RET( NCS_RESOURCE_FOUND)
CASE_RET( NCS_ATTACH_CREATE)
CASE_RET( NCS_ATTACH_EXISTS)
CASE_RET( NCS_NOT_CLUSTER_MEMBER)
CASE_RET( NCS_NO_RESOURCES)
CASE_RET( NCS_TRYLOCK_HELD)
CASE_RET( NCS_JOIN_LEAVE_PENDING)
CASE_RET( NCS_JOIN_LEAVE_ALREADY_IN)
CASE_RET( NCS_JOIN_LEAVE_NOT_IN)
CASE_RET( NCS_JOIN_LEAVE_NO_GIPC)
CASE_RET( NCS_JOIN_LEAVE_GIPC_ERROR)
CASE_RET( NCS_JOIN_LEAVE_SBD_ERROR)
CASE_RET( NCS_JOIN_LEAVE_TIMED_OUT)
CASE_RET( NCS_JOIN_LEAVE_EVENT_EXIT)
CASE_RET( NCS_NOT_SUPPORTED)
}
return "Unknown NCS code";
}
int main( void) {
NCS_HANDLE handle;
UINT32 node_num;
UINT8 node_name[ 64];
NCS_RETURN ccode;
ccode = NCS_Register( NULL, NULL, NULL, NULL, NULL, &handle);
if ( ccode != NCS_SUCCESS) {
printf( "NCS_Register failed, ccode = %d (%s)\n", ccode, strNCSError( ccode));
return EXIT_FAILURE;
}
ccode = NCS_NodeNumber( handle, &node_num);
if ( ccode != NCS_SUCCESS) {
printf( "NCS_NodeNumber failed, ccode = %d (%s)\n", ccode, strNCSError( ccode));
NCS_Deregister( handle);
return EXIT_FAILURE;
}
printf( "node_num = %u\n", node_num);
ccode = NCS_NodeNumToName( handle, node_num, node_name);
if ( ccode != NCS_SUCCESS) {
printf( "NCS_NodeNumToName failed, ccode = %d (%s)\n", ccode, strNCSError( ccode));
NCS_Deregister( handle);
return EXIT_FAILURE;
}
printf( "node_name = %s\n", node_name);
ccode = NCS_Deregister( handle);
if ( ccode != NCS_SUCCESS) {
printf( "NCS_Deregister failed, ccode = %d (%s)\n", ccode, strNCSError( ccode));
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
© 2008 Novell, Inc. All Rights Reserved.