Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/dll/europa/corba/orbit/ai-client.c
1074 views
1
#include <stdio.h>
2
#include <orb/orbit.h>
3
4
#include "europa.h"
5
6
EuropaAI_Europa ai_client;
7
8
int main(int argc, char *argv[]) {
9
CORBA_Environment ev;
10
CORBA_ORB orb;
11
FILE *ifp;
12
char *ior;
13
char filebuffer[1024];
14
15
/*
16
* Standard initalisation of the orb. Notice that
17
* ORB_init 'eats' stuff off the command line
18
*/
19
20
CORBA_exception_init(&ev);
21
orb = CORBA_ORB_init(&argc, argv, "orbit-local-orb", &ev);
22
23
/*
24
* Get the IOR (object reference). It should be written out
25
* by the echo-server into the file echo.ior. So - if you
26
* are running the server in the same place as the client,
27
* this should be fine!
28
*/
29
30
ifp = fopen("ai.ior","r");
31
if( ifp == NULL ) {
32
g_error("No ai.ior file!");
33
exit(-1);
34
}
35
36
fgets(filebuffer,1024,ifp);
37
ior = g_strdup(filebuffer);
38
39
fclose(ifp);
40
41
/*
42
* Actually get the object. So easy!
43
*/
44
ai_client = CORBA_ORB_string_to_object(orb, ior, &ev);
45
if(!ai_client) {
46
printf("Cannot bind to %s\n", ior);
47
return 1;
48
}
49
50
/*
51
* Ok. Now we use the echo object...
52
*/
53
printf("Type messages to the server\n. as the only thing on the line stops\n
54
");
55
while( fgets(filebuffer,1024,stdin) ) {
56
if( filebuffer[0] == '.' && filebuffer[1] == '\n' )
57
break;
58
59
/* chop the newline off */
60
filebuffer[strlen(filebuffer)-1] = '\0';
61
62
/* using the echoString method in the Echo object */
63
/* this is defined in the echo.h header, compiled from echo.idl */
64
65
EuropaAI_Europa_inputChat(ai_client, filebuffer, &ev);
66
67
/* catch any exceptions (eg, network is down) */
68
69
if(ev._major != CORBA_NO_EXCEPTION) {
70
printf("we got exception %d from inputChat!\n", ev._major);
71
return 1;
72
}
73
}
74
75
76
/* Clean up */
77
CORBA_Object_release(ai_client, &ev);
78
CORBA_Object_release((CORBA_Object)orb, &ev);
79
80
return 0;
81
}
82
83