/****************************************************************************
**
** Copyright (C) 1992-2004 Trolltech AS. All rights reserved.
**
** This file is part of the embedded classes of the Qt Toolkit.
**
** Licensees holding valid Qt Preview licenses may use this file in
** accordance with the Qt Preview License Agreement provided with the
** Software.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/

#ifndef QCOPCHANNEL_QWS_H
#define QCOPCHANNEL_QWS_H

#include "qobject.h"

#ifndef QT_NO_COP

class QWSClient;
class QCopChannelPrivate;

class QCopChannel : public QObject
{
    Q_OBJECT
public:
    QCopChannel(const QByteArray &channel, QObject *parent=0);
#ifdef QT_COMPAT
    QCopChannel(const QByteArray &channel, QObject *parent, const char *name);
#endif
    virtual ~QCopChannel();

    QByteArray channel() const;

    static bool isRegistered(const QByteArray& channel);
    static bool send(const QByteArray &channel, const QByteArray &msg);
    static bool send(const QByteArray &channel, const QByteArray &msg,
                      const QByteArray &data);

    static void sendLocally( const QByteArray &ch, const QByteArray &msg,
                               const QByteArray &data);

    virtual void receive(const QByteArray &msg, const QByteArray &data);

signals:
    void received(const QByteArray &msg, const QByteArray &data);

private:
    void init(const QByteArray &channel);

    // server side
    static void registerChannel(const QString &ch, QWSClient *cl);
    static void detach(QWSClient *cl);
    static void answer(QWSClient *cl, const QByteArray &ch,
                        const QByteArray &msg, const QByteArray &data);
    // client side
    QCopChannelPrivate* d;

    friend class QWSServer;
    friend class QApplication;
};

#endif

#endif // QCOPCHANNEL_QWS_H
