void RhoConnectClientImpl::search( const rho::Hashtable<rho::String, rho::String>& args, rho::apiGenerator::CMethodResult& oResult) {
	getSyncThread()->stopAll();

	bool syncChanges = false;
	int progressStep = -1;
	rho::Vector<rho::String> sources;
	rho::String searchParams;
	rho::String from = "search";
	
	/* handle old-style callback setting */
	if (args.containsKey("callback")) {
		oResult.setRubyCallback(args.get("callback"));
        
        if (args.containsKey("callback_param")) {
            oResult.setCallbackParam(args.get("callback_param"));
        }
	}
		
	if (args.containsKey("from") ) {
		from = args.get("from");
	}
	
	/*this will return new arg value, overriding deprecated one, if it is present*/
	struct DeprecatedArgsHandler {
		static bool getArgValue( const rho::Hashtable<rho::String, rho::String>& args, const rho::String& newArgName, const rho::String& deprecatedArgName, rho::String& realArgValue ) {
			bool found = false;
			if ( args.containsKey(deprecatedArgName) ) {
				RAWLOG_WARNING2("'%s' argument is deprecated for search. Use '%s' instead.",deprecatedArgName.c_str(),newArgName.c_str());
				realArgValue = args.get(deprecatedArgName);
				found = true;
			}
			if ( args.containsKey(newArgName) ) {
				realArgValue = args.get(newArgName);
				found = true;
			}
			return found;
		}
	};
	
	
	String jsonSources;
	if ( DeprecatedArgsHandler::getArgValue(args,"sourceNames","source_names",jsonSources) ) {
		rho::json::CJSONEntry json(jsonSources.c_str());
		if ( json.isArray() ) {
			for( rho::json::CJSONArrayIterator array(json); !array.isEnd(); array.next()) {
				sources.push_back( array.getCurItem().getString() );
			}
		}
	}

	if (args.containsKey("offset")) {
		searchParams += "&offset=" + rho::net::URI::urlEncode(args.get("offset"));
	}
	
	rho::String maxResults;
	if ( DeprecatedArgsHandler::getArgValue(args,"maxResults","max_results",maxResults) ) {
		searchParams += "&max_results=" + rho::net::URI::urlEncode(maxResults);
	}
	
	
	rho::String jsonSearchParams;
	if ( DeprecatedArgsHandler::getArgValue(args,"searchParams","search_params",jsonSearchParams) ) {
		rho::json::CJSONEntry json(jsonSearchParams.c_str());
		if ( json.isObject() ) {
			for ( rho::json::CJSONStructIterator obj(json); !obj.isEnd(); obj.next() ) {
				rho::String key = rho::net::URI::urlEncode(obj.getCurKey());
				rho::String value = rho::net::URI::urlEncode(obj.getCurValue().getString());
				
				searchParams += "&search[" + key + "]=" + value;
			}
		}
	}
	
	rho::String strSyncChanges;
	if ( DeprecatedArgsHandler::getArgValue(args,"syncChanges","sync_changes",strSyncChanges) ) {
		syncChanges = (strSyncChanges=="true") || (strSyncChanges=="1");
	}
	
	rho::String strProgressStep;
	if ( DeprecatedArgsHandler::getArgValue(args,"progressStep","progress_step",strProgressStep) ) {
		progressStep = atoi(strProgressStep.c_str());
	}

	getSyncEngine().getNotify().setSearchNotification( new sync::CSyncNotification(oResult, true) );
	getSyncThread()->addQueueCommand(new sync::CSyncThread::CSyncSearchCommand(from,searchParams,sources,syncChanges,progressStep) );
		
	handleSyncResult(oResult);
}
Example #2
0
void CSystemImplBase::setNetworkStatusNotify( const rho::String& url, int poll_interval, rho::apiGenerator::CMethodResult& oResult)
{
    oResult.setRubyCallback(url);
    RHODESAPP().setNetworkStatusNotify( oResult, (int)poll_interval );
}