/*
 * node.h
 *
 * Copyright (C) Leni Mayo 2001-2002
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License, version 2, as
 *	published by the Free Software Foundation.
 *	
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *	
 *	You should have received a copy of the GNU General Public License
 *	along with this program; if not, write to the Free Software
 *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#ifndef _NODE_H_
#define _NODE_H_

#include <glib.h>
#include "common.h"
#include "serviceid.h"
#include "fsm.h"

typedef struct
{
	Pid pidReply;  /* pid of the process blocked waiting for a response  */
	Pid pid;       /* pid of the script - has to entered into the pidmap */
} NodeUserData;

typedef struct
{
	ServiceId id;
	State     fsm;
	NodeUserData *pUserData;
	long      stopwatch;  /* amount of time the node has spent unblocked, in milliseconds */
} Node;

typedef GHashTable Nodes;

Nodes * nodesNew();
void    nodesDelete(Nodes *pNodes);
void    nodesForeach(Nodes *pNodes, CallbackServiceId fn, void *pUserData);
GSList * nodesGet(Nodes *pNodes);

Node * nodeAdd(Nodes *pNodes, const ServiceId id);
void nodeRemove(Nodes *p, ServiceId id); /* assert: id exists */
Node * nodeFromId(Nodes *pNodes, const ServiceId id);
Node * nodeFromName(Nodes *pNodes, const ServiceName name); /* returns NULL if name doesn't exist */

const char * nodeAsString(Node *pNode, char *buf, int bufsiz);
const char * nodesAsString(Nodes *pNodes, char *buf, int bufsiz);

#endif /* _NODE_H_ */
