BOOL CLoginWindow::Receive(SkinChangedParam param) { try { if(!IsWindow()) return FALSE; sLog("CLoginWindow::Receive"); CDuiString bgimage_ = param.bgimage; DWORD bkcolor_ = param.bkcolor; CControlUI* background = GetPaintMgr()->GetRoot(); if (background != NULL&&0!=bgimage_.Compare(background->GetBkImage())) { if (!param.bgimage.IsEmpty()) { CDuiString sBkImage = bgimage_; background->SetBkImage(sBkImage); } else background->SetBkImage(_T("")); background->SetBkColor(param.bkcolor); } return TRUE; } catch (...) { sLogError("CLoginWindow::Receive"); throw _T("CLoginWindow::Receive"); return FALSE; } }
bool CServer::Init( const char * ip, unsigned int port, IConnectorSink* sink ) { // request socket net_shutdown_listener_ = net_service_impl_->RegisterShutdownEventListener(std::bind(&IServer::Shutdown, shared_from_this())); sink_ = sink; // config address struct sockaddr_in sin; sin.sin_family = AF_INET; sin.sin_addr.s_addr = INADDR_ANY; sin.sin_port = htons(port); evconn_listener_ = evconnlistener_new_bind( net_service_impl_->ev_base(), OnAccepted, this, LEV_OPT_THREADSAFE | LEV_OPT_REUSEABLE, ACCEPTOR_LISTEN_BACKLOG, (sockaddr*)&sin, sizeof(sockaddr_in)); if(evconn_listener_ == 0) { net_shutdown_listener_.Disconnect(); sLogError("server(%s:%d) evconnlistener_new_bind failed.", ip, port); return false; } evconnlistener_set_error_cb(evconn_listener_, OnAcceptError); local_ip_ = ip; local_port_ = port; sLogInfo("server(%s:%d) start", local_ip_.c_str(), local_port_); return true; }
CHttpServiceImpl::CHttpServiceImpl( void ) { CURLcode code = curl_global_init(CURL_GLOBAL_DEFAULT); if (code != CURLE_OK) { sLogError("Failed to global init default [%d]\n", code); } }
bool CHttpServiceImpl::GetUrlData( const std::string& url, std::string& content ) { CURL *curl = 0; CURLcode code; std::string http_content; char error[CURL_ERROR_SIZE]; // 创建curl; curl = curl_easy_init(); if (curl == 0) { sLogError("Failed to create CURL connection\n"); return false; } // 初始化curl; if (!_CurlInit(curl, url.c_str(), http_content, error)) { sLogError("Failed to init curl\n"); curl_easy_cleanup(curl); return false; } // 执行curl; code = curl_easy_perform(curl); if (code != CURLE_OK) { sLogError("Failed to get '%s' [%s]\n", url.c_str(), error); curl_easy_cleanup(curl); return false; } // 获取curl信息; long retcode = 0; bool return_code = false; code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &retcode); if ( (code == CURLE_OK) && retcode == 200 ) { content = http_content; return_code = true; } else { sLogError("Failed to get '%s' [%d]", url.c_str(), retcode); } curl_easy_cleanup(curl); return return_code; }
//------------------------------------------------------------------ DWORD WINAPI down_http_file::httpfileload_proc(void* p_param) { down_task* p_task = (down_task*)p_param; assert(p_task); if(!p_task) return 0; // CurlData* pdata = new CurlData(); // pdata->SetURL(mci::unicode_2_utf8(p_task->s_url).c_str()); // pdata->SetFileName(mci::unicode_2_ansi(p_task->s_local_file_down).c_str()); // pdata->h_notify_wnd = p_task->h_notify_wnd; // pdata->n_notify_msg = p_task->n_notify_msg; // pdata->n_lparam = p_task->n_lparam; // pdata->n_wparam = p_task->n_wparam; // pdata->bshowprogress = true; // // int e_result = HttpManagerProto::Instance()->DoHttpGet(pdata); down_result_e e_result = http_file_down(p_task->s_url, p_task->s_local_file_down); if(e_result == dr_success) { switch (p_task->task_type) { case TT_NORMAL: { } break; default: break; } if(!p_task->s_local_file_normal.IsEmpty()) { BOOL bResult = ::MoveFile(p_task->s_local_file_down,p_task->s_local_file_normal); bResult ? sLog("::MoveFile[%s ---> %s]", mci::unicode_2_ansi(p_task->s_local_file_down).c_str(), mci::unicode_2_ansi(p_task->s_local_file_normal).c_str()) : sLogError("::MoveFile[%s--->%s]", mci::unicode_2_ansi(p_task->s_local_file_down).c_str(), mci::unicode_2_ansi(p_task->s_local_file_normal).c_str()); } if (p_task->h_notify_wnd != NULL && p_task->n_notify_msg > 0) { ::PostMessage(p_task->h_notify_wnd,p_task->n_notify_msg,WPARAM(p_task->n_wparam),WP_LOAD_FINISH); } }//end if (e_result == dr_success) delete p_task; p_task = NULL; // delete param; return 0; }
ICom::Ptr CComFactoryManager::CreateCom(const ComID& component_id) { pthread_mutex_lock(&mutex_factory_list_); FactoryMap::iterator itor = component_factory_list_.find(component_id); if (itor == component_factory_list_.end()) { sLogError("[component:error] CComponentRepository::createPlugin create component (%s) failed [ component doesnt existed ]", component_id.c_str()); pthread_mutex_unlock(&mutex_factory_list_); return ICom::Ptr(); } /* * 此处创建的时候会把工厂的引用给组件一份,组件不释放工厂就不会释放,工厂是不释放插件就不会释放。 */ ICom::Ptr com_ptr = itor->second->component_factory->CreateCom(); pthread_mutex_unlock(&mutex_factory_list_); return com_ptr; }
void OnAcceptError(struct evconnlistener* linstener, void *ptr) { CServer * server = (CServer*)ptr; sLogError("OnAcceptError Appear."); // server->ShutdownReal(); }