Agent API¶
When creating the new Agent API it was goal to make it as easy to use as possible while providing all the power needed by the scheduler. Goals when developing the new api included:
- making the need to print "OK" and "BYE" more transparent.
- adding a set of verbose and error functions that provide correctly formated data to the scheduler.
- make setting up the heartbeat simpler.
- adequate documentation for how the hand shake between the agent and the scheduler should take place.
Towards this goal there were 4 functions created that handle all of the hand shake between the scheduler and the agents.
- fo_scheduler_heart: agents should call this to update the number of items processed by the agents.
- fo_scheduler_connect: an agent should call this before calling any other api functions or parsing their command line arguments
- fo_scheduler_next: an agent can call this every time it needs a new piece of information from the scheduler. When this function returns NULL, the agent should clean up any allocated memory and call the next method.
- fo_scheduler_disconnect: this should be the last thing that an agent does. In fact, this function will make the exit system call meaning that the agent will not have a change to do anything else before closing.
There is also now a verbose flags defined by the api. All agents should use this as their verbose flag instead of whatever they are using now. This is implemented this way so that the scheduler is able to change the agent's verbose level. In addition to this flag, there are several verbose macros that can be used to correctly interpret the verbose flag if an agent does not wish to keep track of verbose level personally. All of these macros take the form of "VERBOSE#" where # is the verbose level ranging from 1 to 4. Beyond this they act exactly like a standard printf.
example minimum agents:/* include the header for the fossology api */
#include <libfossology.h>
int main(int argc, char** argv)
{
/* before parsing argv and argc make sure */
/* to initialize the scheduler connection */
fo_scheduler_connect(&argc, argv);
/* enter the main agent loop, continue to */
/* loop until receiving NULL */
while(fo_scheduler_next() != NULL)
{
/* current simply provides access to last */
/* message from the scheduler */
printf("%s\n", fo_scheduler_current());
/* call the heart beat with the number of */
/* items processed since last call */
fo_scheduler_heart(1);
}
/* after cleaning up agent, disconnect from */
/* the scheduler, this doesn't return */
fo_scheduler_disconnect();
}