// **********************************************************************
//
// Copyright (c) 1998
// Object-Oriented Concepts, Inc.
// Billerica, MA, USA
//
// Copyright (c) 1998
// Object-Oriented Concepts GmbH
// Ettlingen, Germany
//
// All Rights Reserved
//
// **********************************************************************

#ifndef OB_REACTOR_H
#define OB_REACTOR_H

//
// Event handler handle
// The event mask
// The event types
//
typedef int OBHandle;
typedef CORBA_ULong OBMask;
const OBMask OBEventRead = 0x1;
const OBMask OBEventWrite = 0x2;

//
// The OBEventHandler class
//
class OBEventHandler
{
    //
    // Hide copy-constructor and asignment operator
    //
    OBEventHandler(const OBEventHandler&);
    void operator=(const OBEventHandler&);

protected:

    OBEventHandler() { }
    virtual ~OBEventHandler() { }

public:

    //
    // Handle event
    // Handle reactor stop
    //
    virtual void handleEvent(OBMask) = 0;
    virtual void handleStop() = 0;
};

//
// The OBReactor base class
//
class OBReactor
{
    //
    // Hide copy-constructor and asignment operator
    //
    OBReactor(const OBReactor&);
    void operator=(const OBReactor&);

protected:

    //
    // The Reactor singleton
    //
    static OBReactor* reactor_;

    //
    // The "stop" flag
    //
    bool stop_;

    OBReactor() : stop_(false) { }
    virtual ~OBReactor() { }

public:

    //
    // Get the reactor singleton
    //
    static OBReactor* instance();

    //
    // Register and unregister event handler
    //
    virtual void registerHandler(OBEventHandler*, OBMask, OBHandle) = 0;
    virtual void unregisterHandler(OBEventHandler*) = 0;

    //
    // Dispatch events
    // Stop dispatching events
    //
    virtual void dispatch() = 0;
    virtual void stop() { stop_ = true; }

    //
    // Dispatch one event
    //
    virtual bool dispatchOneEvent(CORBA_Long) = 0;
};

#endif
