www.pudn.com > acdx.rar > Agent.cpp


 /*============================================================= 
 
  
 Function: 
		 
 
 
 Author: Leon Wang  
==============================================================*/ 
// Agent.cpp: implementation of the Agent class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "Agent.h" 
#include "H323Utils.h" 
 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
//##ModelId=424BB64603B3 
Agent::Agent() 
{ 
	appiniPath = getAppPath();// get acdx.ini path 
	blocked = FALSE; 
} 
 
    /** 
     * Create an Agent object. 
     * @param _epid Endpoint ID 
     * @param _alias H.323 alias 
     */ 
//##ModelId=424BB64603B4 
Agent::Agent(CString _epid, CString _alias)  
{ 
		this->setAlias(_alias); 
		this->setEpid(_epid); 
        //super(_alias, _epid);  father object 
        setLastCall();  // start counting free time from object creation 
		setLastTime(); 
		appiniPath = getAppPath();// get acdx.ini path 
		blocked = FALSE; 
} 
 
//##ModelId=424BB64603C0 
Agent::~Agent() 
{ 
 
} 
    /** 
     * Set a specific time for the last call. 
     * @param lastCall the time (in milliseconds) 
     */ 
//##ModelId=424BB64603C2 
void Agent::setLastCall(long lastCall)  
{ 
        this->lastCall = lastCall; 
} 
    /** 
     * Get the time since last call in milliseconds. 
     * @return elapsed time 
     */ 
//##ModelId=424BB64603C4 
long Agent::getLastCall()  
{ 
       return lastCall; 
} 
 /** 
     * Set lastCall property to now. 
     */ 
//##ModelId=424BB64603D0 
void Agent::setLastCall()  
{ 
	//SYSTEMTIME systime; 
	//GetSystemTime(&systime); 
    //setLastCall(systime.wMilliseconds); 
	setLastCall(GetTickCount()); 
} 
 
    /** 
     * Query if agent is blocked for ACD work. 
     * @return T/F 
     */ 
//##ModelId=424BB64603D1 
BOOL Agent::isBlocked()  
{ 
     return blocked; 
} 
   /** 
     * block / unblock agent from ACD work. 
     * @param blocked   T/F 
     */ 
//##ModelId=424BB64603D2 
void Agent::setBlocked(BOOL blocked)  
{ 
        this->blocked = blocked; 
} 
    /** 
     * isAgent checks if this is an agent that is mentioned in the ACD config. 
     * This is usefull, because the agent list also includes all other endpoints 
     * registered with the gatekeeper. 
     * @return true / false 
     */ 
//##ModelId=424BB64603E1 
BOOL Agent::isAgent()  
{ 
        CString configStr = ""; 
		//appiniPath 
		//getQueues();---> read we support many queue 
		configStr = getConfigKey("Agent",H323Utils::extractAliasName(getAlias()), ""); 
		//configStr = H323Utils::extractAliasName(getAlias()); 
        //configStr = agentConfig.getString(H323Utils.extractAliasName(getAlias())); 
        return (configStr!="");//(configStr.length() > 0); 
} 
 
    /** 
     * isAvailable checks if the Agent is not busy (talking) and is suited for 
     * this particular queue. 
     * @param queue the queue 
     * @return true / false 
     */ 
//##ModelId=424BB64603E2 
BOOL Agent::isAvailable(CString queue)  
{ 
    CString configStr = ""; 
    // check if agent can work this queue 
	if ((getState() == Alias::AVAILABLE) && !isBlocked())  
	{ 
			configStr = getConfigKey("Agent",H323Utils::extractAliasName(getAlias()), ""); 
			//configStr = H323Utils::extractAliasName(getAlias()); 
		 
		if (configStr == "") { 
			return FALSE; 
		} 
		groups_v_t groups; 
		split_Groups(configStr,groups); 
		if (groups.empty()) { 
			return FALSE; 
		} 
		std::vector::iterator groupsElement; 
		CString _queue_temp; 
		for(groupsElement= groups.begin();groupsElement !=groups.end();groupsElement++) 
		{ 
			_queue_temp = *groupsElement; 
			if (_queue_temp == queue) { 
				return TRUE; 
			} 
		} 
	/* 
		for(int i = 0 ; i