/*
 * SmartHome server: Base of the system
 *
 * Copyright (C) 2010 Daniel Pisi <dan.pisi@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License
 * as published by the Free Software Foundation.
 *
 */

/**
 * @file shbase.h
 * @brief Base of the SmartHome server
 * @author Daniel Pisi
 */

#ifndef SHBASE_H
#define SHBASE_H

#include <QObject>
#include <QPair>
#include "shobject.h"
#include "shpin.h"

// -----------------------------------------------------------------------------

/**
 * \class ShBase
 * \brief Main modular subsystem class
 *
 * This class is able to load/unload plugins reflecting configuration stored in the database.
 * It also allows plugins to communicate with each other by routing the messages according
 * to the list of links stored in the database.
 */
class ShBase : public QObject
{
    Q_OBJECT

public:
    ShBase(QObject *parent = 0);

public slots:
    void routeMessage(ShMessagePtr message);

private:
    void reload();

    QList<ShPin> queryPins(int objectId);
    int queryPinId(int object, QString signal);
    bool pinBelongsTo(int pin, int object);
    ShPin queryPin(int pinId);

    QMap<int,ShObject*> mObjects;
};
// -----------------------------------------------------------------------------

#endif // SHBASE_H
