Exemplo n.º 1
0
SyncImpl::SyncImpl()
{
#ifdef PX_WINMODERN
	getSync(this) = CreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS);
#else
	getSync(this) = CreateEvent(0,true,false,0);
#endif
}
Exemplo n.º 2
0
bool SyncImpl::wait(PxU32 milliseconds)
{
	if(milliseconds==-1)
		milliseconds = INFINITE;
#ifdef PX_WINMODERN
	return WaitForSingleObjectEx(getSync(this), milliseconds, false) == WAIT_OBJECT_0 ? true : false;
#else
	return WaitForSingleObject(getSync(this), milliseconds) == WAIT_OBJECT_0 ? true : false;
#endif
}
Exemplo n.º 3
0
void CSyncSource::syncClientChanges()
{
    const char* arUpdateTypes[] = {"create", "update", "delete"};
    for( int i = 0; i < 3 && getSync().isContinueSync(); i++ )
    {
        String strUrl = getUrl() + "/" + arUpdateTypes[i];
        strUrl += "objects";
        String strQuery = CSyncEngine::SYNC_SOURCE_FORMAT() + "&client_id=" + getSync().getClientID();

        m_arSyncBlobs.removeAllElements();
        String strBody;
        makePushBody(strBody, arUpdateTypes[i]);
        if ( strBody.length() > 0 )
        {
		    LOG(INFO) + "Push client changes to server. Source: " + getName() + "Size :" + strBody.length();
		    LOG(TRACE) + "Push body: " + strBody;		
 
            NetResponse( resp, getNet().pushData(strUrl+strQuery,strBody, &getSync()) );
            if ( !resp.isOK() )
            {
                getSync().setState(CSyncEngine::esStop);
                m_nErrCode = RhoRuby.ERR_REMOTESERVER;
                continue;
            }
        }
 
        if ( m_arSyncBlobs.size() > 0 )
        {
		    LOG(INFO) + "Push blobs to server. Source: " + getName() + "Count :" + m_arSyncBlobs.size();
            //oo conflicts
            if ( i < 1 ) //create
                getDB().executeSQL("UPDATE changed_values SET sent=2 WHERE source_id=? and update_type=? and (attrib_type IS NULL or attrib_type!=?) and sent=1", 
                    getID(), arUpdateTypes[i], "blob.file" );
            else
            //
                getDB().executeSQL("DELETE FROM changed_values WHERE source_id=? and update_type=? and (attrib_type IS NULL or attrib_type!=? and sent=1)", 
                    getID(), arUpdateTypes[i], "blob.file" );

            syncClientBlobs(strUrl+strQuery);
        }else if ( strBody.length() > 0 )
        {
            //oo conflicts
            if ( i < 1 ) //create
                getDB().executeSQL("UPDATE changed_values SET sent=2 WHERE source_id=? and update_type=? and sent=1", getID(), arUpdateTypes[i] );
            else
            //
                getDB().executeSQL("DELETE FROM changed_values WHERE source_id=? and update_type=? and sent=1", getID(), arUpdateTypes[i] );
        }
    }
}
Exemplo n.º 4
0
void CSyncSource::processAssociations(const String& strOldObject, const String& strNewObject)
{
    for ( int i = 0; i < (int)m_arAssociations.size(); i++ )
    {
        CSyncSource* pSrc = getSync().findSourceByName(m_arAssociations.elementAt(i).m_strSrcName);
        if ( pSrc != null )
            pSrc->updateAssociation(strOldObject, strNewObject, m_arAssociations.elementAt(i).m_strAttrib);
    }
}
Exemplo n.º 5
0
TEST(TestFutureSync, InSitu)
{
  /* Check that whatever we do, a function returning a FutureSync is not
  * stuck if we take the sync, and blocks if we ignore it
  */
  bool tag = false;
  {
    qi::FutureSync<int> fs = getSync(&tag);
    ASSERT_FALSE(tag);
  }
  ASSERT_TRUE(tag);
  tag = false;
  {
    qi::FutureSync<int> fs = getSync2(&tag);
    ASSERT_FALSE(tag);
  }
  ASSERT_TRUE(tag);
  tag = false;
  {
    qi::FutureSync<int> fs = getGetSync(&tag);
    ASSERT_FALSE(tag);
  }
  ASSERT_TRUE(tag);
  tag = false;
  {
    qi::FutureSync<int> fs = getGetSync2(&tag);
    ASSERT_FALSE(tag);
  }
  ASSERT_TRUE(tag);
  tag = false;
  {
    getSync(&tag);
    ASSERT_TRUE(tag);
  }
  ASSERT_TRUE(tag);
  tag = false;
  {
    getSync2(&tag);
    ASSERT_TRUE(tag);
  }
  ASSERT_TRUE(tag);
  tag = false;
}
Exemplo n.º 6
0
void CSyncSource::processSyncCommand(const String& strCmd, CJSONEntry oCmdEntry)
{
    CJSONStructIterator objIter(oCmdEntry);

    for( ; !objIter.isEnd() && getSync().isContinueSync(); objIter.next() )
    {
        String strObject = objIter.getCurKey();
        CJSONStructIterator attrIter( objIter.getCurValue() );
        if ( m_bSchemaSource )
            processServerCmd_Ver3_Schema(strCmd,strObject,attrIter);
        else
        {
            for( ; !attrIter.isEnd() && getSync().isContinueSync(); attrIter.next() )
            {
                String strAttrib = attrIter.getCurKey();
                String strValue = attrIter.getCurString();

                processServerCmd_Ver3(strCmd,strObject,strAttrib,strValue);
            }
        }

        if ( getSyncType().compare("none") == 0 )
            continue;

        int nSyncObjectCount  = getNotify().incLastSyncObjectCount(getID());
        if ( getProgressStep() > 0 && (nSyncObjectCount%getProgressStep() == 0) )
            getNotify().fireSyncNotification(this, false, RhoAppAdapter.ERR_NONE, "");

        if ( getDB().isUIWaitDB() )
        {
	        LOG(INFO) + "Commit transaction because of UI request.";
            getDB().endTransaction();
            CSyncThread::getInstance()->sleep(1000);
            getDB().startTransaction();
        }

    }
}
Exemplo n.º 7
0
void XDBF::writeEntry(Entry *entry, Achievement_Entry *chiev)
{
    Achievement_Entry temp = *chiev;

    SwapEndian(&temp.size);
    SwapEndian(&temp.id);
    SwapEndian(&temp.imageID);
    SwapEndian(&temp.gamerscore);
    SwapEndian((unsigned long long*)&temp.unlockedTime);

    openedFile->setPosition(entry->address);
    openedFile->write(&temp, 0x1C);

    updateSyncListEntry(*getSync(ET_ACHIEVEMENT, entry->address), ET_ACHIEVEMENT, Enqueue);
}
Exemplo n.º 8
0
void CSyncSource::syncServerChanges()
{
    LOG(INFO) + "Sync server changes source ID :" + getID();

    while( getSync().isContinueSync() )
    {
        setCurPageCount(0);
        String strUrl = getProtocol().getServerQueryUrl("");
        String strQuery = getProtocol().getServerQueryBody(getName(), getSync().getClientID(), getSync().getSyncPageSize());

        if ( !m_bTokenFromDB && getToken() > 1 )
            strQuery += "&token=" + convertToStringA(getToken());

		LOG(INFO) + "Pull changes from server. Url: " + (strUrl+strQuery);
        PROF_START("Net");	    
        NetResponse(resp,getNet().pullData(strUrl+strQuery, &getSync()));
		PROF_STOP("Net");

        if ( !resp.isOK() )
        {
            getSync().stopSync();
			m_nErrCode = RhoAppAdapter.getErrorFromResponse(resp);
            m_strError = resp.getCharData();
            continue;
        }

        const char* szData = resp.getCharData();
        //const char* szData = "[{\"version\":3},{\"token\":\"\"},{\"count\":0},{\"progress_count\":28},{\"total_count\":28},{\"source-error\":{\"login-error\":{\"message\":\"s currently connected from another machine\"}}}]";
        //const char* szData = "[{\"version\":3},{\"token\":\"\"},{\"count\":0},{\"progress_count\":0},{\"total_count\":0},{\"create-error\":{\"0_broken_object_id\":{\"name\":\"wrongname\",\"an_attribute\":\"error create\"},\"0_broken_object_id-error\":{\"message\":\"error create\"}}}]";
        //const char* szData = "[{\"version\":3},{\"token\":\"35639160294387\"},{\"count\":3},{\"progress_count\":0},{\"total_count\":3},{\"metadata\":\"{\\\"foo\\\":\\\"bar\\\"}\",\"insert\":{\"1\":{\"price\":\"199.99\",\"brand\":\"Apple\",\"name\":\"iPhone\"}}}]";

        //LOG(INFO) + szData;
        PROF_START("Parse");
        CJSONArrayIterator oJsonArr(szData);
        PROF_STOP("Parse");

        processServerResponse_ver3(oJsonArr);

        if (getSync().getSourceOptions().getBoolProperty(getID(), "pass_through"))
            processToken(0);

        if ( getToken() == 0 )
            break;
    }

    if ( getSync().isSchemaChanged() )
        getSync().stopSync();
}
StringBuffer MailSyncSourceConfig::print() {

    StringBuffer ret;
    ret = "** SOURCE: "; ret += getName(); ret += "**\r\n";
    
    ret += "URI:\t\t"; ret += getURI(); ret += "\r\n";
    ret += "SyncModes:\t"; ret += getSyncModes(); ret += "\r\n";
    ret += "Type:\t\t"; ret += getType(); ret += "\r\n";
    ret += "Sync:\t\t"; ret += getSync(); ret += "\r\n";
    ret += "Encoding:\t"; ret += getEncoding(); ret += "\r\n";
    ret += "Version:\t"; ret += getVersion(); ret += "\r\n";
    ret += "SupportedType:\t"; ret += getSupportedTypes(); ret += "\r\n";
    ret += "Last:\t\t"; ret.append(getLast()); ret += "\r\n";
    ret += "Encryption:\t"; ret += getEncryption(); ret += "\r\n";    
    ret += "Enabled:\t"; ret += (isEnabled() == true ? "1" : "0"); ret += "\r\n";    


    ret += "DownloadAge:\t"; ret.append(getDownloadAge()); ret += "\r\n";    
    ret += "BodySize:\t"; ret.append(getBodySize()); ret += "\r\n";
    ret += "AttachSize:\t"; ret.append(getAttachSize()); ret += "\r\n";

    return ret;
}
Exemplo n.º 10
0
void SyncImpl::set()
{
	SetEvent(getSync(this));
}
Exemplo n.º 11
0
void SyncImpl::reset()
{
	ResetEvent(getSync(this));
}
Exemplo n.º 12
0
void CSyncSource::processServerData(const char* szData)
{
    PROF_START("Parse");
    CJSONArrayIterator oJsonArr(szData);
    PROF_STOP("Parse");
    PROF_START("Data1");
    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("error") )
    {
        m_strError = oJsonArr.getCurItem().getString("error");
        m_nErrCode = RhoRuby.ERR_CUSTOMSYNCSERVER;
        getSync().stopSync();
        return;
    }

    if ( !oJsonArr.isEnd() )
    {
        setCurPageCount(oJsonArr.getCurItem().getInt("count"));
        oJsonArr.next();
    }
    int nVersion = 0;
    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("version") )
    {
        nVersion = oJsonArr.getCurItem().getInt("version");
        oJsonArr.next();
    }

    if ( nVersion != getSync().SYNC_VERSION() )
    {
        LOG(ERROR) + "Sync server send data with incompatible version. Client version: " + convertToStringA(getSync().SYNC_VERSION()) +
            "; Server response version: " + convertToStringA(nVersion) + ". Source name: " + getName();
        getSync().stopSync();
        m_nErrCode = RhoRuby.ERR_SYNCVERSION;
        return;
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("rt") )
    {
        setRefreshTime(oJsonArr.getCurItem().getInt("rt"));
        oJsonArr.next();
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("total_count") )
    {
        setTotalCount(oJsonArr.getCurItem().getInt("total_count"));
        oJsonArr.next();
    }
    //if ( getServerObjectsCount() == 0 )
    //    getNotify().fireSyncNotification(this, false, RhoRuby.ERR_NONE, "");

    if ( !oJsonArr.isEnd() )
    {
        processToken(oJsonArr.getCurItem().getUInt64("token"));
        oJsonArr.next();
    }else if ( getCurPageCount() == 0 )
    {
        //oo conflicts
        getDB().executeSQL("DELETE FROM changed_values where source_id=? and sent>=3", getID() );
        //
        processToken(0);
    }

	LOG(INFO) + "Got " + getCurPageCount() + "(Processed: " +  getServerObjectsCount() + ") records of " + getTotalCount() + " from server. Source: " + getName()
         + ". Version: " + nVersion;

    PROF_STOP("Data1");
    if ( !oJsonArr.isEnd() && getSync().isContinueSync() )
    {
        PROF_START("Data");
        //TODO: support DBExceptions
        getDB().startTransaction();

        int nSavedPos = oJsonArr.getCurPos();
        setSyncServerDataPass(edpNone);
        processServerData_Ver1(oJsonArr);

        setSyncServerDataPass(edpDeleteObjects);
        oJsonArr.reset(nSavedPos);
        processServerData_Ver1(oJsonArr);

	    PROF_STOP("Data");		    
    	PROF_START("DB");
        getDB().endTransaction();
	    PROF_STOP("DB");

        getNotify().fireObjectsNotification();
    }

	PROF_START("Data1");
    if ( getCurPageCount() > 0 )
        getNotify().fireSyncNotification(this, false, RhoRuby.ERR_NONE, "");
	PROF_STOP("Data1");
}
Exemplo n.º 13
0
void CSyncSource::processServerCmd_Ver3_Schema(const String& strCmd, const String& strObject, CJSONStructIterator& attrIter)//throws Exception
{
    if ( strCmd.compare("insert") == 0 )
    {
        Vector<String> vecValues, vecAttrs;
        String strCols = "", strQuest = "", strSet = "";
        for( ; !attrIter.isEnd() && getSync().isContinueSync(); attrIter.next() )
        {
            CAttrValue oAttrValue(attrIter.getCurKey(),attrIter.getCurString());
            if ( !processBlob(strCmd,strObject,oAttrValue) )
                continue;

            if ( strCols.length() > 0 )
                strCols += ",";
            if ( strQuest.length() > 0)
                strQuest += ",";
            if ( strSet.length() > 0)
                strSet += ",";

            strCols += oAttrValue.m_strAttrib;
            strQuest += "?";
            strSet += oAttrValue.m_strAttrib + "=?";
            vecAttrs.addElement(oAttrValue.m_strAttrib);
            vecValues.addElement(oAttrValue.m_strValue);
        }
        vecValues.addElement(strObject);
        if ( strCols.length() > 0 )
            strCols += ",";
        if ( strQuest.length() > 0)
            strQuest += ",";

        strCols += "object";
        strQuest += "?";

        String strSqlInsert = "INSERT INTO ";
        strSqlInsert += getName() + " (";
        strSqlInsert += strCols + ") VALUES(" + strQuest + ")";

        if ( !getSync().isContinueSync() )
            return;

        DBResult(resInsert, getDB().executeSQLReportNonUniqueEx(strSqlInsert.c_str(), vecValues ) );
        if ( resInsert.isNonUnique() )
        {
            String strSqlUpdate = "UPDATE ";
            strSqlUpdate += getName() + " SET " + strSet + " WHERE object=?";
            getDB().executeSQLEx(strSqlUpdate.c_str(), vecValues);

            if ( getSyncType().compare("none") != 0 )
            {
                // oo conflicts
                for( int i = 0; i < (int)vecAttrs.size(); i++ )
                {
                    getDB().executeSQL("UPDATE changed_values SET sent=4 where object=? and attrib=? and source_id=? and sent>1", 
                        strObject, vecAttrs.elementAt(i), getID() );
                }
                //
            }
        }

        if ( getSyncType().compare("none") != 0 )
            getNotify().onObjectChanged(getID(),strObject, CSyncNotify::enUpdate);

        m_nInserted++;
    }else if (strCmd.compare("delete") == 0)
    {
        Vector<String> vecAttrs;
        String strSet = "";
        for( ; !attrIter.isEnd() && getSync().isContinueSync(); attrIter.next() )
        {
            CAttrValue oAttrValue(attrIter.getCurKey(),attrIter.getCurString());

            if ( strSet.length() > 0 )
                strSet += ",";

            vecAttrs.addElement(oAttrValue.m_strAttrib);
            strSet += oAttrValue.m_strAttrib + "=NULL";
        }

        String strSqlUpdate = "UPDATE ";
        strSqlUpdate += getName() + " SET " + strSet + " WHERE object=?";

        if ( strSet.length() == 0 || !getSync().isContinueSync() )
            return;

        getDB().executeSQL(strSqlUpdate.c_str(), strObject);
        //Remove item if all nulls
        String strSelect = String("SELECT * FROM ") + getName() + " WHERE object=?";
        DBResult(res, getDB().executeSQL( strSelect.c_str(), strObject ) );
        if ( !res.isEnd() )
        {
            boolean bAllNulls = true;
            for( int i = 0; i < res.getColCount(); i ++)
            {
                if ( !res.isNullByIdx(i) && res.getColName(i).compare("object")!=0 )
                {
                    bAllNulls = false;
                    break;
                }
            }

            if (bAllNulls)
            {
                String strDelete = String("DELETE FROM ") + getName() + " WHERE object=?";
                getDB().executeSQL( strDelete.c_str(), strObject);
            }
        }

        if ( getSyncType().compare("none") != 0 )
        {
            getNotify().onObjectChanged(getID(), strObject, CSyncNotify::enDelete);
            // oo conflicts
            for( int i = 0; i < (int)vecAttrs.size(); i++ )
            {
                getDB().executeSQL("UPDATE changed_values SET sent=3 where object=? and attrib=? and source_id=?", 
                    strObject, vecAttrs.elementAt(i), getID() );
            }
            //
        }

        m_nDeleted++;
    }else if ( strCmd.compare("links") == 0 )
    {
        String strValue = attrIter.getCurString();
        processAssociations(strObject, strValue);

        String strSqlUpdate = "UPDATE ";
        strSqlUpdate += getName() + " SET object=? WHERE object=?";
        getDB().executeSQL(strSqlUpdate.c_str(), strValue, strObject);

        getDB().executeSQL("UPDATE changed_values SET object=?,sent=3 where object=? and source_id=?", strValue, strObject, getID() );
        getNotify().onObjectChanged(getID(), strObject, CSyncNotify::enCreate);
    }

}
Exemplo n.º 14
0
void CSyncSource::processServerResponse_ver3(CJSONArrayIterator& oJsonArr)
{
    PROF_START("Data1");

    int nVersion = 0;
    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("version") )
    {
        nVersion = oJsonArr.getCurItem().getInt("version");
        oJsonArr.next();
    }

    if ( nVersion != getProtocol().getVersion() )
    {
        LOG(ERROR) + "Sync server send data with incompatible version. Client version: " + convertToStringA(getProtocol().getVersion()) +
            "; Server response version: " + convertToStringA(nVersion) + ". Source name: " + getName();
        getSync().stopSync();
        m_nErrCode = RhoAppAdapter.ERR_SYNCVERSION;
        return;
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("token"))
    {
        processToken(oJsonArr.getCurItem().getUInt64("token"));
        oJsonArr.next();
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("source") )
    {
        //skip it. it uses in search only
        oJsonArr.next();
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("count") )
    {
        setCurPageCount(oJsonArr.getCurItem().getInt("count"));
        oJsonArr.next();
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("refresh_time") )
    {
        setRefreshTime(oJsonArr.getCurItem().getInt("refresh_time"));
        oJsonArr.next();
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("progress_count") )
    {
        //TODO: progress_count
        //setTotalCount(oJsonArr.getCurItem().getInt("progress_count"));
        oJsonArr.next();
    }

    if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("total_count") )
    {
        setTotalCount(oJsonArr.getCurItem().getInt("total_count"));
        oJsonArr.next();
    }

    //if ( getServerObjectsCount() == 0 )
    //    getNotify().fireSyncNotification(this, false, RhoAppAdapter.ERR_NONE, "");

    if ( getToken() == 0 )
    {
        //oo conflicts
        getDB().executeSQL("DELETE FROM changed_values where source_id=? and sent>=3", getID() );
        //

    }

	LOG(INFO) + "Got " + getCurPageCount() + "(Processed: " +  getServerObjectsCount() + ") records of " + getTotalCount() + " from server. Source: " + getName()
         + ". Version: " + nVersion;

    PROF_STOP("Data1");
    if ( !oJsonArr.isEnd() && getSync().isContinueSync() )
    {
        CJSONEntry oCmds = oJsonArr.getCurItem();
        PROF_START("Data");
        //TODO: use isUIWaitDB inside processSyncCommand
        //    if ( getDB().isUIWaitDB() )
        //    {
		//        LOG(INFO) + "Commit transaction because of UI request.";
        //        getDB().endTransaction();
        //        getDB().startTransaction();
        //    }

        if ( oCmds.hasName("schema-changed") )
        {
            getSync().setSchemaChanged(true);
        }else if ( oCmds.hasName("source-error") )
        {
            CJSONEntry errSrc = oCmds.getEntry("source-error");
            CJSONStructIterator errIter(errSrc);
            for( ; !errIter.isEnd(); errIter.next() )
            {
                m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
                m_strError = errIter.getCurValue().getString("message");
                m_strErrorType = errIter.getCurKey();
            }
        }else if ( oCmds.hasName("search-error") )
        {
            CJSONEntry errSrc = oCmds.getEntry("search-error");
            CJSONStructIterator errIter(errSrc);
            for( ; !errIter.isEnd(); errIter.next() )
            {
                m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
                m_strError = errIter.getCurValue().getString("message");
                m_strErrorType = errIter.getCurKey();
            }
        }else if ( oCmds.hasName("create-error") )
        {
            m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
            m_strErrorType = "create-error";
        }else if ( oCmds.hasName("update-error") )
        {
            m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
            m_strErrorType = "update-error";
        }else if ( oCmds.hasName("delete-error") )
        {
            m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
            m_strErrorType = "delete-error";
        }else
        {
            getDB().startTransaction();

            if (getSync().getSourceOptions().getBoolProperty(getID(), "pass_through"))
            {
                if ( m_bSchemaSource )
                    getDB().executeSQL( (String("DELETE FROM ") + getName()).c_str() );
                else
                    getDB().executeSQL("DELETE FROM object_values WHERE source_id=?", getID() );
            }

            if ( oCmds.hasName("metadata") && getSync().isContinueSync() )
            {
                String strMetadata = oCmds.getString("metadata");
                getDB().executeSQL("UPDATE sources SET metadata=? WHERE source_id=?", strMetadata, getID() );
            }
            if ( oCmds.hasName("links") && getSync().isContinueSync() )
                processSyncCommand("links", oCmds.getEntry("links") );
            if ( oCmds.hasName("delete") && getSync().isContinueSync() )
                processSyncCommand("delete", oCmds.getEntry("delete") );
            if ( oCmds.hasName("insert") && getSync().isContinueSync() )
                processSyncCommand("insert", oCmds.getEntry("insert") );

            PROF_STOP("Data");

	        PROF_START("DB");
            getDB().endTransaction();
            PROF_STOP("DB");

            getNotify().fireObjectsNotification();
        }
    }

	PROF_START("Data1");
    if ( getCurPageCount() > 0 )
        getNotify().fireSyncNotification(this, false, RhoAppAdapter.ERR_NONE, "");
	PROF_STOP("Data1");
}
Exemplo n.º 15
0
static void *
drawVideoThread(void *data)
{
	ffmpegPlayer *me = data;

	AG_ObjectLock(me);

	for (;;) {
		SDL_ffmpegVideoFrame *frame = me->videoFrame[me->curVideoFrame];

		if (!frame->ready) {
			DEBUG("Video buffer underrun!");
			SDL_ffmpegGetVideoFrame(me->file, frame);
		}

		uint64_t sync = getSync(me);
		uint64_t pts = frame->pts;

		if (pts >= sync) {
			AG_ObjectUnlock(me);
			/* condition variable waiting may be faster, test with 500mhz */
			AG_Delay(pts - sync);
			AG_ObjectLock(me);
			if (me->file == NULL) {
				/* FIXME */
				break;
			}

			if (pts > getSync(me))
				continue;

#ifdef USE_OVERLAY
			if (frame->overlay != NULL) {
				if (AG_WidgetVisible(me)) {
					int frame_x = (AGWIDGET(me)->w - me->disp_w) / 2;
					int frame_y = (AGWIDGET(me)->h - me->disp_h) / 2;

					SDL_Rect rect = {
						.x = AGWIDGET(me)->rView.x1 + frame_x,
						.y = AGWIDGET(me)->rView.y1 + frame_y,
						.w = me->disp_w,
						.h = me->disp_h
					};
					SDL_DisplayYUVOverlay(frame->overlay, &rect);
				}
			}
#else
			if (frame->surface != NULL) {
#ifdef USE_SDL_SHADOWSURFACE
				if (me->surface != NULL)
					AG_SDL_ShadowSurfaceFree(me->surface);
				me->surface = AG_SDL_ShadowSurface(frame->surface);
#else
				if (me->surface != NULL)
					AG_SurfaceFree(me->surface);
				me->surface = AG_SurfaceFromSDL(frame->surface);
#endif
				if (me->surface == NULL) {
					/* FIXME */
					break;
				}

				AG_Redraw(AGWIDGET(me));
			}
#endif
		} else {
			/* frame is skipped */
			DEBUG("skip frame: %lums late", sync - frame->pts);
		}

		frame->ready = 0;
		RR_INC(me->curVideoFrame, FFMPEGPLAYER_BUFSIZE);

		/* wake up buffer-fill thread */
		AG_CondSignal(&me->video_cond);
	}
Exemplo n.º 16
0
void CSyncSource::syncServerChanges()
{
    LOG(INFO) + "Sync server changes source ID :" + getID();

    while( getSync().isContinueSync() )
    {
        setCurPageCount(0);
        String strUrl = getUrl();
        if ( m_strAction.length() > 0 )
            strUrl = CFilePath::join( strUrl, m_strAction);

        String strQuery = getSync().SYNC_SOURCE_FORMAT() + "&client_id=" + getSync().getClientID() + 
                "&p_size=" + getSync().SYNC_PAGE_SIZE() + "&version=" + convertToStringA(getSync().SYNC_VERSION());
        if ( m_strParams.length() > 0 )
            strQuery += m_strParams;
        if( m_strUrlParams.length() > 0 )
	        strQuery += "&" + m_strUrlParams;

        if ( getAskParams().length() > 0 )
        {
            strUrl +=  getSync().SYNC_ASK_ACTION();
            strQuery += "&question=" + getAskParams();
        }

        if ( !m_bTokenFromDB && getToken() > 1 )
            strQuery += "&ack_token=" + convertToStringA(getToken());

		LOG(INFO) + "Pull changes from server. Url: " + (strUrl+strQuery);
        PROF_START("Net");	    
        NetResponse(resp,getNet().pullData(strUrl+strQuery, &getSync()));
		PROF_STOP("Net");

        if ( !resp.isOK() )
        {
            getSync().stopSync();
			if (resp.isResponseRecieved())
				m_nErrCode = RhoRuby.ERR_REMOTESERVER;
			else
				m_nErrCode = RhoRuby.ERR_NETWORK;
            continue;
        }

        processServerData(resp.getCharData());

		//String strData =
        //"[{count:10},{version:1},{total_count: 5425},{token: 123},{s:\"RhoDeleteSource\",ol:[{o:\"rho_del_obj\",av:[{i:55550425},{i:75665819},{i:338165272},{i:402396629},{i:521753981},{i:664143530},{i:678116186},{i:831092394},{i:956041217},{i:970452458}]}]}]";
		/*"[{count: 124},{version: 1},{total_count: 5425},{token: 123},"
        "{s:\"Product\",ol:["
		"{oo:\"123\",o:\"2ed2e0c7-8c4c-99c6-1b37-498d250bb8e7\",av:["
		"{a:\"first_name\",i:47354289,v:\"Lars. \n\n Burgess\", t:\"blob\"},"
        "{a:\"second_name\",i:55555,v:\"Burgess\"}]},"
        "{oo:\"456\", e:\"Something went wrong creating this record on the backend: code 7\"}"
        "]}]"; */
		/*"[{count: 1},{version: 1},{total_count: 1},{token: 123},"
        "{s:\"Product\",ol:["
        "{oo:\"94\", e:\"Something went wrong creating this record on the backend: code 7\"}"
        "]}]";*/
		/*"[{count: 1},{version: 1},{total_count: 1},{token: 123},"
        "{s:\"Product\",ol:["
        "{o:\"94\", av:["
        "{a:\"TEST\",i:55555,v:\"Geny\"}]},"
        "]}]";

		//u:\"query\",  
		processServerData(strData.c_str()); */

        if ( getAskParams().length() > 0 || getCurPageCount() == 0 )
            break;
    }
}
Exemplo n.º 17
0
SyncImpl::~SyncImpl()
{
	CloseHandle(getSync(this));
}
Exemplo n.º 18
0
boolean CSyncSource::processSyncObject_ver1(CJSONEntry oJsonObject, int nSrcID)//throws Exception
{
    const char* strOldObject = oJsonObject.getString("oo");
    if ( isDeleteObjectsPass() != (nSrcID < 0) )
        return true;

    if ( oJsonObject.hasName("e") )
    {
        const char* strError = oJsonObject.getString("e");
        getNotify().addCreateObjectError(nSrcID,strOldObject,strError);
        return true;
    }

	const char* strObject = oJsonObject.getString("o");
	CJSONArrayIterator oJsonArr(oJsonObject, "av");
    //oo conflicts
    boolean bUpdatedOO = false;
    //
    for( ; !oJsonArr.isEnd() && getSync().isContinueSync(); oJsonArr.next() )
	{
		CJSONEntry oJsonEntry = oJsonArr.getCurItem();
        if ( oJsonEntry.isEmpty() )
        	continue;

        if ( nSrcID >= 0 ) //insert
        {
    	    CValue value(oJsonEntry,1);
    	    if ( !downloadBlob(value) )
    		    return false;

            String strAttrib = oJsonEntry.getString("a");
            //oo conflicts
            if ( strOldObject != null && !bUpdatedOO )
            {
                getDB().executeSQL("UPDATE object_values SET object=? where object=? and source_id=?", strObject, strOldObject, nSrcID );
                getDB().executeSQL("UPDATE changed_values SET object=? where object=? and source_id=?", strObject, strOldObject, nSrcID );

                getNotify().onObjectChanged(nSrcID,strOldObject, CSyncNotify::enCreate);

                bUpdatedOO = true;
            }

            DBResult(resInsert, getDB().executeSQLReportNonUnique("INSERT INTO object_values \
                (id, attrib, source_id, object, value, attrib_type) VALUES(?,?,?,?,?,?)", 
                value.m_nID, strAttrib, nSrcID, strObject,
                value.m_strValue, value.m_strAttrType ) );
            if ( resInsert.isNonUnique() )
            {
                getDB().executeSQL("UPDATE object_values \
                    SET id=?, value=?, attrib_type=? WHERE object=? and attrib=? and source_id=?", 
                    value.m_nID, value.m_strValue, value.m_strAttrType,
                    strObject, strAttrib, nSrcID );

                // oo conflicts
                getDB().executeSQL("UPDATE changed_values SET main_id=? where object=? and attrib=? and source_id=? and sent<=1", value.m_nID, strObject, strAttrib, nSrcID );
                getDB().executeSQL("UPDATE changed_values SET sent=4 where object=? and attrib=? and source_id=? and sent>1", strObject, strAttrib, nSrcID );
                //
            }

            getNotify().onObjectChanged(nSrcID,strObject, CSyncNotify::enUpdate);

            m_nInserted++;
        }else
Exemplo n.º 19
0
qi::FutureSync<int> getGetSync(bool* tag)
{
  return getSync(tag);
}