filesyncsource.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 226 行
CPP
226 行
/*
* Funambol is a mobile platform developed by Funambol, Inc.
* Copyright (C) 2003 - 2007 Funambol, Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program; if not, see http://www.gnu.org/licenses or write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA.
*
* You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
* 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by Funambol" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by Funambol".
*/
#include "examples/TestSyncSource.h"
#include "base/util/utils.h"
#include "base/Log.h"
static int all = -1;
static int cnew = -1;
static int cupdated = -1;
static int cdeleted = -1;
ArrayList items;
ArrayList newItems;
ArrayList updatedItems;
ArrayList deletedItems;
int setAllItems() {
SyncItem item;
wchar_t name[64];
wchar_t data[128];
for (int i = 0; i < 4; ++i) {
wsprintf(name, TEXT("%s%d"), TEXT("item"), i);
wsprintf(data, TEXT("This is item %d"), i);
item.setKey(name);
item.setData(data , (wcslen(data) + 1)*sizeof(wchar_t));
items.add(item);
}
return 0;
}
int setAllItemsEmpty() {
return 0;
}
int setModifiedItems() {
SyncItem item;
for (int i = 0; i < 4; ++i) {
switch (i) {
case 0:
item.setKey(TEXT("item5"));
item.setData(TEXT("This is a new item Four") , 24*sizeof(wchar_t));
newItems.add(item);
break;
case 1:
item.setKey(TEXT("item1"));
item.setData(TEXT("This is the updated item One") , 29*sizeof(wchar_t));
updatedItems.add(item);
break;
case 2:
item.setKey(TEXT("item3"));
item.setData(TEXT("This is the updated item Three"), 31*sizeof(wchar_t));
updatedItems.add(item);
break;
case 3:
item.setKey(TEXT("item4"));
deletedItems.add(item);
break;
}
}
return 0;
}
int setModifiedItemsEmpty() {
return 0;
}
TestSyncSource::TestSyncSource(const wchar_t* name) : SyncSource(name) {
}
TestSyncSource::~TestSyncSource() {
}
/*
* Return the first SyncItem of all. It is used in case of slow or refresh sync
* and retrieve the entire data source content.
*/
SyncItem* TestSyncSource::getFirstItem() {
setAllItems();
if (items.size() == 0) {
return NULL;
}
all = 0;
return (SyncItem*)items[all]->clone();
}
/*
* Return the next SyncItem of all. It is used in case of slow or refresh sync
* and retrieve the entire data source content.
*/
SyncItem* TestSyncSource::getNextItem() {
all++;
if (all == items.size()) {
return NULL;
}
return (SyncItem*)items.get(all)->clone();
}
SyncItem* TestSyncSource::getFirstNewItem() {
setModifiedItems();
if (newItems.size() == 0) {
return NULL;
}
cnew = 0;
return (SyncItem*)newItems.get(cnew);
}
SyncItem* TestSyncSource::getNextNewItem() {
cnew++;
if (cnew == newItems.size()) {
return NULL;
}
return (SyncItem*)newItems.get(cnew);
}
SyncItem* TestSyncSource::getFirstUpdatedItem() {
if (updatedItems.size() == 0) {
return NULL;
}
cupdated = 0;
return (SyncItem*)updatedItems.get(cupdated);
}
SyncItem* TestSyncSource::getNextUpdatedItem() {
cupdated++;
if (cupdated == updatedItems.size()) {
return NULL;
}
return (SyncItem*)updatedItems.get(cupdated);
}
SyncItem* TestSyncSource::getFirstDeletedItem() {
if (deletedItems.size() == 0) {
return NULL;
}
cdeleted = 0;
return (SyncItem*)deletedItems.get(cdeleted);
}
SyncItem* TestSyncSource::getNextDeletedItem() {
cdeleted++;
if (cdeleted == deletedItems.size()) {
return NULL;
}
return (SyncItem*)deletedItems.get(cdeleted);
}
void TestSyncSource::setItemStatus(const wchar_t* key, int status) {
wchar_t tmp[256];
wsprintf(tmp, TEXT("key: %s, status: %i"), key, status);
LOG.debug(tmp);
}
int TestSyncSource::addItem(SyncItem& item) {
wchar_t tmp[256];
wsprintf(tmp, TEXT("added item: %s"), item.getKey());
item.setKey(TEXT("LUIDAssigned"));
LOG.debug(tmp);
return 200;
}
int TestSyncSource::updateItem(SyncItem& item) {
wchar_t tmp[256];
wsprintf(tmp, TEXT("updated item: %s"), item.getKey());
LOG.debug(tmp);
return 200;
}
int TestSyncSource::deleteItem(SyncItem& item) {
wchar_t tmp[256];
wsprintf(tmp, TEXT("deleted item: %s"), item.getKey());
LOG.debug(tmp);
return 200;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?