contentstorage/caclient/src/caservice.cpp
changeset 93 82b66994846c
parent 92 782e3408c2ab
child 94 dbb8300717f7
equal deleted inserted replaced
92:782e3408c2ab 93:82b66994846c
    27 #include "canotifier.h"
    27 #include "canotifier.h"
    28 #include "canotifier_p.h"
    28 #include "canotifier_p.h"
    29 #include "cadefs.h"
    29 #include "cadefs.h"
    30 
    30 
    31 #include "caclientproxy.h"
    31 #include "caclientproxy.h"
       
    32 #include "caclientnotifierproxy.h"
    32 #include "caobjectadapter.h"
    33 #include "caobjectadapter.h"
    33 #include "caclienttest_global.h"
    34 #include "caclienttest_global.h"
    34 
    35 
    35 // ======== MEMBER FUNCTIONS ========
    36 // ======== MEMBER FUNCTIONS ========
    36 
    37 
    49  \endcode
    50  \endcode
    50 
    51 
    51  For every operations on data is used always one instantiation of a class.
    52  For every operations on data is used always one instantiation of a class.
    52  Below are examples how to create data and work on those ones.
    53  Below are examples how to create data and work on those ones.
    53 
    54 
       
    55  */
       
    56 
       
    57 /*!
       
    58  \var CaServicePrivate::m_q
       
    59  Points to the CaService instance that uses this private implementation.
       
    60  */
       
    61 
       
    62 /*!
       
    63  \var CaServicePrivate::mProxy
       
    64  Proxy to communicate with Symbian server.
       
    65  */
       
    66 
       
    67 /*!
       
    68  \var CaServicePrivate::mErrorCode
       
    69  code of error caused by last operation.
       
    70  */
       
    71 
       
    72 /*!
       
    73  \var CaServicePrivate::mNotifierProxy
       
    74  Proxy to client notifier.
    54  */
    75  */
    55 
    76 
    56 // Initialization of a static member variable.
    77 // Initialization of a static member variable.
    57 QWeakPointer<CaService> CaService::m_instance = QWeakPointer<CaService>();
    78 QWeakPointer<CaService> CaService::m_instance = QWeakPointer<CaService>();
    58 /*!
    79 /*!
   572     }
   593     }
   573     return removeEntriesFromGroup(group.id(), idList);
   594     return removeEntriesFromGroup(group.id(), idList);
   574 }
   595 }
   575 
   596 
   576 /*!
   597 /*!
   577  Performs touch operation on entry.
       
   578  \param entry to be touched
       
   579  \retval boolean with result of operation
       
   580  */
       
   581 bool CaServicePrivate::touch(const CaEntry &entry)
       
   582 {
       
   583     qDebug() << "CaServicePrivate::touch" << "entryId: " << entry.id();
       
   584 
       
   585     mErrorCode = mProxy->touch(entry);
       
   586 
       
   587     qDebug() << "CaServicePrivate::touch mErrorCode:" << mErrorCode;
       
   588 
       
   589     return (mErrorCode == NoErrorCode);
       
   590 }
       
   591 
       
   592 /*!
       
   593  Place entries in a given group at the end.
   598  Place entries in a given group at the end.
   594  \param groupId id of a group.
   599  \param groupId id of a group.
   595  \param entryId id of entry to append.
   600  \param entryId id of entry to append.
   596  \retval true if operation was successful.
   601  \retval true if operation was successful.
   597 
   602 
   931 /*!
   936 /*!
   932  Constructor
   937  Constructor
   933  \param servicePublic pointer to public service
   938  \param servicePublic pointer to public service
   934  */
   939  */
   935 CaServicePrivate::CaServicePrivate(CaService *servicePublic) :
   940 CaServicePrivate::CaServicePrivate(CaService *servicePublic) :
   936     m_q(servicePublic), mProxy(new CaClientProxy)
   941     m_q(servicePublic), mProxy(new CaClientProxy), 
       
   942     mNotifierProxy(NULL)
   937 {
   943 {
   938     const ErrorCode connectionResult = mProxy->connect();
   944     const ErrorCode connectionResult = mProxy->connect();
   939 
   945 
   940     USE_QWARNING_IF(connectionResult)
   946     USE_QWARNING_IF(connectionResult)
   941             << "CaServicePrivate::CaServicePrivate - unable to connect proxy";
   947             << "CaServicePrivate::CaServicePrivate - unable to connect proxy";
   947  destructor
   953  destructor
   948  */
   954  */
   949 CaServicePrivate::~CaServicePrivate()
   955 CaServicePrivate::~CaServicePrivate()
   950 {
   956 {
   951     delete mProxy;
   957     delete mProxy;
       
   958     delete mNotifierProxy;
   952 }
   959 }
   953 
   960 
   954 /*!
   961 /*!
   955  Search for entries.
   962  Search for entries.
   956  \param entryIdList list of entry ids
   963  \param entryIdList list of entry ids
   970     // figure out whether all entries have been retrieved and
   977     // figure out whether all entries have been retrieved and
   971     // store the operation status
   978     // store the operation status
   972     if (mErrorCode == NoErrorCode
   979     if (mErrorCode == NoErrorCode
   973             && entryIdList.count() != resultList.count()) {
   980             && entryIdList.count() != resultList.count()) {
   974         mErrorCode = NotFoundErrorCode;
   981         mErrorCode = NotFoundErrorCode;
       
   982     }//one line with else if
       
   983     else if (mErrorCode == ServerTerminated) {
       
   984         if (!mProxy->connect()) {
       
   985             if (mNotifierProxy) {
       
   986                 mNotifierProxy->connectSessions();
       
   987             }
       
   988             resultList.clear();
       
   989             mErrorCode = mProxy->getData(entryIdList, resultList);
       
   990         }
   975     }
   991     }
   976     CACLIENTTEST_FUNC_EXIT("CaServicePrivate::getEntries");
   992     CACLIENTTEST_FUNC_EXIT("CaServicePrivate::getEntries");
   977 
   993 
   978     qDebug() << "CaServicePrivate::getEntries mErrorCode:"
   994     qDebug() << "CaServicePrivate::getEntries mErrorCode:"
   979              << mErrorCode;
   995              << mErrorCode;
   989 QList< QSharedPointer<CaEntry> > CaServicePrivate::getEntries(const CaQuery &query) const
  1005 QList< QSharedPointer<CaEntry> > CaServicePrivate::getEntries(const CaQuery &query) const
   990 {
  1006 {
   991     QList< QSharedPointer<CaEntry> > resultList;
  1007     QList< QSharedPointer<CaEntry> > resultList;
   992 
  1008 
   993     mErrorCode = mProxy->getData(query, resultList);
  1009     mErrorCode = mProxy->getData(query, resultList);
   994 
  1010     if (mErrorCode == ServerTerminated) {
       
  1011         if (!mProxy->connect()) {
       
  1012             if (mNotifierProxy) {
       
  1013                 mNotifierProxy->connectSessions();
       
  1014             }
       
  1015             resultList.clear();
       
  1016             mErrorCode = mProxy->getData(query, resultList);
       
  1017         }
       
  1018     }
   995     qDebug() << "CaServicePrivate::getEntries mErrorCode:" << mErrorCode;
  1019     qDebug() << "CaServicePrivate::getEntries mErrorCode:" << mErrorCode;
   996 
  1020 
   997     return resultList;
  1021     return resultList;
   998 }
  1022 }
   999 
  1023 
  1006 {
  1030 {
  1007     CACLIENTTEST_FUNC_ENTRY("CaItemModelList::getEntryIds");
  1031     CACLIENTTEST_FUNC_ENTRY("CaItemModelList::getEntryIds");
  1008 
  1032 
  1009     QList<int> resultList;
  1033     QList<int> resultList;
  1010     mErrorCode = mProxy->getEntryIds(query, resultList);
  1034     mErrorCode = mProxy->getEntryIds(query, resultList);
       
  1035     if (mErrorCode == ServerTerminated) {
       
  1036         if (!mProxy->connect()) {
       
  1037             if (mNotifierProxy) {
       
  1038                 mNotifierProxy->connectSessions();
       
  1039             }
       
  1040             resultList.clear();
       
  1041             mErrorCode = mProxy->getEntryIds(query, resultList);
       
  1042         }
       
  1043     }
  1011     CACLIENTTEST_FUNC_EXIT("CaItemModelList::getEntryIds");
  1044     CACLIENTTEST_FUNC_EXIT("CaItemModelList::getEntryIds");
  1012     qDebug() << "CaServicePrivate::getEntryIds mErrorCode:" << mErrorCode;
  1045     qDebug() << "CaServicePrivate::getEntryIds mErrorCode:" << mErrorCode;
  1013     return resultList;
  1046     return resultList;
  1014 }
  1047 }
  1015 
  1048 
  1033     const int nonExistingObjectId = 0;
  1066     const int nonExistingObjectId = 0;
  1034     CaObjectAdapter::setId(*entryClone, nonExistingObjectId);
  1067     CaObjectAdapter::setId(*entryClone, nonExistingObjectId);
  1035 
  1068 
  1036     addDataResult =
  1069     addDataResult =
  1037         mProxy->addData(*entryClone, *newEntry);
  1070         mProxy->addData(*entryClone, *newEntry);
       
  1071     if (addDataResult == ServerTerminated) {
       
  1072         if (!mProxy->connect()) {
       
  1073             if (mNotifierProxy) {
       
  1074                 mNotifierProxy->connectSessions();
       
  1075             }
       
  1076             addDataResult =
       
  1077                 mProxy->addData(*entryClone, *newEntry);
       
  1078         }
       
  1079     }    
  1038 
  1080 
  1039     // return empty pointer if nothing was added
  1081     // return empty pointer if nothing was added
  1040     if (addDataResult != NoErrorCode) {
  1082     if (addDataResult != NoErrorCode) {
  1041         newEntry.clear();
  1083         newEntry.clear();
  1042     }
  1084     }
  1049 
  1091 
  1050     return newEntry;
  1092     return newEntry;
  1051 }
  1093 }
  1052 
  1094 
  1053 /*!
  1095 /*!
       
  1096  Performs touch operation on entry.
       
  1097  \param entry to be touched
       
  1098  \retval boolean with result of operation
       
  1099  */
       
  1100 bool CaServicePrivate::touch(const CaEntry &entry)
       
  1101 {
       
  1102     qDebug() << "CaServicePrivate::touch" << "entryId: " << entry.id();
       
  1103 
       
  1104     mErrorCode = mProxy->touch(entry);
       
  1105     if (mErrorCode == ServerTerminated) {
       
  1106         if (!mProxy->connect()) {
       
  1107             if (mNotifierProxy) {
       
  1108                 mNotifierProxy->connectSessions();
       
  1109             }
       
  1110             mErrorCode = mProxy->touch(entry);
       
  1111         }
       
  1112     }
       
  1113 
       
  1114     qDebug() << "CaServicePrivate::touch mErrorCode:" << mErrorCode;
       
  1115 
       
  1116     return (mErrorCode == NoErrorCode);
       
  1117 }
       
  1118 
       
  1119 /*!
  1054  Update entry.
  1120  Update entry.
  1055  \param entry entry const reference of entry to update
  1121  \param entry entry const reference of entry to update
  1056  \retval true if operation was successful
  1122  \retval true if operation was successful
  1057  */
  1123  */
  1058 bool CaServicePrivate::updateEntry(const CaEntry &entry)
  1124 bool CaServicePrivate::updateEntry(const CaEntry &entry)
  1067     if (entry.id() != 0) {
  1133     if (entry.id() != 0) {
  1068         try {
  1134         try {
  1069             QScopedPointer<CaEntry> updatedEntry(new CaEntry(entry.role()));
  1135             QScopedPointer<CaEntry> updatedEntry(new CaEntry(entry.role()));
  1070 
  1136 
  1071             updateEntryResult = mProxy->addData(entry, *updatedEntry);
  1137             updateEntryResult = mProxy->addData(entry, *updatedEntry);
       
  1138             if (updateEntryResult == ServerTerminated) {
       
  1139                 if (!mProxy->connect()) {
       
  1140                     if (mNotifierProxy) {
       
  1141                         mNotifierProxy->connectSessions();
       
  1142                     }
       
  1143                     updateEntryResult = mProxy->addData(entry, *updatedEntry);
       
  1144                 }
       
  1145             }
  1072 
  1146 
  1073         } catch (const std::bad_alloc &) {
  1147         } catch (const std::bad_alloc &) {
  1074             updateEntryResult = OutOfMemoryErrorCode;
  1148             updateEntryResult = OutOfMemoryErrorCode;
  1075         }
  1149         }
  1076     }
  1150     }
  1095              << "entryIdList: " << entryIdList;
  1169              << "entryIdList: " << entryIdList;
  1096 
  1170 
  1097     CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::removeEntries");
  1171     CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::removeEntries");
  1098 
  1172 
  1099     mErrorCode = mProxy->removeData(entryIdList);
  1173     mErrorCode = mProxy->removeData(entryIdList);
       
  1174     if (mErrorCode == ServerTerminated) {
       
  1175         if (!mProxy->connect()) {
       
  1176             if (mNotifierProxy) {
       
  1177                 mNotifierProxy->connectSessions();
       
  1178             }
       
  1179             mErrorCode = mProxy->removeData(entryIdList);
       
  1180         }
       
  1181     }
  1100 
  1182 
  1101     qDebug() << "CaServicePrivate::removeEntries mErrorCode:" << mErrorCode;
  1183     qDebug() << "CaServicePrivate::removeEntries mErrorCode:" << mErrorCode;
  1102 
  1184 
  1103     CACLIENTTEST_FUNC_EXIT("CaServicePrivate::removeEntries");
  1185     CACLIENTTEST_FUNC_EXIT("CaServicePrivate::removeEntries");
  1104 
  1186 
  1121              << "groupId: " << groupId << " beforeEntryId: " << beforeEntryId
  1203              << "groupId: " << groupId << " beforeEntryId: " << beforeEntryId
  1122              << "entryIdList: " << entryIdList;
  1204              << "entryIdList: " << entryIdList;
  1123 
  1205 
  1124     CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::insertEntriesIntoGroup");
  1206     CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::insertEntriesIntoGroup");
  1125 
  1207 
  1126     mErrorCode = mProxy->insertEntriesIntoGroup(groupId, entryIdList, beforeEntryId);
  1208     mErrorCode = mProxy->insertEntriesIntoGroup(groupId, 
  1127 
  1209             entryIdList, beforeEntryId);
       
  1210     if (mErrorCode == ServerTerminated) {
       
  1211         if (!mProxy->connect()) {
       
  1212             if (mNotifierProxy) {
       
  1213                 mNotifierProxy->connectSessions();
       
  1214             }
       
  1215             mErrorCode = mProxy->insertEntriesIntoGroup(groupId, 
       
  1216                     entryIdList, beforeEntryId);
       
  1217         }
       
  1218     }
  1128     qDebug() << "CaServicePrivate::insertEntriesIntoGroup mErrorCode:"
  1219     qDebug() << "CaServicePrivate::insertEntriesIntoGroup mErrorCode:"
  1129              << mErrorCode;
  1220              << mErrorCode;
  1130 
  1221 
  1131     CACLIENTTEST_FUNC_EXIT("CaServicePrivate::insertEntriesIntoGroup");
  1222     CACLIENTTEST_FUNC_EXIT("CaServicePrivate::insertEntriesIntoGroup");
  1132 
  1223 
  1148              << "groupId: " << groupId << "entryIdList" << entryIdList;
  1239              << "groupId: " << groupId << "entryIdList" << entryIdList;
  1149 
  1240 
  1150     CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::removeEntriesFromGroup");
  1241     CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::removeEntriesFromGroup");
  1151 
  1242 
  1152     mErrorCode = mProxy->removeEntriesFromGroup(groupId, entryIdList);
  1243     mErrorCode = mProxy->removeEntriesFromGroup(groupId, entryIdList);
       
  1244     if (mErrorCode == ServerTerminated) {
       
  1245         if (!mProxy->connect()) {
       
  1246             if (mNotifierProxy) {
       
  1247                 mNotifierProxy->connectSessions();
       
  1248             }
       
  1249             mErrorCode = mProxy->removeEntriesFromGroup(groupId, entryIdList);
       
  1250         }
       
  1251     }
  1153 
  1252 
  1154     qDebug() << "CaServicePrivate::removeEntriesFromGroup mErrorCode:"
  1253     qDebug() << "CaServicePrivate::removeEntriesFromGroup mErrorCode:"
  1155              << mErrorCode;
  1254              << mErrorCode;
  1156 
  1255 
  1157     CACLIENTTEST_FUNC_EXIT("CaServicePrivate::removeEntriesFromGroup");
  1256     CACLIENTTEST_FUNC_EXIT("CaServicePrivate::removeEntriesFromGroup");
  1248  \param CaNotifierFilter which is used be new notifier
  1347  \param CaNotifierFilter which is used be new notifier
  1249  \retval pointer to new Notifier
  1348  \retval pointer to new Notifier
  1250  */
  1349  */
  1251 CaNotifier *CaServicePrivate::createNotifier(const CaNotifierFilter &filter)
  1350 CaNotifier *CaServicePrivate::createNotifier(const CaNotifierFilter &filter)
  1252 {
  1351 {
  1253     return new CaNotifier(new CaNotifierPrivate(filter));
  1352     if (!mNotifierProxy) {
       
  1353         mNotifierProxy = new CaClientNotifierProxy();
       
  1354     }
       
  1355     return new CaNotifier(new CaNotifierPrivate(filter, mNotifierProxy));
  1254 }
  1356 }
  1255 
  1357 
  1256 /*!
  1358 /*!
  1257     Set new order of collection's items set by user.
  1359     Set new order of collection's items set by user.
  1258     \param groupId Group id.
  1360     \param groupId Group id.
  1263 bool CaServicePrivate::customSort(int groupId, QList<int> &entryIdList)
  1365 bool CaServicePrivate::customSort(int groupId, QList<int> &entryIdList)
  1264 {
  1366 {
  1265     CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::customSort");
  1367     CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::customSort");
  1266 
  1368 
  1267     mErrorCode = mProxy->customSort(entryIdList, groupId);
  1369     mErrorCode = mProxy->customSort(entryIdList, groupId);
  1268 
  1370     if (mErrorCode == ServerTerminated) {
       
  1371         if (!mProxy->connect()) {
       
  1372             if (mNotifierProxy) {
       
  1373                 mNotifierProxy->connectSessions();
       
  1374             }
       
  1375             mErrorCode = mProxy->customSort(entryIdList, groupId);
       
  1376         }
       
  1377     }
  1269     CACLIENTTEST_FUNC_EXIT("CaServicePrivate::customSort");
  1378     CACLIENTTEST_FUNC_EXIT("CaServicePrivate::customSort");
  1270 
  1379 
  1271     return (mErrorCode == NoErrorCode);
  1380     return (mErrorCode == NoErrorCode);
  1272 }
  1381 }
  1273 
  1382