コード例 #1
0
ファイル: Connection.cpp プロジェクト: PatrickGleeson/mpdmm
Error Connection::connect(){
	int retv; // What was I thinking with this?
 
	// Clear error

	if(!connected) disconnect();
	
	if(!lock()) return LOCK_FAILURE;
	
	std::string welcome_msg;
	
	try{
		socket.connect(hostname, port);
   	socket.add_delim("\n");
   	socket >> welcome_msg;
	}
	catch(Network::Exception e){
		std::cout << "Got a connection error of: " << e.get_error() << std::endl;
		// Return an MPD::Exception 
	}
	 
	// Parse the welcome message to make sure this is MPD and what version it is
	// Should be of the form "OK MPD %i.%i.%i" (major, minor, micro) version
	std::cout << welcome_msg << std::endl;
	if(welcome_msg.substr(0,7)!="OK MPD ") return NOT_MPD_CONNECTION;
	std::string::size_type first_dot = welcome_msg.find(".", 7);
	std::string::size_type second_dot = welcome_msg.find(".", first_dot);
	if(first_dot==std::string::npos || second_dot==std::string::npos) return BAD_MPD_VERSION;
	version.major=atoi(welcome_msg.substr(7,first_dot-7).c_str());
	version.minor=atoi(welcome_msg.substr(first_dot, second_dot-first_dot).c_str());
	version.micro=atoi(welcome_msg.substr(second_dot).c_str());
	
	// Refresh the status
	refresh_status();
	
	connected = true;
	unlock();

	// refresh the list of supported commands
	//refresh_allowed_commands();
   
	// refresh the list of outputs
   //refresh_outputs();
   
   // refresh the tag types
   //refresh_tag_types();
  
   // emit the necessary signals
   
    return OK;
} // Tested
コード例 #2
0
ファイル: Connection.cpp プロジェクト: PatrickGleeson/mpdmm
Error Connection::execute_or_error(const char* command){
	try{
		start_execute(command);
		std::string tmp;
		while(tmp!="OK" && tmp.substr(0,3)!="ACK"){
			std::cout << "Next line is:" << std::endl;
			socket >> tmp; // Skip through the return messages
			std::cout << tmp << std::endl;
		}
		finish_execute();
		refresh_status();
	}
	catch(Network::Exception e){
		std::cout << "Got a network exception error of" << e.get_error() << std::endl;
		// convert to an MPD error and return it
		return OK;
	}
	catch(Error e){
		return e;
	} 
	return OK;
}
コード例 #3
0
ファイル: Connection.cpp プロジェクト: PatrickGleeson/mpdmm
Status Connection::get_status(){
	//check_safe();
	refresh_status();
	return status;
}
コード例 #4
0
ファイル: script_func.cpp プロジェクト: ueverything/server2
/**
 * \brief 脚本接口,刷新npc状态
 *
 * \param npc : 目标npc的tempid
 */
void refresh_npc(int id)
{
    SceneNpc *sceneNpc = SceneNpcManager::getMe().getNpcByTempID((DWORD)id);
    if (sceneNpc) refresh_status(sceneNpc);

}