// -*- C++ -*-
/***************************************************************************
 *   Copyright (C) 2004 by Abdiel Janulgue                                 *
 *   xynopsis at users dot sourceforge dot net                             *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/
#ifndef _WTSTATELESSSLOT_H_
#define _WTSTATELESSSLOT_H_

#include <WDllDefs.h>

/*
 * Strategy: keep a list of WStatelessSlot objects in
 * WObject, which hold the state associated with a stateless
 * slot implementation.
 */

namespace Wt {

class WObject;
class JSlot;
class EventSignalBase;

class WT_API WStatelessSlot
{
public:
  ~WStatelessSlot();

  typedef void (WObject::*WObjectMethod)();

  enum SlotType { 
    AutoLearnStateless,
    PreLearnStateless,
    JavaScriptSpecified
  };
    
  SlotType type() const; 
  bool learned() const;
  void setNotLearned();
  void setJavaScript(const std::string javaScript);

  void addConnection(EventSignalBase *);
  void removeConnection(EventSignalBase *);	

  std::string javaScript() const;

  void trigger();
  void undoTrigger();

  bool implementsMethod(WObjectMethod method) const;

private:
  WStatelessSlot(WObject *target, WObjectMethod method);
  WStatelessSlot(WObject *target, WObjectMethod method,
		 WObjectMethod undoMethod);
  WStatelessSlot(WObject *target, const std::string& javaScript);

  WObject       *target_;
  WObjectMethod  method_;
  WObjectMethod  undoMethod_;

  bool                           learned_;
  std::string                    jscript_;
  std::vector<EventSignalBase *> connectingSignals_;     

  friend class WObject;
  friend class JSlot;
};

class WT_API SlotLearnerInterface {
public:
  virtual std::string learn(WStatelessSlot* slot) = 0;
  virtual ~SlotLearnerInterface() { }
};

}

#endif
