radio/lib/wModel/model.h

102 lines
3.0 KiB
C
Raw Normal View History

2018-08-04 21:46:25 +00:00
#ifndef W_MODEL_H
#define W_MODEL_H
#include <utils/defines.h>
#include <map>
#include <list>
#include <QtCore/QObject>
#include <QtCore/QString>
#include <wType/address.h>
#include <wType/vector.h>
#include <wType/event.h>
#include <wType/string.h>
#include <wSocket/socket.h>
#include <wDispatcher/handler.h>
#include <wContainer/order.h>
2018-08-04 21:52:16 +00:00
#include <wServerUtils/connector.h>
#include <wController/controller.h>
2018-08-04 21:46:25 +00:00
namespace M {
class Model : public QObject
{
Q_OBJECT
public:
enum ModelType {
string,
list,
vocabulary,
catalogue,
2018-08-04 21:52:16 +00:00
image,
button,
model,
2018-08-04 21:46:25 +00:00
attributes = 50,
file,
2018-08-04 21:52:16 +00:00
resourceCache,
2018-12-17 17:15:58 +00:00
audio,
2018-08-04 21:52:16 +00:00
player = 107
2018-08-04 21:46:25 +00:00
};
Model(const W::Address p_address, QObject* parent = 0);
//i'm not sure about copy constructor, it just doesn't make sense, because the address is the parameter which is supposed to be unique
virtual ~Model();
virtual ModelType getType() const = 0;
virtual void set(W::Object* value) = 0;
virtual void set(const W::Object& value) = 0;
void addModel(M::Model* model);
void addHandler(W::Handler* handler);
void addProperty(const W::String& value, const W::String& name);
2018-08-04 21:52:16 +00:00
void addController(C::Controller* ctrl, const W::String& nodeName);
2018-08-04 21:46:25 +00:00
W::Address getAddress() const;
2018-08-04 21:52:16 +00:00
void getRegistered(U::Connector* connector);
void getUnregistered();
2018-08-04 21:46:25 +00:00
void removeHandler(W::Handler* handler);
void removeModel(M::Model* model);
2018-08-04 21:52:16 +00:00
void removeController(C::Controller* ctrl);
void passToLocalHandler(const W::Event& event) const;
2018-08-04 21:46:25 +00:00
signals:
void serviceMessage(const QString& msg) const;
void subscribersCountChange(uint64_t count) const;
protected:
typedef std::map<W::Address, W::Vocabulary> SMap;
typedef std::map<uint64_t, SMap> Map;
W::Address address;
bool registered;
Map* subscribers;
void send(W::Vocabulary* vc, const W::Address& destination, uint64_t connectionId);
void response(W::Vocabulary* vc, const W::Address& handlerAddress, const W::Event& src);
void fakeResponse(W::Vocabulary* vc, const W::Address& handlerAddress, const W::Address& sourceAddress, const W::Event& src);
void broadcast(W::Vocabulary* vc, const W::Address& handlerAddress);
handler(subscribe)
handler(unsubscribe)
private:
typedef W::Order<W::Handler*> HList;
typedef W::Order<M::Model*> MList;
2018-08-04 21:52:16 +00:00
typedef std::map<C::Controller*, W::String> Controllers;
2018-08-04 21:46:25 +00:00
2018-08-04 21:52:16 +00:00
U::Connector* connector;
2018-08-04 21:46:25 +00:00
uint64_t subscribersCount;
HList* handlers;
W::Vector* properties;
MList* models;
2018-08-04 21:52:16 +00:00
Controllers* controllers;
2018-08-04 21:46:25 +00:00
private slots:
void onSocketDisconnected();
};
}
#endif // W_MODEL_H