/******************************************************************************
*                                                                             *
*  File: SimpleEvent.h                                                        *
*                                                                             *
*  Description: An concrete class for representing simple events.             *
*                                                                             *
*  Project: 2K - Automatic Configuration                                      *
*  Author: Fabio Kon (f-kon@cs.uiuc.edu)                                      *
*                                                                             *
*******************************************************************************

   Revision Control Information

   $Revision: $

   $Log: $
******************************************************************************/

#include "ace/OS.h"
#include "SimpleEvent.h"

const char * const ComponentEvent::UNKNOWN = "UNKNOWN";

SimpleEvent::SimpleEvent (int type, const char *description)
{
    type_ = type;
    // FIX: modify the following line to make sure that description is <= MAXNAMLEN
    if(description)
      description_ = ACE_OS::strdup (description);
    else
      description_ = 0;
}

SimpleEvent::~SimpleEvent ()
{
    if (description_ != 0)
        ACE_OS::free (description_);
}


/* Converts the event into a String.
 * @return a string describing the event.
 */
const char *SimpleEvent::toString() const
{
    char buffer[MAXNAMLEN];
    
    char *typeString;
    
    switch (type_) {
    case DELETION:
        typeString = "DELETION"; break;
    case FAILURE:
        typeString = "FAILURE"; break;
    case RECONFIGURED:
        typeString = "RECONFIGURED"; break;
    case REPLACED:
        typeString = "REPLACED"; break;
    case MIGRATED:
        typeString = "MIGRATED"; break;
    default:    
        return UNKNOWN;
    }

    if (description_ != 0)
        ACE_OS::sprintf(buffer, "type = %s, description = %s", 
                        typeString, description_);
    else
        ACE_OS::sprintf(buffer, "type = %s", typeString);        
    
    return buffer;
    
}
// Note that subclasses of this class can test for different kinds of
// events that were not defined in the ComponentEvent interface. So,
// subclasses can define their own application-specific events.


