Classified ads
Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
Model Class Reference

M of the MVC pattern. Handles permanent storage. More...

#include <model.h>

Inheritance diagram for Model:
Inheritance graph
[legend]
Collaboration diagram for Model:
Collaboration graph
[legend]

Public Types

enum  RingtoneSetting {
  BowRingTone = 0, ElectricalRingTone = 1, AcousticRingTone = 2, BeepRingTone = 3,
  NoRingTone = 4
}
 
enum  CallAcceptanceSetting { AcceptAllCalls = 0, AcceptCallsFromTrusted = 1, AcceptNoCalls = 2 }
 

Public Slots

void notifyOfContentReceived (const Hash &aHashOfContent, const ProtocolItemType aTypeOfReceivdContent)
 
void notifyOfContentReceived (const Hash &aHashOfContent, const Hash &aHashOfClassification, const ProtocolItemType aTypeOfReceivdContent)
 

Signals

void error (MController::CAErrorSituation aError, const QString &aExplanation)
 

Public Member Functions

 Model (MController *aMController)
 
 ~Model ()
 
ContentEncryptionModelcontentEncryptionModel () const
 
virtual ProfileModelprofileModel () const
 
virtual BinaryFileModelbinaryFileModel () const
 
virtual ClassifiedAdsModelclassifiedAdsModel () const
 
virtual PrivMessageModelprivateMessageModel () const
 
virtual ProfileCommentModelprofileCommentModel () const
 
virtual SearchModelsearchModel () const
 
virtual CaDbRecordModelcaDbRecordModel () const
 
virtual TrustTreeModeltrustTreeModel () const
 
virtual TclModeltclModel () const
 
void addOpenNetworkConnection (Connection *aConnection)
 
void removeOpenNetworkConnection (Connection *aDeletedConnection)
 
void addItemToSend (const Hash &aDestinationNode, QByteArray *aBytesToSend)
 
const QList< Connection * > & getConnections () const
 
QList< NetworkRequestExecutor::NetworkRequestQueueItem > & getNetRequests () const
 
virtual void addNetworkRequest (NetworkRequestExecutor::NetworkRequestQueueItem &aRequest) const
 
virtual bool lock ()
 
virtual void unlock ()
 
virtual MNodeModelProtocolInterfacenodeModel () const
 
NetworkRequestExecutorgetNetReqExecutor ()
 
void closeAllConnections (bool aDeleteAlso)
 
void connectionStateChanged (Connection::ConnectionState aState, Connection *aConnection)
 
PublishItem nextItemToPublish (bool *aFound)
 
void addItemToBePublished (ProtocolItemType aType, const Hash &aHash, const QList< quint32 > &aBangPath, const Hash &aSecondaryAddr=KNullHash)
 
PublishItem addNodeToPublishedItem (const Hash &aContentHash, const Hash &aNodeHash)
 
Model::RingtoneSetting getRingtoneSetting ()
 
void setRingtoneSetting (Model::RingtoneSetting aRingTone)
 
Model::CallAcceptanceSetting getCallAcceptanceSetting ()
 
void setCallAcceptanceSetting (Model::CallAcceptanceSetting aAcceptance)
 

Protected Member Functions

void timerEvent (QTimerEvent *event)
 

Private Member Functions

bool openDB ()
 
QSqlError lastError ()
 
bool createTables ()
 
bool createTablesV2 ()
 
bool createTablesV3 ()
 
bool createTablesV4 ()
 
void initPseudoRandom ()
 

Private Attributes

MControlleriController
 
QSqlDatabase iDb
 
QMutex * iMutex
 
QList< Connection * > * iConnections
 
NodeModeliNodeModel
 
NetworkRequestExecutoriNetReqExecutor
 
QList< NetworkRequestExecutor::NetworkRequestQueueItem > * iNetReqQueue
 
ContentEncryptionModeliContentEncryptionModel
 
ProfileModeliProfileModel
 
BinaryFileModeliBinaryFileModel
 
ClassifiedAdsModeliCaModel
 
int iTimerId
 
PrivMessageModeliPrivMsgModel
 
ProfileCommentModeliProfileCommentModel
 
SearchModeliSearchModel
 
CaDbRecordModeliCaDbRecordModel
 
TrustTreeModeliTrustTreeModel
 
time_t iTimeOfLastNetworkAddrCheck
 
TclModeliTclModel
 

Detailed Description

M of the MVC pattern. Handles permanent storage.

All permanent data storage inside classified ads goes somehow via this class here. If user wants to display data, view gets it from here, if a peer wants to leech a phile, it comes from here

Member Enumeration Documentation

◆ CallAcceptanceSetting

Enumeration for call acceptance settings. Numbering of the enum must exactly follow indexing of items in callAcceptanceComboBox in settings UI dialog.

Enumerator
AcceptAllCalls 
AcceptCallsFromTrusted 
AcceptNoCalls 

◆ RingtoneSetting

Enumeration for ringtone settings. Numbering of the enum must exactly follow indexing of items in ringToneComboxBox in settings UI dialog.

