Example 2: Change a parameter in a running application
client.c
#include <stdio.h> #include <unistd.h> #include <libmc.h> int main() { MCAgency_t agency; int i, local_port = 5051, server_port = 5050; char *server_name = "bird1.engr.ucdavis.edu"; char mobagent[3][20] = {"mobileagent1.xml", "mobileagent2.xml", "mobileagent3.xml"}; agency = MC_Initialize(local_port, NULL); for(i=0; i<3; i++) { MC_SendACLMessageFile(agency, mobagent[i], server_name, server_port); sleep(1); } MC_End(agency); return 0; }
server.c
#include <stdio.h> #include <unistd.h> #include <libmc.h> int main() { double temp = 55.55, *ptemp; int i, n = 50000, local_port = 5050, mutex_id; char *mobagentname = "mobileagent"; MCAgency_t agency; MCAgent_t agent; ChInterp_t interp; agency = MC_Initialize(local_port, NULL); for(i=0; i<n; i++) { printf("i = %d\n", i); agent = MC_FindAgentByName(agency, "mobileagent"); if(agent != NULL) { interp = MC_GetAgentExecEngine(agent); if(interp != NULL) { ptemp = Ch_SymbolAddrByName(interp, "temp"); temp = *ptemp; MC_DeleteAgent(agent); } } printf("temp = %f\n", temp); sleep(1); } MC_End(agency); return 0; }
mobileagent1.xml
<?xml version="1.0"?> <!DOCTYPE myMessage SYSTEM "gafmessage.dtd"> <GAF_MESSAGE> <MESSAGE message="MOBILE_AGENT"> <MOBILE_AGENT> <AGENT_DATA> <NAME>mobileagent</NAME> <OWNER>IEL</OWNER> <HOME>iel2.engr.ucdavis.edu:5051</HOME> <TASKS task="1" num="0"> <TASK num="0" persistent="1" return="no-return" complete="0" server="bird1.engr.ucdavis.edu:5050"> </TASK> <AGENT_CODE> <![CDATA[ double temp = 66.66; ]]> </AGENT_CODE> </TASKS> </AGENT_DATA> </MOBILE_AGENT> </MESSAGE> </GAF_MESSAGE>
mobileagent2.xml
<?xml version="1.0"?> <!DOCTYPE myMessage SYSTEM "gafmessage.dtd"> <GAF_MESSAGE> <MESSAGE message="MOBILE_AGENT"> <MOBILE_AGENT> <AGENT_DATA> <NAME>mobileagent</NAME> <OWNER>IEL</OWNER> <HOME>iel2.engr.ucdavis.edu:5051</HOME> <TASKS task="1" num="0"> <TASK num="0" persistent="1" return="no-return" complete="0" server="bird1.engr.ucdavis.edu:5050"> </TASK> <AGENT_CODE> <![CDATA[ double temp = 77.77; ]]> </AGENT_CODE> </TASKS> </AGENT_DATA> </MOBILE_AGENT> </MESSAGE> </GAF_MESSAGE>
mobileagent3.xml
<?xml version="1.0"?> <!DOCTYPE myMessage SYSTEM "gafmessage.dtd"> <GAF_MESSAGE> <MESSAGE message="MOBILE_AGENT"> <MOBILE_AGENT> <AGENT_DATA> <NAME>mobileagent</NAME> <OWNER>IEL</OWNER> <HOME>iel2.engr.ucdavis.edu:5051</HOME> <TASKS task="1" num="0"> <TASK num="0" persistent="1" return="no-return" complete="0" server="bird1.engr.ucdavis.edu:5050"> </TASK> <AGENT_CODE> <![CDATA[ double temp = 88.88; ]]> </AGENT_CODE> </TASKS> </AGENT_DATA> </MOBILE_AGENT> </MESSAGE> </GAF_MESSAGE> |
Integration Engineering Laboratory | UCD MTU Sandia |