//add/update/delete item from server. Returns SyncML Status code
//add needs to set the correct local key here.
int WebOsCalendarSyncSource::addItem(SyncItem &item)
{
	int ret = STC_COMMAND_FAILED;
	LOG.info("addItem called with type %s and data %s.",item.getDataType(),item.getData());

	LOG.info("Calling createEvent.");
	std::vector<WString> result = BlockingServiceCall("createEvent",(WCHAR*)item.getData());
	if(result.empty())
	{
		LOG.error("Add event %s did not work.",item.getData());
		ret = STC_COMMAND_FAILED;
	}
	else
	{
		LOG.debug("Add event was successful, received: %s.",result[0].c_str());
		item.setKey(result[0].c_str());
		ret = STC_OK;
	}

	if (isErrorCode(ret))
	{
		report->setLastErrorCode(ERR_ITEM_ERROR);
	    report->setLastErrorMsg(ERRMSG_ITEM_ERROR);
	    report->setState(SOURCE_ERROR);
	    LOG.debug("Error adding item: %s", item.getKey());
	}

	return ret;
}
SyncItem* WebOsCalendarSyncSource::getNextUpdatedItem()
{
	LOG.info("=========== GET NEXT UPDATED ITEM CALLED ==================");
	if(!mGetChangesCalled)
	{
		getChanges();
	}

	if(!mEvents.empty())
	{
		//take first event and convert into item of correct type.
		std::pair<WString,WString>& e = mEvents.front();
		SyncItem* item = new SyncItem();
		item->setDataType(TEXT("text/calendar"));
		item->setData(e.second.c_str(),e.second.length());
		item->setKey(e.first.c_str());
		LOG.debug("Received %s from JS.",e.second.c_str());
		mEvents.pop_front();
		return item;
	}
	else
		return NULL;


	return NULL;
}
SyncItem* WebOsCalendarSyncSource::getNextDeletedItem()
{
	LOG.info("=========== GET NEXT DELETED ITEM CALLED ==================");
	if(!mGetChangesCalled)
	{
		getChanges();
	}

	std::vector<WString> result = BlockingServiceCall("getDeletedEvent",TEXT(""));
	if(result.empty())
	{
		LOG.error("GetDeleted failed.");
	}
	else
	{
		if(result.front() != "finished")
		{
			SyncItem* item = new SyncItem();
			item->setDataType(TEXT("text/calendar"));
			//item->setData(e.second.c_str(),e.second.length()); no data for deleted items..
			item->setKey(result.front().c_str());
			LOG.debug("Added %s as deleted.",result.front().c_str());
			return item;
		}
	}

	return NULL;
}
Ejemplo n.º 4
0
int LOSyncSource::addItem(SyncItem& item) {

    WCHAR luid[128];
    wsprintf(luid, TEXT("%s-luid"), item.getKey());
    item.setKey(luid);
    return 200;
}
SyncItem* WebOsCalendarSyncSource::getNextItem()
{
	LOG.info("========== GET NEXT ITEM CALLED ===========");
	if(mEvents.empty())
	{
		//no items anymore, need to get more. If that doesn't work, there are no more items.
		getMoreItems();
		if(mEvents.empty())
		{
			LOG.info("======= NO MORE ELEMENTS ==========");
			return NULL;
		}
	}

	if(!mEvents.empty())
	{
		//take first event and convert into item of correct type.
		std::pair<WString,WString>& e = mEvents.front();
		SyncItem* item = new SyncItem();
		item->setDataType(TEXT("text/calendar"));
		item->setData(e.second.c_str(),e.second.length());
		item->setKey(e.first.c_str());
		LOG.debug("Received %s from JS with key %s.",e.second.c_str(),e.first.c_str());
		mEvents.pop_front();
		return item;
	}
	else
		return NULL;
}
Ejemplo n.º 6
0
int setModifiedItems() {

    SyncItem item;
                StringBuffer val; 
                for (int ii = 0; ii<1; ii++){
                    val.append("This is the updated item one");
                }

    for (int i = 0; i < 4; ++i) {

        switch (i) {

            case 0:
                item.setKey(TEXT("item5"));
                item.setData(val.c_str()  , (val.length())*sizeof(char));
                newItems.add(item);
                break;

            case 1:
                item.setKey(TEXT("item1"));
                item.setData(val.c_str()  , (val.length())*sizeof(char));
                updatedItems.add(item);
                break;

            case 2:
                item.setKey(TEXT("item3"));
                item.setData(val.c_str()  , (val.length())*sizeof(char));
                updatedItems.add(item);
                break;

            case 3:

                item.setKey(TEXT("item4"));
                deletedItems.add(item);
                break;

        }
    }

    return 0;
}
Ejemplo n.º 7
0
int AbstractSyncSource::addItem(SyncItem& item)
{
    QByteArray data((char *)item.getData());
    QUniqueId id = m_model->addRecord(data, QPimSource(), m_type);
    item.setKey(id.toString().toAscii().data());
    m_model->updateRecord(id, data, m_type);
    //qDebug() << "AbstractSyncSource::addItem() " << toString(item) << "Id:" << id.toString();
    if (!id.isNull())
        return 201;    //ok, the requested item was added
    else
        return 500;    //failed, the recipient encountered an error
}
Ejemplo n.º 8
0
SyncItem *AbstractSyncSource::createSyncItem(const QUniqueId &id, bool wantData, SyncState state) const
{
    //qDebug() << "AbstractSyncSource::createSyncItem(" << id.toString() << "," << wantData << "," << state << ")";
    QByteArray record = m_model->record(id, m_type);
    SyncItem *item = new SyncItem();
    QString key = id.toString();
    item->setKey(key.toAscii().data());
    item->setModificationTime(m_lastSync.toTime_t());
    item->setState(state);
    if (wantData) {
        item->setData(record.data(), record.size() - 1); // have to omit '\0'
        item->setDataType(getConfig().getType());
    }
    //qDebug() << "AbstractSyncSource::createSyncItem()" << toString(*item);
    return item;
}
Ejemplo n.º 9
0
int setAllItems() {

    SyncItem item;
    WCHAR name[64];
    char data[128];

    for (int i = 0; i < 4; ++i) {

        wsprintf(name, TEXT("%s%d"), TEXT("item"), i);
        sprintf(data, "This is item %d", i);

        item.setKey(name);
        item.setData(data  , (strlen(data))*sizeof(char));
        items.add(item);
    }
    return 0;
}
Ejemplo n.º 10
0
bool StorageHandler::addItem( const ItemId& aItemId,
                              StoragePlugin& aPlugin,
                              const SyncItemKey& aLocalKey,
                              const SyncItemKey& aParentKey,
                              const QString& aType,
                              const QString& aFormat,
                              const QString& aVersion,
                              const QString& aData )
{
    FUNCTION_CALL_TRACE;

    LOG_DEBUG( "Processing item for add:" << aItemId.iCmdId <<"/" << aItemId.iItemIndex );

    if( iLargeObject ) {
        LOG_CRITICAL( "Already processing large object, aborting" );
        return false;
    }

    SyncItem* newItem = aPlugin.newItem();

    if( !newItem ) {
        LOG_CRITICAL( "Could not create new item" );
        return false;
    }

    //Setting empty string as we dont have any local key for it.
    newItem->setKey( aLocalKey );
    newItem->setParentKey( aParentKey );
    newItem->setType( aType );
    newItem->setFormat( aFormat );
    newItem->setVersion( aVersion );

    if( !newItem->write( 0, aData.toUtf8() ) ) {
        delete newItem;
        LOG_CRITICAL( "Could not write to item" );
        return false;
    }

    iAddList.insert( aItemId, newItem );
    LOG_DEBUG( "Item queued for addition" );

    return true;
}
Ejemplo n.º 11
0
int TestSyncSource::addItem(SyncItem& item) {
    char* val = toMultibyte( item.getKey() );
    LOG.info("added item: %s", val);
    if(val){
        delete [] val;
        val = 0;
    }
    char *data = new char [item.getDataSize()];
    memcpy(data, item.getData(), item.getDataSize());
    data[item.getDataSize()] = 0;
    LOG.info("Data: %s", data);
    delete [] data;

    WCHAR *luid = new WCHAR[wcslen(item.getKey())+10];
    wsprintf(luid, TEXT("%s-luid"), item.getKey());
    item.setKey(luid);

    return 200;
}
Ejemplo n.º 12
0
bool StorageHandler::startLargeObjectAdd( StoragePlugin& aPlugin,
                                          const QString& aRemoteKey,
                                          const SyncItemKey& aParentKey,
                                          const QString& aType,
                                          const QString& aFormat,
                                          const QString& aVersion,
                                          qint64 aSize )
{
    FUNCTION_CALL_TRACE;

    if( iLargeObject ) {
        LOG_CRITICAL( "Already processing large object, aborting" );
        return false;
    }

    SyncItem* newItem = aPlugin.newItem();

    if( !newItem ) {
        LOG_CRITICAL( "Could not create new item for large object" );
        return false;
    }

    //Setting empty string as we dont have any local key for it.
    newItem->setKey(QString());
    newItem->setParentKey( aParentKey );
    newItem->setType( aType );
    newItem->setFormat( aFormat );
    newItem->setVersion( aVersion );

    iLargeObject = newItem;
    iLargeObjectSize = aSize;
    iLargeObjectKey = aRemoteKey;

    LOG_DEBUG( "Large object created for addition" );

    return true;
}