/* Agent Tcl
   Bob Gray
   25 January 1995

   agentId.cc

   This file implements the structures RemotePort and AGENT_ID.

   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 NO_PRAGMAS
#pragma implementation
#endif

#include "platPorting.h"
#include "platDelete.h"		// DELETE_OBJECT and DELETE_ARRAY_OBJECT
#include "suppStrings.h"
#include "mesgPort.h"		// RemotePort
#include "agentId.h"

/*
 * destructores for incoming items
 */
 
INCOMING::~INCOMING () {
    DELETE_OBJECT(id);
    DELETE_OBJECT(security);
} 

INCOMING_MESSAGE::~INCOMING_MESSAGE() {
    DELETE_ARRAY_OBJECT(string);
} 

INCOMING_EVENT::~INCOMING_EVENT () {
    DELETE_ARRAY_OBJECT(tag);
    DELETE_ARRAY_OBJECT(string);
}

INCOMING_MEETING::~INCOMING_MEETING () {
    DELETE_OBJECT(port);
} 

/* SECURITY::setEncryption

   Purpose: Turn on or off encryption
 
     Input: p_encryption = e_TRUE to turn on encryption and e_FALSE to turn off
                           encryption
                           (BOOLEAN)

    Output: When turning on encryption, the procedure returns a security error
            code if the encryption subsystem is not available.  Otherwise the
	    procedure returns SECURITY_OK. When turning off encryption (which 
	    always succeeds), the procedure returns SECURITY_OK.
*/
/* NAME_LIST::fill

   Purpose: Fill in a name

     Input: i    = index
            name = the name

    Output: The procedure fills in the name.
*/

void NAME_LIST::fill (int i, char *name)
{
    /* assertions on the parameters */

  assert ((i >= 0) && (i < count));

    /* delete the old name */

  DELETE_OBJECT(names[i]);

    /* fill in the new name */

  names[i] = strcpyWithAlloc (name);

  if (name != NULL) {
    lengths[i] = strlen(name) + 1;
  } else {
    lengths[i] = 0;
  }
}

/* NAME_LIST::NAME_LIST

   Purpose: This procedure is the constructor for class NAME_LIST.

     Input: count = number of names in the list
*/

NAME_LIST::NAME_LIST (int p_count)
{
  NAME_LIST::count   = p_count;
  NAME_LIST::names   = NULL;
  NAME_LIST::lengths = NULL;

  if (count != 0) {

    names   = new char * [count];
    lengths = new UINT_32 [count];
  
    for (int i = 0; i < count; i++) {
      names  [i] = NULL;
      lengths[i] = 0;
    }
  } 
}

/* NAME_LIST::~NAME_LIST

   Purpose: This procedure is the destructor for class NAME_LIST.
*/

NAME_LIST::~NAME_LIST ()
{
  for (int i = 0; i < count; i++) {
    DELETE_OBJECT(names[i]);
  }

  DELETE_ARRAY_OBJECT(lengths);
  DELETE_ARRAY_OBJECT(names);
} 
  
/* ID_LIST::ID_LIST

   Purpose: This procedure is the constructor for class ID_LIST.

     Input: count = number of ids in the list
*/

ID_LIST::ID_LIST (int p_count)
{
  ID_LIST::count = p_count;

  if (count != 0) {
    ids = new UINT_32 [count];
  } else {
    ids = NULL;
  }
}

/* ID_LIST::~ID_LIST

   Purpose: This procedure is the denstructor for class ID_LIST.
*/

ID_LIST::~ID_LIST ()
{
  DELETE_ARRAY_OBJECT(ids);
}

/* AGENT_INFO::AGENT_INFO and AGENT_INFO::~AGENT_INFO

   Purpose: These procedures are the constructor and destructor for class
            AGENT_INFO.
*/

AGENT_INFO::AGENT_INFO (void)
{
    agentPid   = 0;
    blockerPid = 0;
    messages   = 0;
    meetings   = 0;
    events     = 0;
}

AGENT_INFO::~AGENT_INFO ()
{
    /* empty */
}
