2 /***************************************************************************/
6 /* Communications headers */
7 #include "/usr/local/lib/scilab-2.3/routines/libcomm/libCalCom.h"
8 #include "/usr/local/lib/scilab-2.3/routines/libcomm/libCom.h"
10 static void QuitAppli();
11 static void EndAppli();
12 static void ParseMessage();
13 static void MsgError();
16 static actions_messages tb_messages[]={
17 {ID_GeCI,MSG_QUITTER_APPLI,NBP_QUITTER_APPLI,QuitAppli},
18 {ID_GeCI,MSG_FIN_APPLI,NBP_FIN_APPLI,EndAppli},
19 {NULL,MSG_DISTRIB_LISTE_ELMNT,NBP_DISTRIB_LISTE_ELMNT,ParseMessage},
20 {NULL,NULL,0,MsgError}};
22 static void QuitAppli(message)
25 printf("Quit application\n");
29 static void EndAppli(message)
32 printf("End application\n");
35 static void MsgError(message)
38 printf("Bad received message\n");
41 static char *TheAppli;
45 /* ParseMessage is executed when a message is received */
46 static void ParseMessage(message)
49 int lappli, ltype, lmsg;
51 lappli = strlen(message.tableau[0]);
52 if ((TheAppli = (char *)malloc((unsigned)sizeof(char)*(lappli + 1)))
56 strcpy(TheAppli,message.tableau[0]);
58 ltype = strlen(message.tableau[3]);
59 if ((TheType = (char *)malloc((unsigned)sizeof(char)*(ltype + 1)))
63 strcpy(TheType,message.tableau[3]);
65 lmsg = strlen(message.tableau[4]);
66 if ((TheMsg = (char *)malloc((unsigned)sizeof(char)*(lmsg + 1)))
70 strcpy(TheMsg,message.tableau[4]);
73 static int find(s,n,t)
80 if (!strcmp(s,t[i])) return(i);
91 /* Scilab application to execute */
92 char *scilex = "/usr/local/lib/scilab-2.3/bin/scilex";
94 igeci = find("-pipes",argc,argv);
95 if (igeci == -1) exit(1);
97 p1 = atoi(argv[igeci+1]); p2 = atoi(argv[igeci+2]);
99 /* Intialization of communications */
100 init_messages(tb_messages,p1,p2);
102 /* Get the name of my computer */
103 gethostname(myhost,128);
105 /* Execute Scilab with name "Scilab" on my local host */
106 envoyer_message_parametres_var(ID_GeCI,
114 /* Link THIS application with "Scilab" */
115 envoyer_message_parametres_var(ID_GeCI,
117 identificateur_appli(),
120 /* Link "Scilab" with THIS application */
121 envoyer_message_parametres_var(ID_GeCI,
124 identificateur_appli(),NULL);
126 /* Loop waiting for messages */
129 if (TheType != NULL) {
130 printf("Message received from %s\n",TheAppli);
131 printf(" type: %s\n",TheType);
132 printf(" message: %s\n",TheMsg);
133 TheAppli = NULL; TheType = NULL; TheMsg = NULL;
137 /***************************************************************************/