Enumerator
BowRingTone 
ElectricalRingTone 
AcousticRingTone 
BeepRingTone 
NoRingTone 

Constructor & Destructor Documentation

◆ Model()

Model::Model ( MController aMController)

◆ ~Model()

Model::~Model ( )

Member Function Documentation

◆ addItemToBePublished()

void Model::addItemToBePublished ( ProtocolItemType  aType,
const Hash aHash,
const QList< quint32 > &  aBangPath,
const Hash aSecondaryAddr = KNullHash 
)

Method for marking item already in datamodel to be published via PublishingEngine class. For example, if publishing a profile user must first insert the profile into profilemodel, and only after that call this method here.

Parameters
aTypetells type of an item - profile,privmsg,binary blob etc.
aHashfingerprint for identifies object
aBangPathlist of low-order hash-bits of nodes where this content is already supposed to be found
aSecondaryAddris possible 2nd publish addr, used for CA and comment. for private messages this is the destination node, if known.

◆ addItemToSend()

void Model::addItemToSend ( const Hash aDestinationNode,
QByteArray *  aBytesToSend 
)

Method that other parts of this program use to append items into send queue of node connection.

Parameters
aDestinationNodespecifies the node to receive bytes
aBytesToSendcontains the message. Ownership of bytes is transferred to datamodel i.e. after this method is called, the caller is not supposed to delete the bytes itself but that task is left to datamodel to do.
Returns
none.

◆ addNetworkRequest()

virtual void Model::addNetworkRequest ( NetworkRequestExecutor::NetworkRequestQueueItem aRequest) const
virtual

From MModelProtocolInterface

method for adding a network request

Parameters
aRequestis the request to add
Returns
none

Implements MModelProtocolInterface.

◆ addNodeToPublishedItem()

PublishItem Model::addNodeToPublishedItem ( const Hash aContentHash,
const Hash aNodeHash 
)

When publishing-engine is doing its job, it uses this method to update the list of nodes that have received the published content.

Parameters
aContentHashidentifies the published content that has been pushed into one node
aNodeHashidentifies the node where content was pushed to
Returns
The same item to publish, now updated. If the content is already published into enough hosts (model decides) it will return a PublishItem will null hash to tell publishing-engine that this piece of content is now done and it is time to move to next.

◆ addOpenNetworkConnection()

void Model::addOpenNetworkConnection ( Connection aConnection)

Method for adding newly created peer-connection to list kept by datamodel

◆ binaryFileModel()

virtual BinaryFileModel& Model::binaryFileModel ( ) const
virtual

method for getting binary-blob datamodel

Implements MModelProtocolInterface.

◆ caDbRecordModel()

virtual CaDbRecordModel* Model::caDbRecordModel ( ) const
virtual

method for getting distributed database model part

Implements MModelProtocolInterface.

◆ classifiedAdsModel()

virtual ClassifiedAdsModel& Model::classifiedAdsModel ( ) const
virtual

method for getting the ads datamodel

Implements MModelProtocolInterface.

◆ closeAllConnections()

void Model::closeAllConnections ( bool  aDeleteAlso)

Close all connections that might be open. Called before deletia.

Parameters
aDeleteAlsoif set to true, will delete remaining connections. if that needs to be done, results easily in SEGFAULT as connections are threads .. they should be closed so that threads no longer run, run() returns and thread cleans up itself..

◆ connectionStateChanged()

void Model::connectionStateChanged ( Connection::ConnectionState  aState,
Connection aConnection 
)

method for communicating the fact that socket is open or closed

◆ contentEncryptionModel()

ContentEncryptionModel& Model::contentEncryptionModel ( ) const
virtual

method for getting content-encryption-specific datamodel

Implements MModelProtocolInterface.

◆ createTables()

bool Model::createTables ( )
private

◆ createTablesV2()

bool Model::createTablesV2 ( )
private

◆ createTablesV3()

bool Model::createTablesV3 ( )
private

◆ createTablesV4()

bool Model::createTablesV4 ( )
private

◆ error

void Model::error ( MController::CAErrorSituation  aError,
const QString &  aExplanation 
)
signal

◆ getCallAcceptanceSetting()

Model::CallAcceptanceSetting Model::getCallAcceptanceSetting ( )

getter method for users call-acceptance-setting

◆ getConnections()

const QList<Connection *>& Model::getConnections ( ) const

Currently open connections. Caller does not own the returned list and should not try adding/removing items from it.

◆ getNetReqExecutor()

NetworkRequestExecutor* Model::getNetReqExecutor ( )

pointer to class handling network requests

◆ getNetRequests()

QList<NetworkRequestExecutor::NetworkRequestQueueItem>& Model::getNetRequests ( ) const

Currently pending network requests. Even as this returns a pointer, not a reference, ownership of the list is not transferred ; caller may modiify content but is not supposed to delete

◆ getRingtoneSetting()

Model::RingtoneSetting Model::getRingtoneSetting ( )

getter method for users ringtone-setting

◆ initPseudoRandom()

void Model::initPseudoRandom ( )
private

just calls srand()

◆ lastError()

QSqlError Model::lastError ( )
private

