/* Agent Tcl
   Bob Gray
   25 January 1995

   agentId.h

   This file defines the structures RemotePort.

   Copyright (c) 1995, Robert S. Gray Dartmouth College

   See the file "agent.terms" for information on usage and redistribution
   of this file and for a DISCLAIMER OF ALL WARRANTIES.
*/

#ifndef _AgentId_H
#define _AgentId_H

#ifndef NO_PRAGMAS
#pragma interface
#endif

#ifndef _SUPP_MACH_ID_H
#include "mesgMachId.h"	// MachineId
#endif
#ifndef _AGENT_AGENT_UD_H
#include "agentAgentId.h"	// AgentId
#endif


#include "platPorting.h"
#include "agentSecure.h"
#include "genUtility.h"

class RemotePort;

    /* wildcard constants */

char *const ANY_SERVER		= NULL; 
const UINT_32 ANY_IP		= 0;
char *const ANY_NAME		= NULL;
const UINT_32 ANY_ID		= 0;
char *const ANY_TAG		= NULL;

    /* three types of communication */

const int MEETING_ITEM		= 0;
const int MESSAGE_ITEM		= 1;
const int EVENT_ITEM		= 2;
const int NUM_ITEMS		= 3;

    /* agent information */

struct AGENT_INFO 
{
    struct AgentId id;	            /* agent identification                 */
    MachineId actual;       /* actual agent location                */
    struct BASE_SECURITY security;  /* security information                 */ 
    int agentPid;	            /* process id of the running agent      */
    int blockerPid;                 /* process id of message handler        */
    int messages;                   /* number of messages waiting at server */
    int meetings;                   /* number of meetings waiting at server */
    int events;	                    /* number of events waiting at server   */

#ifdef __cplusplus

	/* constructor and destructor */

    AGENT_INFO (void);
   ~AGENT_INFO ();

#endif
};

    /* an incoming item */

struct INCOMING
{
	/* agent identification and security information */

    AgentId *id;
    BASE_SECURITY *security;

	/* constructor */

    INCOMING (AgentId *p_id, BASE_SECURITY *p_security):
	id	 (p_id),
	security (p_security)
    {
	/* empty */
    };
	
	/* destructor */

    virtual ~INCOMING ();
};

    /* an incoming message */

struct INCOMING_MESSAGE: public INCOMING
{
	/* message code and string */

    UINT_32 code;
    char *string;

	/* constructor */

    INCOMING_MESSAGE (AgentId *p_id, UINT_32 p_code, char *p_string, BASE_SECURITY *p_security): 
	INCOMING	(p_id, p_security),
	code		(p_code),
	string		(p_string)
    {
	/* empty */
    };

	/* destructor */

    virtual ~INCOMING_MESSAGE();
};

    /* an incoming event */

struct INCOMING_EVENT: public INCOMING
{
	/* event tag and string */

    char *tag;
    char *string;

	/* constructor */

    INCOMING_EVENT (AgentId *p_id, char *p_tag, char *p_string, BASE_SECURITY *p_security): 
	INCOMING	(p_id, p_security),
	tag		(p_tag),
	string		(p_string)
    {
	/* empty */
    };

	/* destructor */

    virtual ~INCOMING_EVENT ();
};

    /* an incoming meeting */

struct INCOMING_MEETING: public INCOMING 
{
	/* status flag and port information */

    UINT_8 status;    
    RemotePort *port; 
    UINT_32 localHandle;
    UINT_32 remoteHandle;

	/* constructor */

    INCOMING_MEETING (AgentId *p_id, UINT_8 p_status, UINT_32 p_localHandle, UINT_32 p_remoteHandle, RemotePort *p_port, BASE_SECURITY *p_security):
	INCOMING	(p_id, p_security),
	status		(p_status),
	port		(p_port),
	localHandle	(p_localHandle),
	remoteHandle 	(p_remoteHandle)
    {
	/* empty */
    };
 
    virtual ~INCOMING_MEETING();
};

    /* list of numeric ids */

struct ID_LIST	      
{
    int count;          /* number of numeric ids */
    UINT_32 *ids;       /* the numeric ids       */

#ifdef __cplusplus

	/* constructor and destructor */

    ID_LIST (int count);
   ~ID_LIST ();

#endif
};
 
    /* list of symbolic names */
 
struct NAME_LIST 
{
    int count;          /* number of symbolic names */
    UINT_32 *lengths;   /* lengths of the names     */
    char **names;       /* the symbolic names       */

#ifdef __cplusplus

	/* fill in a name */

    void fill (int i, char *name);

      /* constructor and destructor */

    NAME_LIST (int count);
   ~NAME_LIST ();

#endif
};

#endif
