/* $Id: ApplicationEvent,v 1.1.1.1 2008/11/28 17:57:26 kiesling Exp $ -*-c-mode-*-*/

/*
  This file is part of ctalk.
  Copyright  2005-2008  Robert Kiesling, ctalk@ctalklang.org.
  Permission is granted to copy this software provided that this copyright
  notice is included in all source code modules.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This library 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
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*/

/*
 *   ApplicationEvent Class
 */

#include <sys/types.h>
#include <unistd.h>

Event class ApplicationEvent;

/*
 *  This List does not use the List : new method, so
 *  it has a value variable.
 */
ApplicationEvent classVariable pendingEvents List NULL;
ApplicationEvent instanceVariable processID Integer 0;
ApplicationEvent instanceVariable data String NULL;

ApplicationEvent instanceMethod new (char *__appEventName) {

  ApplicationEvent super new __appEventName;

  __ctalkInstanceVarsFromClassObject (__appEventName);

  methodReturnObject(__appEventName)
}

ApplicationEvent instanceMethod queueEvent (void) {

  OBJECT *__self_object, *__pendingEventList, *__t;

  __self_object = __ctalk_self_internal ();

  __pendingEventList = ApplicationEvent pendingEvents;

  for (__t = __pendingEventList; __t && __t -> next; __t = __t -> next)
    ;

  __t -> next = __self_object;
  __self_object -> prev = __t;
}

ApplicationEvent instanceMethod getPID (void) {

  self addInstanceVariable "processID", getpid ();

  methodReturnSelf
}

ApplicationEvent instanceMethod pending (void) {

  OBJECT *__pendingEventList;

  returnObjectClass Integer;

  __pendingEventList = ApplicationEvent pendingEvents;

  if (__pendingEventList -> instancevars == NULL) {
    methodReturnFalse
  } else {
    methodReturnTrue
  }
  
  methodReturnNULL
}

ApplicationEvent instanceMethod sendToApp (char *__data) {

  ApplicationEvent new __newEvent;

  __newEvent getPID;

  __newEvent addInstanceVariable "data", __data;

  __newEvent queueEvent;

  methodReturnSelf
}
