Gaia
yamlrpcserver.h
1 /*
2  * Copyright (C) 2006-2013 Music Technology Group - Universitat Pompeu Fabra
3  *
4  * This file is part of Gaia
5  *
6  * Gaia is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License as published by the Free
8  * Software Foundation (FSF), either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the Affero GNU General Public License
17  * version 3 along with this program. If not, see http://www.gnu.org/licenses/
18  */
19 
20 #ifndef GAIA_YAMLRPCSERVER_H
21 #define GAIA_YAMLRPCSERVER_H
22 
23 #include <QTcpServer>
24 #include <QDateTime>
25 #include "yamlcpp.h"
26 
27 
28 GAIA_DEFINE_EXCEPTION(NotImplementedError);
29 GAIA_DEFINE_EXCEPTION(InvalidParams);
30 
31 class YamlProxy {
32  public:
33  virtual gaia2::yaml::Node process(const gaia2::yaml::Mapping& query) = 0;
34  virtual ~YamlProxy() {}
35 };
36 
40 QString timeElapsed(const QDateTime& from, const QDateTime& to);
41 
45 gaia2::yaml::Mapping rpcError(int code, const QString& msg);
46 
50 QByteArray readHTTPRequest(QTcpSocket* socket);
51 
52 
56 gaia2::yaml::Mapping readYamlRPCRequest(QTcpSocket* socket);
57 
58 
59 class YamlRPCServer : public QTcpServer {
60 Q_OBJECT
61 
62  public:
63 
64  YamlRPCServer(quint16 port, YamlProxy* proxy);
65 
66  void incomingConnection(int socket);
67 
68  gaia2::yaml::Mapping processRequest(QTcpSocket* socket);
69 
70  int numberConnectedClients() const;
71 
72  signals:
73  void quit();
74 
75  protected slots:
76  virtual void readClient();
77  void discardClient();
78 
79  protected:
80  YamlProxy* _proxy;
81  QDateTime _startedOn;
82 
83  QMap<QTcpSocket*, QByteArray> _socketIDs;
84 };
85 
86 
87 #endif // GAIA_YAMLRPCSERVER_H
Definition: yamlrpcserver.h:59
Definition: yamlrpcserver.h:31
Definition: yamlcpp.h:77