<commit_before>/**
 * @author  <NAME> (Kent), Rewritten by <NAME> 2009-3-29
 */

#include <net/message-framework/MessageControllerLight.h>
#include <net/message-framework/MessageClientLight.h>
#include <iostream>
#include <util/izene_log.h>

using namespace std;
using namespace boost;

namespace messageframework {

void MessageControllerLight::processServiceRegistrationRequest() {
	boost::mutex::scoped_lock lock(processDummyMutex_);
	processDummyCond_.wait(lock);
}

void MessageControllerLight::processServicePermissionRequest() {
	boost::mutex::scoped_lock lock(processDummyMutex_);
	processDummyCond_.wait(lock);
}

void MessageControllerLight::processServiceResultFromServer() {
	boost::mutex::scoped_lock lock(processDummyMutex_);
	processDummyCond_.wait(lock);
}

void MessageControllerLight::processServiceRequestFromClient() {
	boost::mutex::scoped_lock lock(processDummyMutex_);
	processDummyCond_.wait(lock);
}

int MessageControllerLight::applyForClientId() {
	{
		boost::mutex::scoped_lock lock(nxtClientIdMutex_);
		if (nxtClientId_ == MF_LIGHT_MAX_CLIENT_ID) {
			std::cout << "Error: Max Client ID reached" << std::endl;
			return 0;
		}

		DLOG(INFO)<<"applyForClientId"<<nxtClientId_<<endl;
		serviceIdResultMaps_[nxtClientId_].reset(new std::map<unsigned int, ServiceResultPtr>);
		serviceIdResultMutexs_[nxtClientId_].reset(new boost::mutex() );
		serviceIdResultConds_[nxtClientId_].reset(new boost::condition_variable() );

		int clientId = nxtClientId_;
		nxtClientId_ ++;
		return clientId;
	}
}

bool MessageControllerLight::addServiceRegistrationRequest(
		const ServiceRegistrationMessage & message) {

	const MessageFrameworkNode & server = message.getServer();
	boost::mutex::scoped_lock lock(availableServiceListMutex_);
	std::string serviceName = message.getServiceName();

	boost::unordered_map<std::string, ServicePermissionInfo>::iterator it;
	it = availableServiceList_.find(serviceName);
	
	if (it != availableServiceList_.end() ) {
		it->second.setServer(message.getAgentInfo(), server);
	} else {
		ServicePermissionInfo permissionInfo;
		permissionInfo.setServiceName(serviceName);
		permissionInfo.setServer(message.getAgentInfo(), server);
		availableServiceList_.insert(make_pair(serviceName, permissionInfo) );
	}
	

	DLOG(INFO)<<"MessageControllerLight::addServiceRegistrationRequest()"<<endl;
	availableServiceList_[serviceName].display();
	

	boost::mutex::scoped_lock lock_map(serverServiceRequestQueueMapMutex_);
	boost::shared_ptr<vector<shared_ptr<ServiceRequestInfo> > ><commit_msg>remove MessageControllerLight debug info<commit_after>/**
 * @author  <NAME> (Kent), Rewritten by Wei Cao 2009-3-29
 */

#include <net/message-framework/MessageControllerLight.h>
#include <net/message-framework/MessageClientLight.h>
#include <iostream>
#include <util/izene_log.h>

using namespace std;
using namespace boost;

namespace messageframework {

void MessageControllerLight::processServiceRegistrationRequest() {
	boost::mutex::scoped_lock lock(processDummyMutex_);
	processDummyCond_.wait(lock);
}

void MessageControllerLight::processServicePermissionRequest() {
	boost::mutex::scoped_lock lock(processDummyMutex_);
	processDummyCond_.wait(lock);
}

void MessageControllerLight::processServiceResultFromServer() {
	boost::mutex::scoped_lock lock(processDummyMutex_);
	processDummyCond_.wait(lock);
}

void MessageControllerLight::processServiceRequestFromClient() {
	boost::mutex::scoped_lock lock(processDummyMutex_);
	processDummyCond_.wait(lock);
}

int MessageControllerLight::applyForClientId() {
	{
		boost::mutex::scoped_lock lock(nxtClientIdMutex_);
		if (nxtClientId_ == MF_LIGHT_MAX_CLIENT_ID) {
			std::cout << "Error: Max Client ID reached" << std::endl;
			return 0;
		}

		DLOG(INFO)<<"applyForClientId"<<nxtClientId_<<endl;
		serviceIdResultMaps_[nxtClientId_].reset(new std::map<unsigned int, ServiceResultPtr>);
		serviceIdResultMutexs_[nxtClientId_].reset(new boost::mutex() );
		serviceIdResultConds_[nxtClientId_].reset(new boost::condition_variable() );

		int clientId = nxtClientId_;
		nxtClientId_ ++;
		return clientId;
	}
}

bool MessageControllerLight::addServiceRegistrationRequest(
		const ServiceRegistrationMessage & message) {

	const MessageFrameworkNode & server = message.getServer();
	boost::mutex::scoped_lock lock(availableServiceListMutex_);
	std::string serviceName = message.getServiceName();

	boost::unordered_map<std::string, ServicePermissionInfo>::iterator it;
	it = availableServiceList_.find(serviceName);
	
	if (it != availableServiceList_.end() ) {
		it->second.setServer(message.getAgentInfo(), server);
	} else {
		ServicePermissionInfo permissionInfo;
		permissionInfo.setServiceName(serviceName);
		permissionInfo.setServer(message.getAgentInfo(), server);
		availableServiceList_.insert(make_pair(serviceName, permissionInfo) );
	}
	

	DLOG(INFO)<<"MessageControllerLight::addServiceRegistrationRequest()"<<endl;
	//availableServiceList_[serviceName].display();
	

	boost::mutex::scoped_lock lock_map(serverServiceRequestQueueMapMutex_);
	boost::shared_ptr<vector<shared_ptr<ServiceRequestInfo> > >
{'fraction_non_alphanumeric': 0.12152097216777734, 'fraction_numerical': 0.0031360250882007056, 'mean_word_length': 8.43253234750462, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3746246', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1542, 'n_words': 228}