◆ lock()

virtual bool Model::lock ( )
virtual

From MModelProtocolInterface. thread sync: this claims access to datamodel

Implements MModelProtocolInterface.

◆ nextItemToPublish()

PublishItem Model::nextItemToPublish ( bool *  aFound)

method for getting next item to publish

Parameters
aFoundwill be set to true if there is an item to publish
Returns
if aFound is true, returned item contains details about the item to publish.

◆ nodeModel()

virtual MNodeModelProtocolInterface& Model::nodeModel ( ) const
virtual

From MModelProtocolInterface.

method for getting node-specific datamodel

Implements MModelProtocolInterface.

◆ notifyOfContentReceived [1/2]

void Model::notifyOfContentReceived ( const Hash aHashOfContent,
const ProtocolItemType  aTypeOfReceivdContent 
)
slot

notification of content received

◆ notifyOfContentReceived [2/2]

void Model::notifyOfContentReceived ( const Hash aHashOfContent,
const Hash aHashOfClassification,
const ProtocolItemType  aTypeOfReceivdContent 
)
slot

notification of classified ads received

◆ openDB()

bool Model::openDB ( )
private

◆ privateMessageModel()

virtual PrivMessageModel& Model::privateMessageModel ( ) const
virtual

method for getting the priv msg datamodel

Implements MModelProtocolInterface.

◆ profileCommentModel()

virtual ProfileCommentModel& Model::profileCommentModel ( ) const
virtual

method for getting the comment datamodel

Implements MModelProtocolInterface.

◆ profileModel()

virtual ProfileModel& Model::profileModel ( ) const
virtual

method for getting profile-specific datamodel

Implements MModelProtocolInterface.

◆ removeOpenNetworkConnection()

void Model::removeOpenNetworkConnection ( Connection aDeletedConnection)

Method for telling datamodel about a existing network connection has been closed for any reason that is valid for a socket.

Parameters
aConnectionis pointer to the connection
Returns
none

◆ searchModel()

virtual SearchModel* Model::searchModel ( ) const
virtual

method for getting the full text search datamodel

Implements MModelProtocolInterface.

◆ setCallAcceptanceSetting()

void Model::setCallAcceptanceSetting ( Model::CallAcceptanceSetting  aAcceptance)

getter method for users call-acceptance-setting

◆ setRingtoneSetting()

void Model::setRingtoneSetting ( Model::RingtoneSetting  aRingTone)

getter method for users ringtone-setting

◆ tclModel()

virtual TclModel& Model::tclModel ( ) const
virtual

method for getting the storage of TCL programs

Implements MModelProtocolInterface.

◆ timerEvent()

void Model::timerEvent ( QTimerEvent *  event)
protected

for periodical stuff inside datamodel

◆ trustTreeModel()

virtual TrustTreeModel* Model::trustTreeModel ( ) const
virtual

method for getting the trust tree datamodel

◆ unlock()

virtual void Model::unlock ( )
virtual

From MModelProtocolInterface. thread sync: releases data model to other threads

Implements MModelProtocolInterface.

Member Data Documentation

◆ iBinaryFileModel

BinaryFileModel* Model::iBinaryFileModel
private

Random binary blob storage

◆ iCaDbRecordModel

CaDbRecordModel* Model::iCaDbRecordModel
private

distributed general-purpose database

◆ iCaModel

ClassifiedAdsModel* Model::iCaModel
private

Classified ads storage

◆ iConnections

QList<Connection *>* Model::iConnections
private

◆ iContentEncryptionModel

ContentEncryptionModel* Model::iContentEncryptionModel
private

cryptographic animal

◆ iController

MController* Model::iController
private

◆ iDb

QSqlDatabase Model::iDb
private

actual storage here

◆ iMutex

QMutex* Model::iMutex
private

this mutex protects access to this datamodel

◆ iNetReqExecutor

NetworkRequestExecutor* Model::iNetReqExecutor
private

◆ iNetReqQueue

QList<NetworkRequestExecutor::NetworkRequestQueueItem>* Model::iNetReqQueue
private

have datamodel own network request queue, this is our queue of pending tasks

◆ iNodeModel

NodeModel* Model::iNodeModel
private

Network connections currently open datamodel about our peers

◆ iPrivMsgModel

PrivMessageModel* Model::iPrivMsgModel
private

storage of private messages

◆ iProfileCommentModel

ProfileCommentModel* Model::iProfileCommentModel
private

comments data storage

◆ iProfileModel

ProfileModel* Model::iProfileModel
private

Profile data storage

◆ iSearchModel

SearchModel* Model::iSearchModel
private

full text search model part

◆ iTclModel

TclModel* Model::iTclModel
private

TCL scripts storage

◆ iTimeOfLastNetworkAddrCheck

time_t Model::iTimeOfLastNetworkAddrCheck
private

timestamp of local addr update

◆ iTimerId

int Model::iTimerId
private

id of our periodical timer

◆ iTrustTreeModel

TrustTreeModel* Model::iTrustTreeModel
private

trust list handling model


The documentation for this class was generated from the following file: