void BGApp::networkConnectionChanged(bool isConnected) { SDL_mutexP(this->_mutex); bool runnerActive = (this->_xmpprunner) != NULL && (this->_xmpprunner->_connection != NULL); bool registered = (!ApplicationData::_chatUserId.empty()); _LOGDATA("BGApp sees wifi changed to %d with active runnner %d and registered %d ", isConnected, runnerActive, registered); this->_isNetworkConnected = isConnected; if ((isConnected) && (this->_chatState->_state == ChatState::CHAT_STATE_SOCKET_CONNECTING)) { Uint32 curStateHeld = (time(NULL) - this->_chatState->_time_changed); if ((curStateHeld > ChatState::MAX_SILENT_INTERVAL) && ((Uint32) ((time(NULL) - this->_lastXMPPRunnerKill)) > (3 * ChatState::MAX_SILENT_INTERVAL))) { XmppRunner* oldRunner = this->_xmpprunner; XmppRunner* newRunner = new XmppRunner(this); if (oldRunner != NULL && oldRunner->killWithConfirmation()) { _LOGDATA("killed old fun runner"); this->_xmpprunner = newRunner; this->_chatState->setState(ChatState::CHAT_STATE_DISCONNECTED); _xmppthread = SDL_CreateThread(XmppRunner::startXmppThreadCallback, this->_xmpprunner); this->_lastXMPPRunnerKill = time(NULL); } else { _LOGDATA("attempted fun runner kill was denied"); } } } if (isConnected && (this->_xmpprunner != NULL) && (this->_xmpprunner->_connection == NULL) && (registered)) { _LOGDATA("kicking off delayed internet connect attempt"); SDL_CreateThread(BGApp::doConnect1TrheadCallBack, this); } SDL_mutexV(this->_mutex); }
void CFileSelectDialog::ScanDir() { _LOG(_L("0")); TInt i=0; CDir* results=NULL; TFindFile findFiles(iFs); TBuf<5> mask(_L("*")); findFiles.FindWildByDir(mask,iCurrentPath,results); if (results==NULL){return;} _LOG(_L("2")); for (i=0;i<results->Count();i++) { _LOGDATA(_L("3 %d"),i); if (((TEntry)(*results)[i]).IsDir()) { TBuf<255> buf; buf.Copy(_L("[")); buf.Append(((TEntry)(*results)[i]).iName); buf.Append(_L("]")); iArray->AppendL(buf);} } if (iType!=EFolder) { for (i=0;i<results->Count();i++) { _LOGDATA(_L("4 %d"),i); if ((!((TEntry)(*results)[i]).IsDir())&&((TEntry)(*results)[i]).iName.Match(iMask)!=KErrNotFound) {iArray->AppendL(((TEntry)(*results)[i]).iName);} } } _LOG(_L("Exit from ScanDir")); }
TInt CFileSelectDialog::Show() { _LOG(_L("CFileSelectDialog::Show()")); TInt sel=0; CDesCArray* itemList = new (ELeave) CDesCArrayFlat(3); if (iCurrentPath.Compare(_L(""))!=0){if (iType==EFolder){iArray->InsertL(0,_L("Select folder"));}iArray->InsertL(0,_L("..."));} _LOGDATA(_L("Length of array: %d"),iArray->Count()); for (TInt i=0;i<iArray->Count();i++) { TBuf<255> ItemTxt; ItemTxt.Copy(_L("0\t")); ItemTxt.Append(iArray->MdcaPoint(i)); ItemTxt.Append(_L("\t\t")); itemList->AppendL(ItemTxt); _LOGDATA(_L("Item: %S"),&iArray->MdcaPoint(i)); } _LOG(_L("Will create dialog")); SetItemTextArray(itemList); ListBox()->HandleItemAdditionL(); Layout(); ListBox()->SetCurrentItemIndex(0); ListBox()->DrawNow(); DrawDeferred(); }
int ChatState::reconnectTaskCallBack(void* param) { Uint32 newDelay = (Uint32) param; while (true) { SDL_Delay(newDelay); ChatState* _cs = ChatState::getState(); try { SDL_mutexP(_cs->_inflightLock); if (_cs->_inflightRecons > 0) _cs->_inflightRecons--; SDL_mutexV(_cs->_inflightLock); if (_cs->_state == CHAT_STATE_DISCONNECTED) { _LOGDATA("ReconnectTask woke up and is trying to connect"); bool res = _cs->doConnect(TRIGGER_RECONNECT); if ((!res) && (_cs->_state == CHAT_STATE_DISCONNECTED)) { Uint32 delay = _cs->processFailInternal(); if (delay > 0) { newDelay = delay; continue; } } } else { _LOGDATA("ReconnectTask woke up but it looks like we're already connected or connecting."); } } catch (exception& ex) { _LOGDATA("ReconnectTask blowup: %s", ex.what()); } break; } return 0; }
void BGApp::initialize() { SDL_mutexP(this->_mutex); if (this->_initialized) return; _LOGDATA("bg initializing chat state"); this->_chatState = ChatState::initialize(); this->_chatState->_startupTaskState |= 1; _LOGDATA("bg creating fun runner"); this->_xmpprunner = new XmppRunner(this); _LOGDATA("bg starting fun runner thread in pause"); _xmppthread = SDL_CreateThread(XmppRunner::startXmppThreadCallback, this->_xmpprunner); if (_xmppthread == NULL) { _LOGDATA("No se puede crear el thread para llamar a XmppRunner::startXmppThreadCallback"); } this->_chatState->_startupTaskState |= 32; this->_initialized = true; if (!ApplicationData::_chatUserId.empty()) { this->_myPlainJid = ApplicationData::_chatUserId + "@" + "s.whatsapp.net"; if (SDL_CreateThread(BGApp::initialXMPPConnectionThreadCallback, this) == NULL) { _LOGDATA("No se puede crear el thread para llmar a BGApp::initialXMPPConnectionThreadCallback"); } } SDL_mutexV(this->_mutex); }
TBool CFileSelectDialog::OkToExitL(TInt aButton) { TInt selected=ListBox()->CurrentItemIndex(); _LOGDATA(_L("Selected: %d"),selected); if (aButton==EAknSoftkeyCancel){return ETrue;} if (iCurrentPath.Compare(_L(""))==0) { _LOG(_L("(iCurrentPath.Compare(_L(""))==0)")); _LOG(iCurrentPath); iCurrentPath.Append(iArray->MdcaPoint(selected)); iCurrentPath.Append(_L("\\")); if (BaflUtils::PathExists(iFs,iCurrentPath)){Update();Show();return EFalse;} //Update(); } else if ((selected>1&&iType==EFolder)||(selected>0&&iType==EFile)) { _LOG(_L("((selected>1)&&(iCurrentPath.Compare(_L(""))!=0))")); _LOG(iCurrentPath); TBuf<255> temp(iArray->MdcaPoint(selected)); TChar c1='[',c2=']'; if (temp[0]==c1&&temp[temp.Length()-1]==c2) {temp.Copy(temp.Left(temp.Length()-1));temp.Copy(temp.Right(temp.Length()-1));} _LOGDATA(_L("Temp: %S"),&temp); iCurrentPath.Append(temp); iCurrentPath.Append(_L("\\")); _LOGDATA(_L("CurrPath after append: %S"),&iCurrentPath); CEikonEnv::Static()->InfoMsg(iCurrentPath); User::After(500000); if (BaflUtils::PathExists(iFs,iCurrentPath)){Update();Show();return EFalse;} else if (BaflUtils::FileExists(iFs,iCurrentPath.Left(iCurrentPath.Length()-1))) { iResult.Copy(iCurrentPath.Left(iCurrentPath.Length()-1)); return ETrue; } } else if (selected==0) { _LOG(_L("(selected==0&&(iCurrentPath.Compare(_L(""))!=0))")); _LOG(iCurrentPath); TParse p; iFs.Parse(iCurrentPath, p); _LOG(_L("Will pop now")) TInt err=p.PopDir(); if (err!=KErrNone||iCurrentPath.Compare(p.FullName())==0){iCurrentPath.Copy(_L(""));} else {iCurrentPath.Copy(p.FullName());} //if (iCurrentPath.Compare(_L(""))!=0) Update();Show();return EFalse; } else if (selected==1&&iType==EFolder&&(iCurrentPath.Compare(_L(""))!=0)) { _LOG(_L("Will update result")); iResult.Copy(iCurrentPath); return ETrue; } Update();Show();return EFalse; }
void BGApp::onIsTyping(const std::string& jid, bool what) { std::string nakedJid = WAConnection::removeResourceFromJid(jid); int state; if (what) { state = 0; _LOGDATA("is typing: %s", nakedJid.c_str()); } else { state = 1; _LOGDATA("stop typing: %s", nakedJid.c_str()); } sendContactInfoToFG(nakedJid, state, (time_t) 0); }
int ChatState::sentinelTaskCallBack(void* param) { Uint32 newDelay = (Uint32) param; while (true) { SDL_Delay(newDelay); try { ChatState* _cs = ChatState::getState(); if (_cs->_state == CHAT_STATE_CONNECTED) { XmppRunner* xmppRunner = BGApp::getInstance()->_xmpprunner; if (xmppRunner != NULL) { WAConnection* fConn = xmppRunner->_connection; if (fConn != NULL) { int quietInterval = (int) difftime(time(NULL), fConn->lastTreeRead); if (quietInterval >= MAX_SILENT_INTERVAL) { _LOGDATA("sending ping after quiet on xmpp conn for 1QI mins %d", quietInterval / 60); try { fConn->sendPing(); } catch (exception& ex) { _LOGDATA("ChatState: error sending ping! %s", ex.what()); } } else { newDelay = scheduleSentinelTask((Uint32) ((MAX_SILENT_INTERVAL - quietInterval) * 1000)); continue; } } } else { _LOGDATA("sentinel sees null fun conn in connected state"); } } else if (_cs->_state == CHAT_STATE_SOCKET_CONNECTING) { time_t curStateHeld = (time(NULL) - _cs->_time_changed); _LOGDATA("LOCKED? sentinel sees SOCKETING_CONNECTING held for seconds: %d", (curStateHeld)); } else if (_cs->_state == CHAT_STATE_XMPP_CONNECTING) { time_t curStateHeld = (time(NULL) - _cs->_time_changed); _LOGDATA("LOCKED? sentinel sees XMPP_CONNECTING held for seconds: %d", (curStateHeld)); } else if (_cs->_state == CHAT_STATE_DISCONNECTED) { _LOGDATA("sentinel sees DISCONNECTED, inflight recons: %d", (_cs->_inflightRecons)); } else { if (_cs->_state == CHAT_STATE_PASSWORD_FAIL) { _LOGDATA("sentinel sees PASSWD_FAIL, no more sentinel"); break; } _LOGDATA("sentinel sees unknown chat state %d", (_cs->_state)); } newDelay = scheduleSentinelTask((Uint32) (MAX_SILENT_INTERVAL * 1000)); continue; } catch (exception& ex) { _LOGDATA("SentinelTask blowup: %s", ex.what()); break; } } return 0; }
int BGApp::initialXMPPConnectionThreadCallback(void *data) { SDL_Delay(4000L); _LOGDATA("waking up xmpp"); ((BGApp*) data)->_chatState->doConnect(ChatState::TRIGGER_APP_START); return 0; }
void BGApp::finalize() { SDL_mutexP(this->_mutex); if (this->_initialized) { if (this->_xmpprunner != NULL && this->_xmpprunner->_connection != NULL) { try { this->_xmpprunner->_connection->sendClose(); } catch (exception& ex) { _LOGDATA("Error sending BGApp::finalize:sendingClose: %s", ex.what()); } } if (this->_xmpprunner != NULL) this->_xmpprunner->killWithConfirmation(); SDL_KillThread(this->_xmppthread); ChatState::finalize(); if (this->_xmpprunner != NULL) delete _xmpprunner; this->_lastXMPPRunnerKill = time(NULL); this->_chatState = NULL; this->_xmpprunner = NULL; this->_initialized = false; } SDL_mutexV(this->_mutex); }
Uint32 ChatState::scheduleSentinelTask(Uint32 delay) { // _sentinelThread = SDL_CreateThread(ChatState::sentinelTaskCallBack, (void*) delay); // if (_sentinelThread == NULL) // _LOGDATA("Error adding timer sentinelTask"); _LOGDATA("new SentinelTask scheduled for wakeup mins from now: %d", delay / 60000); return delay; }
void BGApp::onAvailable(const std::string& jid, bool what) { std::string nakedJid = WAConnection::removeResourceFromJid(jid); time_t lastSeen; int state; if (what) { lastSeen = 0L; state = 1; _LOGDATA("here: %s", nakedJid.c_str()); } else { lastSeen = time(NULL); state = 2; _LOGDATA("gone: %s", nakedJid.c_str()); } sendContactInfoToFG(nakedJid, state, lastSeen); }
void BGApp::onLastSeen(const std::string& jid, int seconds, std::string* status) { std::string nakedJid = WAConnection::removeResourceFromJid(jid); _LOGDATA("last seen info for %s, %d seconds: status %s", nakedJid.c_str(), seconds, (status == NULL?"":status->c_str())); time_t lastSeen = time(NULL) - (time_t) seconds; this->sendContactInfoToFG(nakedJid, 2, lastSeen); }
bool ChatState::doConnect(int trigger) { if (this->_state == CHAT_STATE_DISCONNECTED) { if (BGApp::getInstance()->_xmpprunner != NULL) { SDL_mutexP(this->_connectLock); _LOGDATA("got lock, with trigger %d connecting to chat [%d total drops]", trigger, this->_totalDrops); this->_last_login_trigger = trigger; BGApp::getInstance()->_xmpprunner->wakeUp(); this->_totalDrops += 1; SDL_mutexV(this->_connectLock); return true; } else { _LOGDATA("no XmppRunner available..."); } } _LOGDATA("doConnect bailing on non-disconnected state %s", STATE_WORDS[this->_state].c_str()); return false; }
void BGApp::onParticipatingGroups(const std::vector<string>& groups) { _LOGDATA("GRP particpating in %d groups", groups.size()); WAConnection* fconn = this->_xmpprunner->_connection; if (fconn != NULL) { this->sendParticipatingGroupsToFG(groups); fconn->sendClearDirty("groups"); } }
void ChatState::setState(int new_state) { _LOGDATA("ChatState change %s -> %s", STATE_WORDS[this->_state].c_str(), STATE_WORDS[new_state].c_str()); this->_state = new_state; this->_time_changed = time(NULL); if (new_state == CHAT_STATE_CONNECTED) { this->_consecFails = 0; BGApp::getInstance()->sendNewStateToFG(new_state); } }
void BGApp::onPing(const std::string& id) throw (WAException) { WAConnection* fconn = this->_xmpprunner->_connection; if (fconn != NULL) { try { _LOGDATA("got ping id %s sending pong", id.c_str()); fconn->sendPong(id); } catch (exception& ex) { } } }
Uint32 ChatState::processFailInternal() { _LOGDATA("entering processFail with state %s and inflights %d", STATE_WORDS[this->_state].c_str(), this->_inflightRecons); SDL_mutexP(this->_inflightLock); if (this->_inflightRecons > 0) { _LOGDATA("ProcessFail finds inflight already, no new task."); SDL_mutexV(this->_inflightLock); return 0; } this->_inflightRecons += 1; SDL_mutexV(this->_inflightLock); unsigned int mins = chooseRetryMins(); this->_consecFails += 1; if ((this->_consecFails > RETRY_INTERVALS_LEN) && (this->_xmpp_expire_date < time(NULL))) { _LOGDATA("expired and at the end of all intervals... not scheduling another delayed connect"); return 0; } srand(time(NULL)); unsigned int jitter = rand() % 10000; _LOGDATA("ProcessFail after consec fail %d, launching timed chat connector with delay %d mins %d seconds of jitter", this->_consecFails, mins, jitter); return (60000 * mins + jitter); }
void CFileSelectDialog::Update() { iArray->Reset(); _LOG(_L("Update")); _LOGDATA(_L("CurrDir at enter: %S"),&iCurrentPath); if( iCurrentPath.Compare(_L(""))==0) { _LOG(_L("( iCurrentPath.Compare(_L(""))==0)")); _LOG(_L("Will load drive list")); LoadDriveList(); } else {_LOG(_L("Will scan dir"));ScanDir();} }
void CSliderForDialog::HandlePointerEventL(const TPointerEvent& aEvent) { TInt offset=0; _LOG(_L("PointerEvent")); if (aEvent.iType==aEvent.EButton1Down) { _LOG(_L("PointerEventDown")); iPenDownPos=aEvent.iPosition; } else if (aEvent.iType==aEvent.EDrag) { _LOG(_L("PointerEventMove")); iDragged=ETrue; } else if (aEvent.iType==aEvent.EButton1Up) { _LOG(_L("PointerEventUp")); } TReal percent=(TReal)aEvent.iPosition.iX/((TReal)(Size().iWidth-40)); TReal r_new_val=percent*(iMaxVal-iMinVal); TReal rval; Math::Round(rval,r_new_val,0); TInt i_new_val=(TInt)rval; offset=i_new_val-iValue; TBuf<255> a; TRealFormat rf; a.Num(percent,rf); a.Append(_L(", ")); a.AppendNum(r_new_val,rf); a.Append(_L(", ")); a.AppendNum(offset); _LOGDATA(_L("percent,r_newval,offset %S"),&a); if (iDragged) { iValue+=offset; if(iValue>iMaxVal){iValue =iMaxVal;} if(iValue<iMinVal){iValue = iMinVal;} DrawNow(); iPenDownPos=aEvent.iPosition; } iDragged=EFalse; CCoeControl::HandlePointerEventL(aEvent); }
ChatState* ChatState::initialize() { if (_instance != NULL) { if (_sentinelThread != NULL) SDL_KillThread(_sentinelThread); if (_reconnectThread != NULL) SDL_KillThread(_reconnectThread); delete _instance; } ChatState* curState = new ChatState(); curState->setState(ChatState::CHAT_STATE_DISCONNECTED); _instance = curState; if (SEND_PING) { _sentinelThread = SDL_CreateThread(ChatState::sentinelTaskCallBack, (void*) ((Uint32) (MAX_SILENT_INTERVAL * 1000))); if (_sentinelThread == NULL) _LOGDATA("Error adding timer sentinelTask"); } return curState; }
void BGApp::onPingResponseReceived() { _LOGDATA("ping response received"); }
void BGApp::onOwningGroups(const std::vector<string>& groups) { if (!groups.empty()) _LOGDATA("GRP seeing owning groups %d", groups.size()); }
std::string BGApp::testLogin(const std::string& userId, const std::string& password, const std::string& pushName) { _LOGDATA("Test Login"); std::string usePushName = pushName; MySocketConnection* conn = NULL; WAConnection* connection = NULL; WALogin* login = NULL; try { std::string socketURL = WHATSAPP_LOGIN_SERVER; if (usePushName.empty()) usePushName = "HP Webos user"; bool done = false; int usedPorts = 0; std::string resource; do { int socketPort = XmppRunner::PORTS[XmppRunner::LAST_USED_PORT_INDEX]; resource = std::string() + ACCOUNT_RESOURCE; // + "-" + Utilities::intToStr(socketPort); try { conn = new MySocketConnection(socketURL, socketPort); done = true; } catch (WAException& ex) { usedPorts++; XmppRunner::LAST_USED_PORT_INDEX = (XmppRunner::LAST_USED_PORT_INDEX + 1) % XmppRunner::NUM_PORTS; if (usedPorts == XmppRunner::NUM_PORTS) { throw ex; } } } while (!done); connection = new WAConnection(NULL, NULL); login = new WALogin(connection, new BinTreeNodeReader(connection, conn, WAConnection::dictionary, WAConnection::DICTIONARY_LEN), new BinTreeNodeWriter(connection, conn, WAConnection::dictionary, WAConnection::DICTIONARY_LEN), "s.whatsapp.net", userId, resource, base64_decode(password), usePushName); connection->setVerboseId(true); std::vector<unsigned char>* existingChallenge = new std::vector<unsigned char>(0); std::vector<unsigned char>* nextChallenge = login->login(*existingChallenge); connection->setLogin(login); delete existingChallenge; delete nextChallenge; } catch (WAException& ex) { _LOGDATA("Error test login: %s, %d, %d", ex.what(), ex.type, ex.subtype); time_t expire_date; if (login != NULL) expire_date = login->expire_date; if ((connection->getLogin() == NULL) && (login != NULL)) delete login; if (conn != NULL) delete conn; if (connection != NULL) delete connection; if (ex.type == WAException::CORRUPT_STREAM_EX) return "corrupt stream"; else if ((ex.type == WAException::LOGIN_FAILURE_EX) && (ex.subtype == WAException::LOGIN_FAILURE_EX_TYPE_PASSWORD)) { return "password failure"; } else if ((ex.type == WAException::LOGIN_FAILURE_EX) && (ex.subtype == WAException::LOGIN_FAILURE_EX_TYPE_EXPIRED)) { return "account expired on " + std::string(ctime(&expire_date)); } else { return "connection error"; } } if (conn != NULL) delete conn; if (connection != NULL) delete connection; return "ok"; }
void BGApp::onLeaveGroup(const std::string& from) { _LOGDATA("GRP %s left group", from.c_str()); }
void BGApp::onClientConfigReceived(const std::string& push_id) { _LOGDATA("client config received with id %s", push_id.c_str()); }