platform/shared/common/RhodesApp.cpp in rhodes-2.3.0 vs platform/shared/common/RhodesApp.cpp in rhodes-2.3.1.beta.1
- old
+ new
@@ -51,11 +51,11 @@
ui_created,
app_activated
};
public:
- CAppCallbacksQueue(IRhoClassFactory *factory);
+ CAppCallbacksQueue();
~CAppCallbacksQueue();
//void call(callback_t type);
friend class Command;
@@ -97,12 +97,12 @@
default:
return "UNKNOWN";
}
}
-CAppCallbacksQueue::CAppCallbacksQueue(IRhoClassFactory *factory)
- :CThreadQueue(factory), m_expected(local_server_started)
+CAppCallbacksQueue::CAppCallbacksQueue()
+ :CThreadQueue(), m_expected(local_server_started)
{
CThreadQueue::setLogCategory(getLogCategory());
//setPollInterval(1);
start(epNormal);
}
@@ -141,11 +141,11 @@
}
if (cmd->type > m_expected)
{
boolean bDuplicate = false;
- for( int i = 0; i < m_commands.size() ; i++)
+ for( int i = 0; i < (int)m_commands.size() ; i++)
{
if ( m_commands.elementAt(i) == cmd->type )
{
bDuplicate = true;
break;
@@ -179,40 +179,28 @@
m_expected = app_activated;
#endif
break;
case local_server_started:
- // Nothing
+ m_expected = ui_created;
break;
case ui_created:
{
- common::CAutoPtr<common::IRhoClassFactory> factory = rho_impl_createClassFactory();
- common::CAutoPtr<net::INetRequest> pNetRequest = factory->createNetRequest();
String strUrl = RHODESAPP().getBaseUrl();
strUrl += "/system/uicreated";
- NetResponse(resp, pNetRequest->pullData( strUrl, null ) );
+ NetResponse resp = getNetRequest().pullData( strUrl, null );
if ( !resp.isOK() )
LOG(ERROR) + "activate app failed. Code: " + resp.getRespCode() + "; Error body: " + resp.getCharData();
m_expected = app_activated;
}
break;
case app_activated:
{
-/* static bool navigatedToStartUrl = false;
- if (!navigatedToStartUrl)
- {
- LOG(INFO) + "navigate to first start url";
- RHODESAPP().navigateToUrl(RHODESAPP().getFirstStartUrl());
- navigatedToStartUrl = true;
- }*/
-
- common::CAutoPtr<common::IRhoClassFactory> factory = rho_impl_createClassFactory();
- common::CAutoPtr<net::INetRequest> pNetRequest = factory->createNetRequest();
String strUrl = RHODESAPP().getBaseUrl();
strUrl += "/system/activateapp";
- NetResponse(resp, pNetRequest->pullData( strUrl, null ) );
+ NetResponse resp = getNetRequest().pullData( strUrl, null );
if ( !resp.isOK() )
LOG(ERROR) + "activate app failed. Code: " + resp.getRespCode() + "; Error body: " + resp.getCharData();
m_expected = app_deactivated;
}
@@ -247,13 +235,11 @@
m_bExit = false;
m_bDeactivationMode = false;
m_bRestartServer = false;
//m_activateCounter = 0;
- m_ptrFactory = rho_impl_createClassFactory();
- m_NetRequest = m_ptrFactory->createNetRequest();
- m_appCallbacksQueue = new CAppCallbacksQueue(rho_impl_createClassFactory());
+ m_appCallbacksQueue = new CAppCallbacksQueue();
#if defined( OS_WINCE ) || defined (OS_WINDOWS)
//initializing winsock
WSADATA WsaData;
int result = WSAStartup(MAKEWORD(2,2),&WsaData);
@@ -273,16 +259,16 @@
void CRhodesApp::run()
{
LOG(INFO) + "Starting RhodesApp main routine...";
RhoRubyStart();
- rubyext::CGeoLocation::Create(m_ptrFactory);
+ rubyext::CGeoLocation::Create();
rho_db_init_attr_manager();
LOG(INFO) + "Starting sync engine...";
- sync::CSyncThread::Create(rho_impl_createClassFactory());
+ sync::CSyncThread::Create();
LOG(INFO) + "RhoRubyInitApp...";
RhoRubyInitApp();
rho_ruby_call_config_conflicts();
RHOCONF().conflictsResolved();
@@ -343,11 +329,11 @@
template <typename T>
class CRhoCallInThread : public common::CRhoThread
{
public:
CRhoCallInThread(T* cb)
- :CRhoThread(rho_impl_createClassFactory()), m_cb(cb)
+ :CRhoThread(), m_cb(cb)
{
start(epNormal);
}
private:
@@ -367,27 +353,25 @@
new CRhoCallInThread<T>(cb);
}
class CRhoCallbackCall
{
- common::CAutoPtr<common::IRhoClassFactory> m_ptrFactory;
String m_strCallback, m_strBody;
public:
- CRhoCallbackCall(const String& strCallback, const String& strBody, common::IRhoClassFactory* factory)
- :m_ptrFactory(factory), m_strCallback(strCallback), m_strBody(strBody)
+ CRhoCallbackCall(const String& strCallback, const String& strBody)
+ : m_strCallback(strCallback), m_strBody(strBody)
{}
void run(common::CRhoThread &)
{
- common::CAutoPtr<net::INetRequest> pNetRequest = m_ptrFactory->createNetRequest();
- common::CAutoPtr<net::INetResponse> presp = pNetRequest->pushData( m_strCallback, m_strBody, null );
+ getNetRequest().pushData( m_strCallback, m_strBody, null );
}
};
void CRhodesApp::runCallbackInThread(const String& strCallback, const String& strBody)
{
- rho_rhodesapp_call_in_thread(new CRhoCallbackCall(strCallback, strBody, rho_impl_createClassFactory() ) );
+ rho_rhodesapp_call_in_thread(new CRhoCallbackCall(strCallback, strBody ) );
}
static void callback_activateapp(void *arg, String const &strQuery)
{
rho_ruby_activateApp();
@@ -441,11 +425,11 @@
}
void CRhodesApp::callUiDestroyedCallback()
{
String strUrl = m_strHomeUrl + "/system/uidestroyed";
- NetResponse(resp,getNet().pullData( strUrl, null ));
+ NetResponse resp = getNetRequest().pullData( strUrl, null );
if ( !resp.isOK() )
{
LOG(ERROR) + "UI destroy callback failed. Code: " + resp.getRespCode() + "; Error body: " + resp.getCharData();
}
}
@@ -478,23 +462,25 @@
// All such operation will throw exception in ruby code when calling in 'deactivate' mode.
m_bDeactivationMode = true;
m_appCallbacksQueue->addQueueCommand(new CAppCallbacksQueue::Command(CAppCallbacksQueue::app_deactivated));
String strUrl = m_strHomeUrl + "/system/deactivateapp";
- NetResponse(resp,getNet().pullData( strUrl, null ));
+ NetResponse resp = getNetRequest().pullData( strUrl, null );
if ( !resp.isOK() )
{
LOG(ERROR) + "deactivate app failed. Code: " + resp.getRespCode() + "; Error body: " + resp.getCharData();
}else
{
const char* szData = resp.getCharData();
boolean bStop = szData && strcmp(szData,"stop_local_server") == 0;
if (bStop)
{
+#if !defined( OS_WINCE ) && !defined (OS_WINDOWS)
LOG(INFO) + "Stopping local server.";
m_httpServer->stop();
+#endif
}
}
m_bDeactivationMode = false;
}
@@ -513,11 +499,11 @@
strBody = "status=error&message=" + strError;
}else
strBody = "status=ok&image_uri=db%2Fdb-files%2F" + strImagePath;
strBody += "&rho_callback=1";
- NetRequest( getNet().pushData( strCallbackUrl, strBody, null ) );
+ getNetRequest().pushData( strCallbackUrl, strBody, null );
}
void CRhodesApp::callSignatureCallback(String strCallbackUrl, const String& strSignaturePath,
const String& strError, boolean bCancel )
{
@@ -531,11 +517,11 @@
strBody = "status=error&message=" + strError;
}else
strBody = "status=ok&signature_uri=db%2Fdb-files%2F" + strSignaturePath;
strBody += "&rho_callback=1";
- NetRequest( getNet().pushData( strCallbackUrl, strBody, null ) );
+ getNetRequest().pushData( strCallbackUrl, strBody, null );
}
void CRhodesApp::callDateTimeCallback(String strCallbackUrl, long lDateTime, const char* szData, int bCancel )
{
strCallbackUrl = canonicalizeRhoUrl(strCallbackUrl);
@@ -550,29 +536,29 @@
strBody += "&opaque=";
strBody += szData;
}
strBody += "&rho_callback=1";
- NetRequest( getNet().pushData( strCallbackUrl, strBody, null ) );
+ getNetRequest().pushData( strCallbackUrl, strBody, null );
}
void CRhodesApp::callBluetoothCallback(String strCallbackUrl, const char* body) {
strCallbackUrl = canonicalizeRhoUrl(strCallbackUrl);
String strBody = body;
strBody += "&rho_callback=1";
- NetRequest( getNet().pushData( strCallbackUrl, strBody, null ) );
+ getNetRequest().pushData( strCallbackUrl, strBody, null );
}
void CRhodesApp::callPopupCallback(String strCallbackUrl, const String &id, const String &title)
{
if ( strCallbackUrl.length() == 0 )
return;
strCallbackUrl = canonicalizeRhoUrl(strCallbackUrl);
String strBody = "button_id=" + id + "&button_title=" + title;
strBody += "&rho_callback=1";
- NetRequest( getNet().pushData( strCallbackUrl, strBody, null ) );
+ getNetRequest().pushData( strCallbackUrl, strBody, null );
}
static void callback_syncdb(void *arg, String const &/*query*/ )
{
rho_sync_doSyncAllSources(1);
@@ -640,11 +626,11 @@
{
strUrl += "msgid=";
strUrl += szName;
}
- NetResponse(resp,getNet().pullData( strUrl, null ));
+ NetResponse resp = getNetRequest().pullData( strUrl, null );
if ( !resp.isOK() )
{
LOG(ERROR) + "getRhoMessage failed. Code: " + resp.getRespCode() + "; Error body: " + resp.getCharData();
m_strRhoMessage = "";
}
@@ -973,11 +959,11 @@
oItem.m_strFilePath = LOGCONF().getLogFilePath();
oItem.m_strContentType = "application/octet-stream";
boolean bOldSaveToFile = LOGCONF().isLogToFile();
LOGCONF().setLogToFile(false);
- NetResponse( resp, getNet().pushMultipartData( strQuery, oItem, &(rho::sync::CSyncThread::getSyncEngine()), null ) );
+ NetResponse resp = getNetRequest().pushMultipartData( strQuery, oItem, &(rho::sync::CSyncThread::getSyncEngine()), null );
LOGCONF().setLogToFile(bOldSaveToFile);
if ( !resp.isOK() )
{
LOG(ERROR) + "send_log failed : network error - " + resp.getRespCode() + "; Body - " + resp.getCharData();
@@ -1043,12 +1029,11 @@
String strBody = strData + "&rho_callback=1";
if ( m_strPushCallbackParams.length() > 0 )
strBody += "&" + m_strPushCallbackParams;
- common::CAutoPtr<net::INetRequest> pNetRequest = m_ptrFactory->createNetRequest();
- NetResponse(resp,pNetRequest->pushData( m_strPushCallback, strBody, null ));
+ NetResponse resp = getNetRequest().pushData( m_strPushCallback, strBody, null );
if (!resp.isOK())
LOG(ERROR) + "Push notification failed. Code: " + resp.getRespCode() + "; Error body: " + resp.getCharData();
else
{
const char* szData = resp.getCharData();
@@ -1082,13 +1067,11 @@
strBody += "°rees="; strBody += convertToStringA(degrees);
if ( m_strScreenRotationCallbackParams.length() > 0 )
strBody += "&" + m_strPushCallbackParams;
- common::CAutoPtr<net::INetRequest> pNetRequest = m_ptrFactory->createNetRequest();
- NetResponse(resp, pNetRequest->pushData( m_strScreenRotationCallback, strBody, null));
-
+ NetResponse resp = getNetRequest().pushData( m_strScreenRotationCallback, strBody, null);
if (!resp.isOK()) {
LOG(ERROR) + "Screen rotation notification failed. Code: " + resp.getRespCode() + "; Error body: " + resp.getCharData();
}
}
}
@@ -1126,13 +1109,11 @@
}
url = canonicalizeRhoUrl(url);
if (callback)
{
- common::CAutoPtr<net::INetRequest> pNetRequest = m_ptrFactory->createNetRequest();
- NetResponse(resp, pNetRequest->pushData( url, "rho_callback=1", null ));
- (void)resp;
+ getNetRequest().pushData( url, "rho_callback=1", null );
}
else
navigateToUrl(url);
}
@@ -1386,18 +1367,15 @@
return RHODESAPP().sendLog();
}
void rho_net_request(const char *url)
{
- rho::common::CAutoPtr<rho::common::IRhoClassFactory> factory = rho_impl_createClassFactory();
- rho::common::CAutoPtr<rho::net::INetRequest> request = factory->createNetRequest();
- request->pullData(url, null);
+ getNetRequest().pullData(url, null);
}
-void rho_net_request_with_data(const char *url, const char *str_body) {
- rho::common::CAutoPtr<rho::common::IRhoClassFactory> factory = rho_impl_createClassFactory();
- rho::common::CAutoPtr<rho::net::INetRequest> request = factory->createNetRequest();
- request->pushData(url, str_body, null);
+void rho_net_request_with_data(const char *url, const char *str_body)
+{
+ getNetRequest().pushData(url, str_body, null);
}
void rho_rhodesapp_load_url(const char *url)
{
RHODESAPP().loadUrl(url);