-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
113 lines (96 loc) · 2.93 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <nimbus.h>
#include <nim.h>
#include <port.h>
#include <pds.h>
/* Global variables */
char *gProbeName;
char *gVersion;
/********************************************************
* list_robots - example on how to perform calls to other
* Nimsoft components
********************************************************/
int list_robots () {
PDS *psIn=NULL, *psOut=NULL, *psEntry=NULL;
int i=0, iRes=0, iWait=30;
char *Tmp=NULL, *HubDomain=NULL, *HubName=NULL, *HubRobotName=NULL;
const char *Err=NULL;
char zHubAddress [512]="";
/* Issue the gethub command to the local controller */
iRes = nimNamedRequest ("controller", "gethub", psIn, &psOut, iWait);
if (iRes != NIME_OK) {
Err = nimError2Txt (iRes);
return FALSE;
}
/* Get the hubdomain, hubname and hubrobot entries from the returned PDS */
if (pdsGet_PCH (psOut, "hubdomain", &HubDomain) != PDS_ERR_NONE) {
pdsDelete (psOut);
return FALSE;
}
if (pdsGet_PCH (psOut, "hubname", &HubName) != PDS_ERR_NONE) {
free (HubDomain);
pdsDelete (psOut);
return FALSE;
}
if (pdsGet_PCH (psOut, "hubrobotname", &HubRobotName) != PDS_ERR_NONE) {
free (HubDomain);
free (HubName);
pdsDelete (psOut);
return FALSE;
}
pdsDelete (psOut);
psOut = NULL;
/* Build a full Nimsoft address for the Hub */
sprintf (zHubAddress, "/%s/%s/%s/hub", HubDomain, HubName, HubRobotName);
free (HubDomain);
free (HubName);
free (HubRobotName);
/* Issue the getrobots command to the hub */
iRes = nimNamedRequest (zHubAddress, "getrobots", psIn, &psOut, iWait);
if (iRes != NIME_OK) {
Err = nimError2Txt (iRes);
return FALSE;
}
/* Loop through the robotlist in the return PDS one element at a time */
psEntry = NULL;
i = 0;
while (pdsGetTable (psOut, PDS_PDS, "robotlist", i, &psEntry) == PDS_ERR_NONE) {
if (pdsGet_PCH (psEntry, "name", &Tmp) == PDS_ERR_NONE) {
free (Tmp);
}
pdsDelete (psEntry);
i++;
}
pdsDelete (psOut);
return TRUE;
}
/***************
* main program
***************/
int main (int argc, char **argv) {
extern char *optarg;
extern int optind;
int opt=0;
gProbeName = strdup ("example_probe");
gVersion = strdup ("1.00");
nimInit (0);
/* Parse command-line options */
while ((opt = getopt (argc, argv, "Vh")) != EOF) {
switch (opt) {
case 'V': /* Get version information */
printf ("%s %s\n", gProbeName, gVersion);
exit (0);
break;
case 'h':
default:
printf ("usage: %s [Vh]\n", gProbeName);
exit (1);
break;
}
}
/* Perform nimsoft calls */
list_robots ();
nimEnd (0);
if (gProbeName) free (gProbeName);
if (gVersion) free (gVersion);
exit (0);
}