Exemple #1
0
void CSyncCenter::updateTotalUpdate(uint32_t nUpdated)
{
    CacheManager* pCacheManager = CacheManager::getInstance();
    CacheConn* pCacheConn = pCacheManager->GetCacheConn("unread");
    if (pCacheConn) {
        last_update_lock_.lock();
        m_nLastUpdate = nUpdated;
        last_update_lock_.unlock();
        string strUpdated = int2string(nUpdated);
        pCacheConn->set("total_user_update", strUpdated);
        pCacheManager->RelCacheConn(pCacheConn);
    }
    else
    {
        log("no cache connection to get total_user_updated");
    }
}
Exemple #2
0
bool CMessageModel::resetMsgId(uint32_t nRelateId)
{
    bool bRet = false;
    uint32_t nMsgId = 0;
    CacheManager* pCacheManager = CacheManager::getInstance();
    CacheConn* pCacheConn = pCacheManager->GetCacheConn("unread");
    if(pCacheConn)
    {
        string strKey = "msg_id_" + int2string(nRelateId);
        string strValue = "0";
        string strReply = pCacheConn->set(strKey, strValue);
        if(strReply == strValue)
        {
            bRet = true;
        }
        pCacheManager->RelCacheConn(pCacheConn);
    }
    return bRet;
}
 void setDevicesToken(CImPdu* pPdu, uint32_t conn_uuid)
 {
     IM::Login::IMDeviceTokenReq msg;
     IM::Login::IMDeviceTokenRsp msgResp;
     if(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength()))
     {
         uint32_t nUserId = msg.user_id();
         string strToken = msg.device_token();
         CImPdu* pPduResp = new CImPdu;
         CacheManager* pCacheManager = CacheManager::getInstance();
         CacheConn* pCacheConn = pCacheManager->GetCacheConn("token");
         if (pCacheConn)
         {
             IM::BaseDefine::ClientType nClientType = msg.client_type();
             string strValue;
             if(IM::BaseDefine::CLIENT_TYPE_IOS == nClientType)
             {
                 strValue = "ios:"+strToken;
             }
             else if(IM::BaseDefine::CLIENT_TYPE_ANDROID == nClientType)
             {
                 strValue = "android:"+strToken;
             }
             else
             {
                 strValue = strToken;
             }
             
             string strOldValue = pCacheConn->get("device_"+int2string(nUserId));
             
             if(!strOldValue.empty())
             {
                 size_t nPos = strOldValue.find(":");
                 if(nPos!=string::npos)
                 {
                     string strOldToken = strOldValue.substr(nPos + 1);
                     string strReply = pCacheConn->get("device_"+strOldToken);
                     if (!strReply.empty()) {
                         string strNewValue("");
                         pCacheConn->set("device_"+strOldToken, strNewValue);
                     }
                 }
             }
             
             pCacheConn->set("device_"+int2string(nUserId), strValue);
             string strNewValue = int2string(nUserId);
             pCacheConn->set("device_"+strToken, strNewValue);
         
             log("setDeviceToken. userId=%u, deviceToken=%s", nUserId, strToken.c_str());
             pCacheManager->RelCacheConn(pCacheConn);
         }
         else
         {
             log("no cache connection for token");
         }
         
         log("setDeviceToken. userId=%u, deviceToken=%s", nUserId, strToken.c_str());
         msgResp.set_attach_data(msg.attach_data());
         msgResp.set_user_id(nUserId);
         pPduResp->SetPBMsg(&msgResp);
         pPduResp->SetSeqNum(pPdu->GetSeqNum());
         pPduResp->SetServiceId(IM::BaseDefine::SID_LOGIN);
         pPduResp->SetCommandId(IM::BaseDefine::CID_LOGIN_RES_DEVICETOKEN);
         CProxyConn::AddResponsePdu(conn_uuid, pPduResp);
     }
     else
     {
         log("parse pb failed");
     }
 }