#ifndef SIOMANAGER_H
#define SIOMANAGER_H

/*
   SIOManager.h - simple command dispatcher

   Copyright (C) 2002 Matthias Reichl <hias@horus.com>

   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.

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

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/


#include "AbstractSIOHandler.h"
#include "SIOWrapper.h"

class SIOManager {
public:
	SIOManager(SIOWrapper* wrapper);
	~SIOManager();

	int RegisterHandler(unsigned char device_id, AbstractSIOHandler* handler);
	AbstractSIOHandler* GetHandler(unsigned char device_id);
	const AbstractSIOHandler* GetConstHandler(unsigned char device_id) const;

	int UnregisterHandler(unsigned char device_id);

	/*
	 * return:
	 * -1 = an error occurred
	 *  0 = specified device has data available
	 *  1 = error (or signal caught) during select
	 */
	int DoServing(int otherReadPollDevice=-1);

private:
	SIOWrapper* fWrapper;
	AbstractSIOHandler* fHandlers[256];
	
	// debugging stuff (default = off)
};

inline AbstractSIOHandler* SIOManager::GetHandler(unsigned char device_id)
{
	return fHandlers[device_id];
}

inline const AbstractSIOHandler* SIOManager::GetConstHandler(unsigned char device_id) const
{
	return fHandlers[device_id];
}

#endif
