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-2016.
3 
4  This file is part of Classified Ads.
5 
6  Classified Ads is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (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 GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with Classified Ads; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #ifndef CLASSIFIED_DATAMODEL_H
22 #define CLASSIFIED_DATAMODEL_H
23 #include <QSqlDatabase>
24 #include <QObject>
25 #include "../mcontroller.h" // because enum from there is needed
26 #include "../net/connection.h"
27 #include <QHostAddress>
28 #include <QPair>
29 #include "netrequestexecutor.h"
30 #include "nodemodel.h"
33 
34 class QSqlDatabase ;
35 class QMutex ;
36 class Hash ;
37 class QSslCertificate ;
38 class QSslKey ;
39 class SearchModel ;
40 class TrustTreeModel ;
41 class TclModel ;
42 
51  Q_OBJECT
52 
53 public:
54  // public enums
67  } ;
78  } ;
79  // methods
80  Model(MController *aMController) ;
81  ~Model() ;
83  virtual ProfileModel& profileModel() const ;
84  virtual BinaryFileModel& binaryFileModel() const ;
85  virtual ClassifiedAdsModel& classifiedAdsModel() const ;
86  virtual PrivMessageModel& privateMessageModel() const ;
87  virtual ProfileCommentModel& profileCommentModel() const ;
88  virtual SearchModel* searchModel() const ;
89  virtual CaDbRecordModel* caDbRecordModel() const ;
90  virtual TrustTreeModel* trustTreeModel() const ;
91  virtual TclModel& tclModel() const ;
96  void addOpenNetworkConnection(Connection *aConnection) ;
103  void removeOpenNetworkConnection(Connection *aDeletedConnection) ;
104 
115  void addItemToSend(const Hash& aDestinationNode,
116  QByteArray* aBytesToSend) ;
117 
122  const QList <Connection *>& getConnections() const ;
129  QList <NetworkRequestExecutor::NetworkRequestQueueItem>& getNetRequests() const ;
138  aRequest) const ;
143  virtual bool lock() ;
148  virtual void unlock() ;
154  virtual MNodeModelProtocolInterface& nodeModel() const ;
169  void closeAllConnections(bool aDeleteAlso) ;
174  Connection *aConnection) ;
181  PublishItem nextItemToPublish(bool* aFound) ;
196  const Hash& aHash,
197  const QList<quint32>& aBangPath,
198  const Hash& aSecondaryAddr = KNullHash ) ;
212  PublishItem addNodeToPublishedItem(const Hash& aContentHash,const Hash& aNodeHash) ;
221 
230 
231 
232 public slots:
236  void notifyOfContentReceived(const Hash& aHashOfContent,
237  const ProtocolItemType aTypeOfReceivdContent) ;
241  void notifyOfContentReceived(const Hash& aHashOfContent,
242  const Hash& aHashOfClassification,
243  const ProtocolItemType aTypeOfReceivdContent) ;
244 protected:
248  void timerEvent(QTimerEvent *event);
249 private:
250  bool openDB();
251  QSqlError lastError();
252  // 1st-time initialization methods ahead
253  bool createTables() ;
254  // additions to first version of tables
255  bool createTablesV2() ;
256  // additions to 2nd version of tables
257  bool createTablesV3() ;
258  // additions to 3rd version of tables
259  bool createTablesV4() ;
260  void initPseudoRandom() ;
261 signals:
263  const QString& aExplanation) ;
264 private:
266  QSqlDatabase iDb;
267  QMutex* iMutex ;
268  QList <Connection *> *iConnections ;
275  QList <NetworkRequestExecutor::NetworkRequestQueueItem>* iNetReqQueue ;
280  int iTimerId ;
288 } ;
289 #endif
Model::CallAcceptanceSetting getCallAcceptanceSetting()
Definition: model.h:77
void initPseudoRandom()
void setRingtoneSetting(Model::RingtoneSetting aRingTone)
void addItemToBePublished(ProtocolItemType aType, const Hash &aHash, const QList< quint32 > &aBangPath, const Hash &aSecondaryAddr=KNullHash)
CaDbRecordModel * iCaDbRecordModel
Definition: model.h:284
PublishItem addNodeToPublishedItem(const Hash &aContentHash, const Hash &aNodeHash)
Definition: model.h:63
void addItemToSend(const Hash &aDestinationNode, QByteArray *aBytesToSend)
void notifyOfContentReceived(const Hash &aHashOfContent, const ProtocolItemType aTypeOfReceivdContent)
void addOpenNetworkConnection(Connection *aConnection)
Definition: model.h:62
Logic for handling tasks received from other peers or from user.
Definition: netrequestexecutor.h:40
Model-class for performing text-based searches on objects in db This datamodel part is dual-use ; it ...
Definition: searchmodel.h:45
virtual PrivMessageModel & privateMessageModel() const
This is is part of datamodel for storing comments of user profiles.
Definition: profilecommentmodel.h:38
This is is part of datamodel for storing private messages.
Definition: privmsgmodel.h:51
ProfileCommentModel * iProfileCommentModel
Definition: model.h:282
virtual void unlock()
virtual SearchModel * searchModel() const
TclModel * iTclModel
Definition: model.h:287
Definition: model.h:75
int iTimerId
Definition: model.h:280
MController * iController
Definition: model.h:265
Hash is class that carries 160-bit digest.
Definition: hash.h:38
CAErrorSituation
Definition: mcontroller.h:57
virtual ProfileModel & profileModel() const
time_t iTimeOfLastNetworkAddrCheck
Definition: model.h:286
bool createTablesV2()
ContentEncryptionModel * iContentEncryptionModel
Definition: model.h:276
TrustTreeModel * iTrustTreeModel
Definition: model.h:285
ConnectionState
Definition: connection.h:47
ProtocolItemType
Definition: protocol.h:157
This is part of datamodel for storage/retrieval of classified ads.
Definition: camodel.h:40
ProfileModel * iProfileModel
Definition: model.h:277
void setCallAcceptanceSetting(Model::CallAcceptanceSetting aAcceptance)
Model(MController *aMController)
virtual bool lock()
PublishItem nextItemToPublish(bool *aFound)
virtual TclModel & tclModel() const
Pure-virtual interface of datamodel for message parser to use.
Definition: mmodelprotocolinterface.h:46
Definition: model.h:65
virtual void addNetworkRequest(NetworkRequestExecutor::NetworkRequestQueueItem &aRequest) const
Definition: model.h:76
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:48
void connectionStateChanged(Connection::ConnectionState aState, Connection *aConnection)
Hash KNullHash
void timerEvent(QTimerEvent *event)
bool createTablesV4()
bool createTables()
NetworkRequestExecutor * iNetReqExecutor
Definition: model.h:270
M of the MVC pattern. Handles permanent storage.
Definition: model.h:50
RingtoneSetting
Definition: model.h:61
virtual CaDbRecordModel * caDbRecordModel() const
ContentEncryptionModel & contentEncryptionModel() const
This is is part of datamodel for storing user profiles.
Definition: profilemodel.h:39
PrivMessageModel * iPrivMsgModel
Definition: model.h:281
void closeAllConnections(bool aDeleteAlso)
virtual BinaryFileModel & binaryFileModel() const
Model::RingtoneSetting getRingtoneSetting()
virtual ClassifiedAdsModel & classifiedAdsModel() const
QList< NetworkRequestExecutor::NetworkRequestQueueItem > & getNetRequests() const
This is node-specific part of the datamodel.
Definition: nodemodel.h:46
QList< Connection * > * iConnections
Definition: model.h:268
NetworkRequestExecutor * getNetReqExecutor()
void error(MController::CAErrorSituation aError, const QString &aExplanation)
ClassifiedAdsModel * iCaModel
Definition: model.h:279
Definition: model.h:66
virtual TrustTreeModel * trustTreeModel() const
Datamodel-part of storage related to TCL-programs.
Definition: tclmodel.h:38
NodeModel * iNodeModel
Definition: model.h:269
QSqlError lastError()
Work queue item.
Definition: netrequestexecutor.h:60
CallAcceptanceSetting
Definition: model.h:74
QMutex * iMutex
Definition: model.h:267
This is is part of datamodel for storing database records.
Definition: cadbrecordmodel.h:44
Definition: model.h:64
BinaryFileModel * iBinaryFileModel
Definition: model.h:278
Pure-virtual interface of nodemodel.
Definition: mnodemodelprotocolinterface.h:39
const QList< Connection * > & getConnections() const
SearchModel * iSearchModel
Definition: model.h:283
bool createTablesV3()
This is is part of datamodel for trust tree related operation.
Definition: trusttreemodel.h:55
Carrier for keeping state of item about to be published.
Definition: protocol.h:206
Class that represents a network connection.
Definition: connection.h:43
QList< NetworkRequestExecutor::NetworkRequestQueueItem > * iNetReqQueue
Definition: model.h:275
QSqlDatabase iDb
Definition: model.h:266
This is part of datamodel for any binary blobs.
Definition: binaryfilemodel.h:39
virtual MNodeModelProtocolInterface & nodeModel() const
virtual ProfileCommentModel & profileCommentModel() const
This is content-crypto-operations-specific part of the datamodel.
Definition: contentencryptionmodel.h:37
bool openDB()
void removeOpenNetworkConnection(Connection *aDeletedConnection)