diff -r 000000000000 -r fa475d6462b2 bookmarksengine/bookmarksclient/src/bookmarkclient.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bookmarksengine/bookmarksclient/src/bookmarkclient.cpp Tue May 04 12:39:38 2010 +0300 @@ -0,0 +1,351 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include +#include +#include +#include + +class BookmarksClientSidePrivate + { +BOOKMARKSCLIENT_PUBLIC(BookmarksClientSide) + +public: + ~BookmarksClientSidePrivate(); + QString m_clientName; + int m_clientuid; + bool m_isConnected; + int m_error; + WRT::ServiceFwIPC* m_IpcSession; + int dispatchServerMessagestoClient(int msgType, QString title); + }; + +/**============================================================== + * Description: Constructor of BookmarksClientSidePrivate + * Author: Chandrashekar.V + * EmpId: 10289207 + ================================================================*/ +BookmarksClientSidePrivate::~BookmarksClientSidePrivate() + { + if (m_IpcSession) + { + m_IpcSession->disconnect(); + delete m_IpcSession; + m_IpcSession = NULL; + } + + } + +/**============================================================== + * Description: Constructor of BookmarksClientSide + * Author: Chandrashekar.V + * EmpId: 10289207 + ================================================================*/ +BookmarksClientSide::BookmarksClientSide() + { + BOOKMARKSCLIENT_INITIALIZE(BookmarksClientSide); + + priv->m_IpcSession = new WRT::ServiceFwIPC(this); + + } + +/**============================================================== + * Description: Connects to the bookmark server + * Author: Chandrashekar.V + * EmpId: 10289207 + ================================================================*/ +int BookmarksClientSide::connectToServer() + { + BOOKMARKSCLIENT_PRIVATEPTR(BookmarksClientSide); + bool connected = false; + if (priv->m_IpcSession) + { + int retry(5); + for (;;) + { + connected = priv->m_IpcSession->connect(BOOKMARKSENGINESERVER); + if (connected) + { + break; + } + else + { + if (!priv->m_IpcSession->startServer(BOOKMARKSENGINESERVER, + BOOKMARKSENGINESERVEREXE)) + { // start server failed + qDebug() << "Failed to Start the BOOKMARK Server."; + break; + } + + } + if (0 == --retry) + { + break; + } + } + } + if (connected) + { + + connect(priv->m_IpcSession, SIGNAL(readyRead()), this, + SLOT(handleServerResponse())); + return ErrNone; + } + else + { + return ErrGeneral; + } + } + +/**============================================================== +* Description: Disconnects the client +* Author: Chandrashekar.V +* EmpId: 10289207 +================================================================*/ +void BookmarksClientSide::closeServer() + { + BOOKMARKSCLIENT_PRIVATEPTR(BookmarksClientSide); + if (priv->m_IpcSession) + { + priv->m_IpcSession->disconnect(); + } + } + +/**============================================================== + * Description: Destrcutor of the BookmarksClientSide + * Author: Chandrashekar.V + * EmpId: 10289207 + ================================================================*/ +BookmarksClientSide::~BookmarksClientSide() + { + } + +/**============================================================== + * Description: Sends add bookmark request to the server + * Author: Chandrashekar.V + * EmpId: 10289207 + ================================================================*/ +int BookmarksClientSide::AddBookmark( + BookmarkLeaf* BookmarkContent) + { + BOOKMARKSCLIENT_PRIVATEPTR(BookmarksClientSide); + QString data; + bool result = false; + data.append(BookmarkContent->getTitle()); + data.append(BOOKMARKSENGINESEPARATOR); + data.append(BookmarkContent->getUrl()); + data.append(BOOKMARKSENGINESEPARATOR); + data.append(BookmarkContent->getDate().toString("dd.MM.yyyy")); + data.append(BOOKMARKSENGINESEPARATOR); + data.append(BookmarkContent->getTag()); + QString requestType; + requestType.append(QString::number(EAddBookmark)); + if (priv->m_IpcSession) + { + result = priv->m_IpcSession->sendSync(requestType, data.toAscii()); + } + + if (result == true) + { + return ErrNone; + } + else + { + return ErrGeneral; + } + } + +/**============================================================== + * Description: Sends add fetchbookmark request to the server + * Author: Chandrashekar.V + * EmpId: 10289207 + ================================================================*/ +BookmarkLeaf* BookmarksClientSide::FetchBookmark( + QString title) + { + BOOKMARKSCLIENT_PRIVATEPTR(BookmarksClientSide); + BookmarkLeaf *node = NULL; + QString data; + data.append(title); + QString requestType; + requestType.append(QString::number(EFetchBookmark)); + if (priv->m_IpcSession) + { + priv->m_IpcSession->sendSync(requestType, data.toAscii()); + QByteArray msg = priv->m_IpcSession->readAll(); + QString serverMsg; + serverMsg = msg.data(); + QStringList list = serverMsg.split(BOOKMARKSENGINESEPARATOR); + + QString title = list[0]; + QString url = list[1]; + QString strdate = list[2]; + QString tags = list[3]; + QDate adate = QDate::fromString(strdate, "dd.MM.yyyy"); + + node = new BookmarkLeaf(); + node->setTitle(title); + node->setUrl(url); + node->setDate(adate); + node->setTag(tags); + } + return node; + } + +/**============================================================== + * Description: Sends add deletebookmark request to the server + * Author: Chandrashekar.V + * EmpId: 10289207 + ================================================================*/ +int BookmarksClientSide::DeleteBookmark( + QString title) + { + BOOKMARKSCLIENT_PRIVATEPTR(BookmarksClientSide); + QString data; + bool result = false; + data.append(title); + QString requestType; + requestType.append(QString::number(EDeleteBookmark)); + if (priv->m_IpcSession) + { + result = priv->m_IpcSession->sendSync(requestType, data.toAscii()); + } + if (result == true) + { + return ErrNone; + } + else + { + return ErrGeneral; + } + + } + +/**============================================================== + * Description: gets session Id of the client + * Author: Chandrashekar.V + * EmpId: 10289207 + ================================================================*/ +int BookmarksClientSide::getSessionId( + int& BookmarkId) + { + BOOKMARKSCLIENT_PRIVATEPTR(BookmarksClientSide); + bool result = false; + if (priv->m_IpcSession) + { + result = priv->m_IpcSession->getSessionId(BookmarkId); + } + if (result == true) + { + return ErrNone; + } + else + { + return ErrGeneral; + } + } + +/**============================================================== + * Description: Sends add fetchAllbookmark request to the server + * Author: Chandrashekar.V + * EmpId: 10289207 + ================================================================*/ +QList BookmarksClientSide::FetchAllBookmarks() + { + BOOKMARKSCLIENT_PRIVATEPTR(BookmarksClientSide); + QList nodeslist; + QString data; + data.append(NULL); + QString requestType; + requestType.append(QString::number(EFetchAllBookmark)); + + if (priv->m_IpcSession) + { + priv->m_IpcSession->sendSync(requestType, data.toAscii()); + QByteArray msg = priv->m_IpcSession->readAll(); + QString serverMsg; + serverMsg = msg.data(); + QStringList list = serverMsg.split(BOOKMARKSENGINESEPARATOR); + int count = list.count() / 4; + int i = 0; + while (count--) + { + QString title = list[i++]; + QString url = list[i++]; + QString strdate = list[i++]; + QDate adate = QDate::fromString(strdate, "dd.MM.yyyy"); + QString tags = list[i++]; + BookmarkLeaf* node = new BookmarkLeaf(); + node->setTitle(title); + node->setUrl(url); + node->setDate(adate); + node->setTag(tags); + + nodeslist.append(node); + } + } + return nodeslist; + + } + +/**============================================================== + * Description: handles server responses + * Author: Chandrashekar.V + * EmpId: 10289207 + ================================================================*/ +void BookmarksClientSide::handleServerResponse() + { + BOOKMARKSCLIENT_PRIVATEPTR(BookmarksClientSide); + qDebug() << " handling server response" << '\n'; + QByteArray msg; + msg = priv->m_IpcSession->readAll(); + QString serverMsg; + serverMsg = msg.data(); + qDebug() << " Message is " << serverMsg << '\n'; + QStringList list1 = serverMsg.split(BOOKMARKSENGINESEPARATOR); + int msgType = list1[0].toLocal8Bit().toInt(); + QString title = list1[1]; + int res=priv->dispatchServerMessagestoClient(msgType, title); + + } + +/**============================================================== + * Description: Sends server response notifications to the UI + * Author: Chandrashekar.V + * EmpId: 10289207 + ================================================================*/ +int BookmarksClientSidePrivate::dispatchServerMessagestoClient(int msgType, + QString title) + { + BOOKMARKSCLIENT_PUBLICPTR(BookmarksClientSide); + switch (msgType) + { + case EServerMsgBookmarkDeleted: + emit pub->BookmarkDeleted(title); + break; + case EServerMsgBookmarkAdded: + emit pub->BookmarkAdded(title); + break; + default: + break; + } + return ErrNone; + } +