12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- /*
- * mycoagent.c
- *
- * This is an example agent that showcases the use of mycorrhiza.
- */
- #include "../src/myco-agent.c"
- // MYCO fetch: Requests a remote, transactional resource. Blocks until
- // the resource has been granted.
- // MYCO create: Creates a new resource and registers it with the agent.
- // MYCO release: Releases a resource. It can now be taken by other agents via fetch.
- // MYCO free: Destroys a resource for the entire system. Only works if the calling agent has ownership (fetch/create) of the resource.
- // MYCO read: Creates a local copy of a remote resource.
- // MYCO push: Updates the remote resource with the local copy obtained from read.
- // MYCO lock: Protects a resource from read access.
- // MYCO unlock: Allows read access again.
- int main() {
- // At the beginning every agent needs to register itself with the agent server.
- char *agent_name = "MYAGENT3";
- int agent_message_queue_id = myco_agent_register(agent_name);
- // MYCO read
- // #MYCO read("RESOURCE_3")
- struct resource myresource3;
- myresource3 = myco_agent_read_remote_resource(agent_message_queue_id, "RESOURCE_3");
- if (myresource3.size != -1) {
- printf("The first integer of RESOURCE_3 is: %d\n", *((int*)myresource3.pointer));
- }
- // Change some values in RESOURCE_3
- ((int*)myresource3.pointer)[0] = 1;
- sleep(10);
- // MYCO push
- // #MYCO push("RESOURCE_3")
- myco_agent_write_remote_resource(agent_message_queue_id, "RESOURCE_3", myresource3.pointer, myresource3.size, 0);
- // At the end of its runtime the agent unregisters with the daemon.
- myco_agent_unregister(agent_name, agent_message_queue_id);
- return EXIT_SUCCESS;
- }
|