/*

ARIA header files for use with ARNL 1.7.1

Copyright(C) 2004, 2005 ActivMedia Robotics, LLC. 
Copyright(C) 2006, 2007, 2008, 2009 MobileRobots Inc.
All rights reserved.

This copy of Aria was relicensed for use with Arnl and the Arnl
license by MobileRobots Inc.  If you wish to download a seperate
distribution of Aria licensed under the GPL or a commercial license go to
http://www.mobilerobots.com/SOFTWARE/aria.html or contact MobileRobots
Inc, at robots@mobilerobots.com or MobileRobots Inc,
10 Columbia Drive, Amherst, NH 03031; 800-639-9481

MobileRobots Inc hereby grants to other individuals or
organizations permission to use this software with Arnl and in
compliance with the Arnl license.  This software may not be
distributed to others except by MobileRobots Inc.

MobileRobots Inc does not make any representations about the
suitability of this software for any purpose.  It is provided "as is"
without express or implied warranty.

*/
#ifndef ARSERVERHANDLERCOMMANDS_H
#define ARSERVERHANDLERCOMMANDS_H

#include "Aria.h"
#include "ArServerBase.h"

/// Class for having commands that can be called easily on the client
/**
   You can add commands with addCommand and addStringCommand, you can
   get the list of commands by requesting the data "listCommands" and
   "listStringCommands".
 **/
class ArServerHandlerCommands
{
public:
  /// Constructor
  AREXPORT ArServerHandlerCommands(ArServerBase *server);
  /// Destructor
  AREXPORT virtual ~ArServerHandlerCommands();
  /// Adds a command with no arguments
  AREXPORT bool addCommand(const char *name, const char *description,
			   ArFunctor *functor, 
			   const char *commandGroup = NULL);
  /// Adds a command that takes a string argument
  AREXPORT bool addStringCommand(const char *name, const char *description,
				 ArFunctor1<ArArgumentBuilder *> *functor, 
				 const char *commandGroup = NULL);
  /// Sets a prefix for commands 
  AREXPORT void setPrefix(const char *prefix);
  /// Gets the prefix
  AREXPORT const char *getPrefix(void);
  /// The function that lists the commands
  AREXPORT void netListCommands(ArServerClient *client, ArNetPacket *packet);
  /// The function that lists the string commands
  AREXPORT void netListStringCommands(ArServerClient *client, 
				      ArNetPacket *packet);
  
protected:
  ArServerBase *myServer;
  void netParseCommand(ArServerClient *client, ArNetPacket *packet, 
		       ArFunctor *functor);
  void netParseStringCommand(ArServerClient *client, ArNetPacket *packet, 
			     ArFunctor1<ArArgumentBuilder *> *functor);
  std::list<std::string> myCommands;
  std::list<std::string> myCommandDescriptions;
  std::list<std::string> myStringCommands;
  std::list<std::string> myStringCommandDescriptions;
  std::list<ArFunctor3<ArServerClient *, ArNetPacket *,
		       ArFunctor *> *> myFunctors;
  std::list<ArFunctor3<ArServerClient *, ArNetPacket *, 
		       ArFunctor1<ArArgumentBuilder *> *> *> myStringFunctors;
  std::string myPrefix;
  ArFunctor2C<ArServerHandlerCommands, 
      ArServerClient *, ArNetPacket *> myNetListCommandsCB;
  ArFunctor2C<ArServerHandlerCommands, 
      ArServerClient *, ArNetPacket *> myNetListStringCommandsCB;
};

#endif 
