2004-08-27 12:52:43 +01:00
|
|
|
/**
|
|
|
|
* Label info
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "memory.h"
|
|
|
|
#include "term.h"
|
|
|
|
#include "label.h"
|
2004-08-27 13:36:23 +01:00
|
|
|
#include "list.h"
|
|
|
|
#include "system.h"
|
2004-08-27 12:52:43 +01:00
|
|
|
|
2004-08-27 13:36:23 +01:00
|
|
|
//! Create a new labelinfo node
|
2004-11-16 12:07:55 +00:00
|
|
|
Labelinfo
|
|
|
|
label_create (const Term label, const Protocol protocol)
|
2004-08-27 12:52:43 +01:00
|
|
|
{
|
|
|
|
Labelinfo li;
|
|
|
|
|
|
|
|
li = (Labelinfo) memAlloc (sizeof (struct labelinfo));
|
|
|
|
li->label = label;
|
|
|
|
li->protocol = protocol;
|
|
|
|
li->sendrole = NULL;
|
|
|
|
li->readrole = NULL;
|
|
|
|
return li;
|
|
|
|
}
|
|
|
|
|
2004-08-27 13:36:23 +01:00
|
|
|
//! Destroy a labelinfo node
|
2004-11-16 12:07:55 +00:00
|
|
|
void
|
|
|
|
label_destroy (Labelinfo linfo)
|
2004-08-27 12:52:43 +01:00
|
|
|
{
|
|
|
|
memFree (linfo, sizeof (struct labelinfo));
|
|
|
|
}
|
|
|
|
|
2004-08-27 13:36:23 +01:00
|
|
|
//! Given a list of label infos, yield the correct one or NULL
|
2004-11-16 12:07:55 +00:00
|
|
|
Labelinfo
|
|
|
|
label_find (List labellist, const Term label)
|
2004-08-27 13:36:23 +01:00
|
|
|
{
|
|
|
|
Labelinfo linfo;
|
|
|
|
|
2004-08-30 21:08:11 +01:00
|
|
|
int label_find_scan (void *data)
|
2004-11-16 12:07:55 +00:00
|
|
|
{
|
|
|
|
Labelinfo linfo_scan;
|
|
|
|
|
|
|
|
linfo_scan = (Labelinfo) data;
|
|
|
|
if (isTermEqual (label, linfo_scan->label))
|
|
|
|
{
|
|
|
|
linfo = linfo_scan;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2004-08-27 13:36:23 +01:00
|
|
|
|
|
|
|
linfo = NULL;
|
2004-08-30 21:08:11 +01:00
|
|
|
if (label != NULL)
|
|
|
|
{
|
|
|
|
list_iterate (labellist, label_find_scan);
|
|
|
|
}
|
2004-08-27 13:36:23 +01:00
|
|
|
return linfo;
|
|
|
|
}
|