Classified ads
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 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
 
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
MNodeModelProtocolInterface
nodeModel () 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)
 

Protected Member Functions

void timerEvent (QTimerEvent *event)
 

Private Member Functions

bool openDB ()
 
QSqlError lastError ()
 
bool createTables ()
 
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
 

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

Constructor & Destructor Documentation

Model::Model ( MController aMController)
Model::~Model ( )

Member Function Documentation

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.
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.
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.

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.
void Model::addOpenNetworkConnection ( Connection aConnection)
virtual BinaryFileModel& Model::binaryFileModel ( ) const
virtual

method for getting binary-blob datamodel

Implements MModelProtocolInterface.

virtual ClassifiedAdsModel& Model::classifiedAdsModel ( ) const
virtual

method for getting the ads datamodel

Implements MModelProtocolInterface.

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..
void Model::connectionStateChanged ( Connection::ConnectionState  aState,
Connection aConnection 
)

method for communicating the fact that socket is open or closed

ContentEncryptionModel& Model::contentEncryptionModel ( ) const
virtual

method for getting content-encryption-specific datamodel

Implements MModelProtocolInterface.

bool Model::createTables ( )
private
void Model::error ( MController::CAErrorSituation  aError,
const QString &  aExplanation 
)
signal
const QList<Connection *>& Model::getConnections ( ) const

Currently open connections.

NetworkRequestExecutor* Model::getNetReqExecutor ( )

pointer to class handling network requests

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

void Model::initPseudoRandom ( )
private

just calls srand()

QSqlError Model::lastError ( )
private
virtual bool Model::lock ( )
virtual

From MModelProtocolInterface. thread sync: this claims access to datamodel

Implements MModelProtocolInterface.

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.
virtual MNodeModelProtocolInterface& Model::nodeModel ( ) const
virtual

From MModelProtocolInterface.

method for getting node-specific datamodel

Implements MModelProtocolInterface.

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

notification of content received

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

notification of classified ads received

bool Model::openDB ( )
private
virtual PrivMessageModel& Model::privateMessageModel ( ) const
virtual

method for getting the priv msg datamodel

Implements MModelProtocolInterface.

virtual ProfileCommentModel& Model::profileCommentModel ( ) const
virtual

method for getting the comment datamodel

Implements MModelProtocolInterface.

virtual ProfileModel& Model::profileModel ( ) const
virtual

method for getting profile-specific datamodel

Implements MModelProtocolInterface.

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
virtual SearchModel* Model::searchModel ( ) const
virtual

method for getting the full text search datamodel

Implements MModelProtocolInterface.

void Model::timerEvent ( QTimerEvent *  event)
protected

for periodical stuff inside datamodel

virtual void Model::unlock ( )
virtual

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

Implements MModelProtocolInterface.

Member Data Documentation

BinaryFileModel* Model::iBinaryFileModel
private

Random binary blob storage

ClassifiedAdsModel* Model::iCaModel
private

Classified ads storage

QList<Connection *>* Model::iConnections
private
ContentEncryptionModel* Model::iContentEncryptionModel
private

cryptographic animal

MController* Model::iController
private
QSqlDatabase Model::iDb
private

actual storage here

QMutex* Model::iMutex
private

this mutex protects access to this datamodel

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

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

NodeModel* Model::iNodeModel
private

Network connections currently open datamodel about our peers

PrivMessageModel* Model::iPrivMsgModel
private

storage of private messages

ProfileCommentModel* Model::iProfileCommentModel
private

comments data storage

ProfileModel* Model::iProfileModel
private

Profile data storage

SearchModel* Model::iSearchModel
private

full text search model part

int Model::iTimerId
private

id of our periodical timer


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