Classified ads
model.h
Go to the documentation of this file.
1 /* -*-C++-*- -*-coding: utf-8-unix;-*-
2  Classified Ads is Copyright (c) Antti Jarvinen 2013.
3 
4  This file is part of Classified Ads.
5 
6  Classified Ads is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Classified Ads is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Classified Ads. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef CLASSIFIED_DATAMODEL_H
21 #define CLASSIFIED_DATAMODEL_H
22 #include <QSqlDatabase>
23 #include <QObject>
24 #include "../mcontroller.h" // because enum from there is needed
25 #include "../net/connection.h"
26 #include <QHostAddress>
27 #include <QPair>
28 #include "netrequestexecutor.h"
29 #include "nodemodel.h"
32 
33 class QSqlDatabase ;
34 class QMutex ;
35 class Hash ;
36 class QSslCertificate ;
37 class QSslKey ;
38 class SearchModel ;
39 
48  Q_OBJECT
49 
50 public:
51  Model(MController *aMController) ;
52  ~Model() ;
54  virtual ProfileModel& profileModel() const ;
55  virtual BinaryFileModel& binaryFileModel() const ;
56  virtual ClassifiedAdsModel& classifiedAdsModel() const ;
57  virtual PrivMessageModel& privateMessageModel() const ;
58  virtual ProfileCommentModel& profileCommentModel() const ;
59  virtual SearchModel* searchModel() const ;
60  void addOpenNetworkConnection(Connection *aConnection) ;
67  void removeOpenNetworkConnection(Connection *aDeletedConnection) ;
68 
79  void addItemToSend(const Hash& aDestinationNode,
80  QByteArray* aBytesToSend) ;
81 
85  const QList <Connection *>& getConnections() const ;
92  QList <NetworkRequestExecutor::NetworkRequestQueueItem>& getNetRequests() const ;
101  aRequest) const ;
106  virtual bool lock() ;
111  virtual void unlock() ;
117  virtual MNodeModelProtocolInterface& nodeModel() const ;
132  void closeAllConnections(bool aDeleteAlso) ;
137  Connection *aConnection) ;
144  PublishItem nextItemToPublish(bool* aFound) ;
159  const Hash& aHash,
160  const QList<quint32>& aBangPath,
161  const Hash& aSecondaryAddr = KNullHash ) ;
175  PublishItem addNodeToPublishedItem(const Hash& aContentHash,const Hash& aNodeHash) ;
176 public slots:
180  void notifyOfContentReceived(const Hash& aHashOfContent,
181  const ProtocolItemType aTypeOfReceivdContent) ;
185  void notifyOfContentReceived(const Hash& aHashOfContent,
186  const Hash& aHashOfClassification,
187  const ProtocolItemType aTypeOfReceivdContent) ;
188 protected:
192  void timerEvent(QTimerEvent *event);
193 private:
194  bool openDB();
195  QSqlError lastError();
196  // 1st-time initialization methods ahead
197  bool createTables() ;
198  void initPseudoRandom() ;
199 signals:
201  const QString& aExplanation) ;
202 private:
204  QSqlDatabase iDb;
205  QMutex* iMutex ;
206  QList <Connection *> *iConnections ;
213  QList <NetworkRequestExecutor::NetworkRequestQueueItem>* iNetReqQueue ;
218  int iTimerId ;
222 } ;
223 #endif
void initPseudoRandom()
virtual PrivMessageModel & privateMessageModel() const
void addItemToBePublished(ProtocolItemType aType, const Hash &aHash, const QList< quint32 > &aBangPath, const Hash &aSecondaryAddr=KNullHash)
virtual SearchModel * searchModel() const
PublishItem addNodeToPublishedItem(const Hash &aContentHash, const Hash &aNodeHash)
void addItemToSend(const Hash &aDestinationNode, QByteArray *aBytesToSend)
void notifyOfContentReceived(const Hash &aHashOfContent, const ProtocolItemType aTypeOfReceivdContent)
void addOpenNetworkConnection(Connection *aConnection)
Logic for handling tasks received from other peers or from user.
Definition: netrequestexecutor.h:39
Model-class for performing text-based searches on objects in db This datamodel part is dual-use ; it ...
Definition: searchmodel.h:44
This is is part of datamodel for storing comments of user profiles.
Definition: profilecommentmodel.h:37
This is is part of datamodel for storing private messages.
Definition: privmsgmodel.h:50
ProfileCommentModel * iProfileCommentModel
Definition: model.h:220
virtual void unlock()
const QList< Connection * > & getConnections() const
int iTimerId
Definition: model.h:218
MController * iController
Definition: model.h:203
Hash is class that carries 160-bit digest.
Definition: hash.h:37
CAErrorSituation
Definition: mcontroller.h:48
ContentEncryptionModel * iContentEncryptionModel
Definition: model.h:214
virtual void addNetworkRequest(NetworkRequestExecutor::NetworkRequestQueueItem &aRequest) const
QList< NetworkRequestExecutor::NetworkRequestQueueItem > & getNetRequests() const
ConnectionState
Definition: connection.h:45
ProtocolItemType
Definition: protocol.h:124
This is part of datamodel for storage/retrieval of classified ads.
Definition: camodel.h:38
ProfileModel * iProfileModel
Definition: model.h:215
Model(MController *aMController)
virtual bool lock()
PublishItem nextItemToPublish(bool *aFound)
Pure-virtual interface of datamodel for message parser to use.
Definition: mmodelprotocolinterface.h:44
virtual BinaryFileModel & binaryFileModel() const
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:39
void connectionStateChanged(Connection::ConnectionState aState, Connection *aConnection)
virtual ProfileCommentModel & profileCommentModel() const
Hash KNullHash
void timerEvent(QTimerEvent *event)
bool createTables()
NetworkRequestExecutor * iNetReqExecutor
Definition: model.h:208
M of the MVC pattern. Handles permanent storage.
Definition: model.h:47
This is is part of datamodel for storing user profiles.
Definition: profilemodel.h:38
PrivMessageModel * iPrivMsgModel
Definition: model.h:219
virtual ProfileModel & profileModel() const
void closeAllConnections(bool aDeleteAlso)
ContentEncryptionModel & contentEncryptionModel() const
This is node-specific part of the datamodel.
Definition: nodemodel.h:45
QList< Connection * > * iConnections
Definition: model.h:206
NetworkRequestExecutor * getNetReqExecutor()
virtual ClassifiedAdsModel & classifiedAdsModel() const
void error(MController::CAErrorSituation aError, const QString &aExplanation)
ClassifiedAdsModel * iCaModel
Definition: model.h:217
NodeModel * iNodeModel
Definition: model.h:207
QSqlError lastError()
Work queue item.
Definition: netrequestexecutor.h:59
virtual MNodeModelProtocolInterface & nodeModel() const
QMutex * iMutex
Definition: model.h:205
BinaryFileModel * iBinaryFileModel
Definition: model.h:216
Pure-virtual interface of nodemodel.
Definition: mnodemodelprotocolinterface.h:38
SearchModel * iSearchModel
Definition: model.h:221
Carrier for keeping state of item about to be published.
Definition: protocol.h:168
Class that represents a network connection.
Definition: connection.h:41
QList< NetworkRequestExecutor::NetworkRequestQueueItem > * iNetReqQueue
Definition: model.h:213
QSqlDatabase iDb
Definition: model.h:204
This is part of datamodel for any binary blobs.
Definition: binaryfilemodel.h:38
This is content-crypto-operations-specific part of the datamodel.
Definition: contentencryptionmodel.h:36
bool openDB()
void removeOpenNetworkConnection(Connection *aDeletedConnection)