void testGlobalNamedCounter(){ PROF_CREATE_COUNTER("GlobalCounter1"); PROF_START("GlobalCounter1"); Sleep(1234); PROF_STOP("GlobalCounter1"); PROF_START("GlobalCounter1"); Sleep(1234); PROF_STOP("GlobalCounter1"); PROF_DESTROY_COUNTER("GlobalCounter1"); }
void testGlobalNamedCounterFlush(){ PROF_CREATE_COUNTER("GlobalCounter2"); PROF_START("GlobalCounter2"); Sleep(1234); PROF_STOP("GlobalCounter2"); PROF_FLUSH_COUNTER("GlobalCounter2","Step1"); PROF_START("GlobalCounter2"); Sleep(1234); PROF_STOP("GlobalCounter2"); PROF_DESTROY_COUNTER("GlobalCounter2"); }
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(); }
static VALUE db_execute(int argc, VALUE *argv, VALUE self) { sqlite3 * db = NULL; void **ppDB = NULL; sqlite3_stmt *statement = NULL; const char* sql = NULL; VALUE arRes = rb_ary_new(); VALUE* colNames = NULL; int nRes = 0; char * szErrMsg = 0; int is_batch = 0; if ((argc < 2) || (argc > 3)) rb_raise(rb_eArgError, "wrong # of arguments(%d for 3)",argc); Data_Get_Struct(self, void *, ppDB); db = (sqlite3 *)rho_db_get_handle(*ppDB); sql = RSTRING_PTR(argv[0]); is_batch = argv[1] == Qtrue ? 1 : 0; RAWTRACE1("db_execute: %s", sql); PROF_START_CREATED("SQLITE"); if ( is_batch ) { PROF_START_CREATED("SQLITE_EXEC"); rho_db_lock(*ppDB); nRes = sqlite3_exec(db, sql, NULL, NULL, &szErrMsg); rho_db_unlock(*ppDB); PROF_STOP("SQLITE_EXEC"); } else { rho_db_lock(*ppDB); PROF_START_CREATED("SQLITE_PREPARE"); nRes = rho_db_prepare_statement(*ppDB, sql, -1, &statement); PROF_STOP("SQLITE_PREPARE"); //nRes = sqlite3_prepare_v2(db, sql, -1, &statement, NULL); if ( nRes != SQLITE_OK) { szErrMsg = (char *)sqlite3_errmsg(db); rho_db_unlock(*ppDB); rb_raise(rb_eArgError, "could not prepare statement: %d; Message: %s",nRes, (szErrMsg?szErrMsg:"")); } if ( argc > 2 ) { int i = 0; VALUE args = argv[2]; if ( RARRAY_LEN(args) > 0 && TYPE(RARRAY_PTR(args)[0]) == T_ARRAY ) args = RARRAY_PTR(args)[0]; for( ; i < RARRAY_LEN(args); i++ ) { VALUE arg = RARRAY_PTR(args)[i]; if (NIL_P(arg)) { sqlite3_bind_null(statement, i+1); continue; } switch( TYPE(arg) ) { case T_STRING: sqlite3_bind_text(statement, i+1, RSTRING_PTR(arg), RSTRING_LEN(arg), SQLITE_TRANSIENT); break; case T_FLOAT: sqlite3_bind_double(statement, i+1, NUM2DBL(arg)); break; case T_FIXNUM: case T_BIGNUM: sqlite3_bind_int64(statement, i+1, NUM2LL(arg)); break; default: { VALUE strVal = rb_funcall(arg, rb_intern("to_s"), 0); sqlite3_bind_text(statement, i+1, RSTRING_PTR(strVal), -1, SQLITE_TRANSIENT); } break; } } } PROF_START_CREATED("SQLITE_EXEC"); nRes = sqlite3_step(statement); PROF_STOP("SQLITE_EXEC"); while( nRes== SQLITE_ROW ) { int nCount = sqlite3_data_count(statement); int nCol = 0; VALUE hashRec = rb_hash_new(); //if ( !colNames ) // colNames = getColNames(statement, nCount); for(;nCol<nCount;nCol++){ int nColType = sqlite3_column_type(statement,nCol); const char* szColName = sqlite3_column_name(statement,nCol); VALUE colName = rb_str_new2(szColName); VALUE colValue = Qnil; switch(nColType){ case SQLITE_NULL: break; case SQLITE_FLOAT: { double dVal = sqlite3_column_double(statement, nCol); colValue = DBL2NUM(dVal); break; } case SQLITE_INTEGER: { sqlite_int64 nVal = sqlite3_column_int64(statement, nCol); colValue = LL2NUM(nVal); break; } default:{ sqlite3_value * sqlValue = sqlite3_column_value(statement, nCol); int nLen = sqlite3_value_bytes(sqlValue); const char* szValue = (const char *)sqlite3_value_text(sqlValue); //char *text = (char *)sqlite3_column_text(statement, nCol); colValue = rb_str_new(szValue, nLen); break; } } rb_hash_aset(hashRec, colName/*colNames[nCol]*/, colValue); } rb_ary_push(arRes, hashRec); PROF_START_CREATED("SQLITE_EXEC"); nRes = sqlite3_step(statement); PROF_STOP("SQLITE_EXEC"); } rho_db_unlock(*ppDB); } if ( statement ) //sqlite3_finalize(statement); sqlite3_reset(statement); if ( colNames ) free(colNames); if ( nRes != SQLITE_OK && nRes != SQLITE_ROW && nRes != SQLITE_DONE ) { if ( !szErrMsg ) szErrMsg = (char*)sqlite3_errmsg(db); rb_raise(rb_eArgError, "could not execute statement: %d; Message: %s",nRes, (szErrMsg?szErrMsg:"")); } PROF_STOP("SQLITE"); return arRes; }
bool CHttpServer::decide(String const &method, String const &arg_uri, String const &query, HeaderList const &headers, String const &body/*, IResponseSender& respSender*/ ) { if (verbose) RAWTRACE1("Decide what to do with uri %s", arg_uri.c_str()); callback_t callback = registered(arg_uri); if (callback) { if (verbose) RAWTRACE1("Uri %s is registered callback, so handle it appropriately", arg_uri.c_str()); if ( callback == rho_http_ruby_proc_callback ) call_ruby_proc( query, body ); else callback(this, query.length() ? query : body); return false; } String uri = arg_uri; String fullPath = CFilePath::join(m_root, uri); #ifndef RHO_NO_RUBY_API if (rho_ruby_is_started()) { Route route; if (dispatch(uri, route)) { if (verbose) RAWTRACE1("Uri %s is correct route, so enable MVC logic", uri.c_str()); VALUE req = create_request_hash(route.application, route.model, route.action, route.id, method, uri, query, headers, body); VALUE data = callFramework(req); String reply(getStringFromValue(data), getStringLenFromValue(data)); rho_ruby_releaseValue(data); bool isRedirect = String_startsWith(reply, "HTTP/1.1 301") || String_startsWith(reply, "HTTP/1.1 302"); if (!send_response(reply, isRedirect)) return false; if (method == "GET") rho_rhodesapp_keeplastvisitedurl(uri.c_str()); if ( sync::RhoconnectClientManager::haveRhoconnectClientImpl() ) { if (!route.id.empty()) { sync::RhoconnectClientManager::rho_sync_addobjectnotify_bysrcname(route.model.c_str(), route.id.c_str()); } } return true; } if (isdir(fullPath)) { if (verbose) RAWTRACE1("Uri %s is directory, redirecting to index", uri.c_str()); String q = query.empty() ? "" : "?" + query; HeaderList headers; headers.push_back(Header("Location", CFilePath::join( uri, "index" RHO_ERB_EXT) + q)); send_response(create_response("301 Moved Permanently", headers), true); return false; } if (isindex(uri)) { if (!isfile(fullPath)) { if (verbose) RAWLOG_ERROR1("The file %s was not found", fullPath.c_str()); String error = "<!DOCTYPE html><html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + uri + " was not found.</font></html>"; send_response(create_response("404 Not Found",error)); return false; } if (verbose) RAWTRACE1("Uri %s is index file, call serveIndex", uri.c_str()); VALUE req = create_request_hash(route.application, route.model, route.action, route.id, method, uri, query, headers, body); VALUE data = callServeIndex((char *)fullPath.c_str(), req); String reply(getStringFromValue(data), getStringLenFromValue(data)); rho_ruby_releaseValue(data); if (!send_response(reply)) return false; if (method == "GET") rho_rhodesapp_keeplastvisitedurl(uri.c_str()); return true; } } #endif // Try to send requested file if (verbose) RAWTRACE1("Uri %s should be regular file, trying to send it", uri.c_str()); PROF_START("READ_FILE"); bool bRes = send_file(uri, headers); PROF_STOP("READ_FILE"); return bRes; }
bool CHttpServer::send_file(String const &path, HeaderList const &hdrs) { String fullPath = CFilePath::normalizePath(path); if (String_startsWith(fullPath,"/app/db/db-files") ) fullPath = CFilePath::join( rho_native_rhodbpath(), path.substr(4) ); else if (fullPath.find(m_root) != 0 && fullPath.find(m_strRhoRoot) != 0 && fullPath.find(m_strRuntimeRoot) != 0 && fullPath.find(m_userroot) != 0 && fullPath.find(m_strRhoUserRoot) != 0) fullPath = CFilePath::join( m_root, path ); struct stat st; bool bCheckExist = true; #ifdef RHODES_EMULATOR String strPlatform = RHOSIMCONF().getString("platform"); if ( strPlatform.length() > 0 ) { String fullPath1 = fullPath; int nDot = fullPath1.rfind('.'); if ( nDot >= 0 ) fullPath1.insert(nDot, String(".") + strPlatform); else fullPath1 += String(".") + strPlatform; if (stat(fullPath1.c_str(), &st) == 0 && S_ISREG(st.st_mode)) { fullPath = fullPath1; bCheckExist = false; } } #endif bool doesNotExists = bCheckExist && (stat(fullPath.c_str(), &st) != 0 || !S_ISREG(st.st_mode)); if ( doesNotExists ) { // looking for files at 'rho/apps' at runtime folder fullPath = CFilePath::join( m_strRuntimeRoot, path ); } if (verbose) RAWTRACE1("Sending file %s...", fullPath.c_str()); if ( doesNotExists ) { if ( stat(fullPath.c_str(), &st) != 0 || !S_ISREG(st.st_mode) ) { doesNotExists = true; }else doesNotExists = false; } #ifdef RHODES_EMULATOR if ( doesNotExists ) { CTokenizer oTokenizer( RHOSIMCONF().getString("ext_path"), ";" ); while (oTokenizer.hasMoreTokens()) { String tok = oTokenizer.nextToken(); tok = String_trim(tok); String fullPath1 = CFilePath::join( tok, path ); if (stat(fullPath1.c_str(), &st) == 0 && S_ISREG(st.st_mode)) { fullPath = fullPath1; doesNotExists = false; break; } } } #endif if ( doesNotExists ) { if (verbose) RAWLOG_ERROR1("The file %s was not found", path.c_str()); String error = "<!DOCTYPE html><html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + path + " was not found.</font></html>"; send_response(create_response("404 Not Found",error)); return false; } PROF_START("LOW_FILE"); FILE *fp = fopen(fullPath.c_str(), "rb"); PROF_STOP("LOW_FILE"); if (!fp) { if (verbose) RAWLOG_ERROR1("The file %s could not be opened", path.c_str()); String error = "<!DOCTYPE html><html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + path + " could not be opened.</font></html"; send_response(create_response("404 Not Found",error)); return false; } HeaderList headers; // Detect mime type headers.push_back(Header("Content-Type", get_mime_type(path))); if ( String_startsWith(path, "/public") ) { headers.push_back(Header("Expires", "Thu, 15 Apr 2020 20:00:00 GMT") ); headers.push_back(Header("Cache-Control", "max-age=2592000") ); } // Content length char* buf = new char[FILE_BUF_SIZE]; String start_line; size_t file_size = st.st_size; size_t range_begin = 0, range_end = file_size - 1; size_t content_size = file_size; if (parse_range(hdrs, &range_begin, &range_end)) { if (range_end >= file_size) range_end = file_size - 1; if (range_begin >= range_end) range_begin = range_end - 1; content_size = range_end - range_begin + 1; if (fseek(fp, range_begin, SEEK_SET) == -1) { RAWLOG_ERROR1("Can not seek to specified range start: %lu", (unsigned long)range_begin); snprintf(buf, FILE_BUF_SIZE, "bytes */%lu", (unsigned long)file_size); headers.push_back(Header("Content-Range", buf)); send_response(create_response("416 Request Range Not Satisfiable",headers)); fclose(fp); delete[] buf; return false; } snprintf(buf, FILE_BUF_SIZE, "bytes %lu-%lu/%lu", (unsigned long)range_begin, (unsigned long)range_end, (unsigned long)file_size); headers.push_back(Header("Content-Range", buf)); start_line = "206 Partial Content"; } else { start_line = "200 OK"; } snprintf(buf, FILE_BUF_SIZE, "%lu", (unsigned long)content_size); headers.push_back(Header("Content-Length", buf)); // Send headers if (!send_response(create_response(start_line, headers))) { if (verbose) RAWLOG_ERROR1("Can not send headers while sending file %s", path.c_str()); fclose(fp); delete[] buf; return false; } // Send body for (size_t start = range_begin; start < range_end + 1;) { size_t need_to_read = range_end - start + 1; if (need_to_read == 0) break; if (need_to_read > FILE_BUF_SIZE) need_to_read = FILE_BUF_SIZE; PROF_START("LOW_FILE"); size_t n = fread(buf, 1, need_to_read, fp);//fread(buf, 1, need_to_read, fp); PROF_STOP("LOW_FILE"); if (n < need_to_read) { if (ferror(fp) ) { if (verbose) RAWLOG_ERROR2("Can not read part of file (at position %lu): %s", (unsigned long)start, strerror(errno)); } else if ( feof(fp) ) { if (verbose) RAWLOG_ERROR1("End of file reached, but we expect data (%lu bytes)", (unsigned long)need_to_read); } fclose(fp); delete[] buf; return false; } start += n; if (!send_response_body(String(buf, n))) { if (verbose) RAWLOG_ERROR1("Can not send part of data while sending file %s", path.c_str()); fclose(fp); delete[] buf; return false; } } PROF_START("LOW_FILE"); fclose(fp); PROF_STOP("LOW_FILE"); delete[] buf; if (verbose) RAWTRACE1("File %s was sent successfully", path.c_str()); return false; }
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"); }
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; } }
RHO_GLOBAL void JNICALL Java_com_rhomobile_rhodes_Logger_profStop (JNIEnv *env, jclass, jstring tag) { PROF_STOP(rho_cast<std::string>(env, tag).c_str()); }
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"); }
void testLocalNamedCounter(){ PROF_START("LocalCounter1"); Sleep(2126); PROF_STOP("LocalCounter1"); }