예제 #1
0
void Document::loadFileToString( const String& file_name_, String &buffer_ )
{
	FRL_EXCEPT_GUARD();
	if( ! fs::exists( file_name_ ) )
		FRL_THROW_S_CLASS( Document::FileNotFound );
	size_t length = static_cast< size_t >( fs::file_size( file_name_ ) );
	if( length == 0 )
		FRL_THROW_S_CLASS( Document::EmptyFile );
	if( ! buffer_.empty() )
		buffer_.clear();

	static const size_t buffer_size = 4096;
	stream_std::InFile in( file_name_.c_str(), std::ios::binary );
	if( ! in.is_open() )
		FRL_THROW_S_CLASS( Document::UnknownError );
	std::vector< Char > buf( buffer_size );

	buffer_.reserve( length );
	while( in )
	{
		in.read( &buf[ 0 ], buffer_size );
		buffer_.append( &buf[ 0 ], in.gcount() );
	}
	in.close();
}
void ServerConnection::connectToRemoteServer( CLSID server_clsid )
{
	FRL_EXCEPT_GUARD();
	COSERVERINFO server_info;
	os::win32::com::zeroMemory( &server_info );

	server_info.pwszName = util::duplicateString( unicodeCompatibility( host_name ) );
	// setup requested interfaces
	MULTI_QI mq_result;
	os::win32::com::zeroMemory( &mq_result );

	mq_result.pIID = &IID_IOPCServer;
	mq_result.pItf = NULL;
	mq_result.hr   = S_OK;

	// call create instance
	if( FAILED( CoCreateInstanceEx( server_clsid,
		NULL,
		CLSCTX_REMOTE_SERVER,
		&server_info,
		1,
		&mq_result) ) )
	{
		FRL_THROW_S_CLASS( CreateServerObjectError );
	}

	// check QueryInterface result
	if( FAILED(mq_result.hr) )
		FRL_THROW_S_CLASS( QueryInterfaceError );

	// set pointer to server object
	ComPtr<IOPCServer> tmp( (IOPCServer*)mq_result.pItf );
	tmp.get()->Release(); // release tmp
	server.swap( tmp ); // equal: this->server->ptr = mq_result.pItf
}
예제 #3
0
void AddressSpace::addBranch( const String &fullPath )
{
	FRL_EXCEPT_GUARD();
	if( rootTag == NULL )
		FRL_THROW_S_CLASS( NotFinalConstruct );
	if( fullPath.empty() )
		FRL_THROW_S_CLASS( InvalidBranchName );
	size_t pos = fullPath.rfind( delimiter + delimiter );
	if ( pos != String::npos )
		FRL_THROW_S_CLASS( InvalidBranchName );
	pos = fullPath.rfind( delimiter );
	if( pos == String::npos )
	{
		Tag *added = rootTag->addBranch( fullPath );
		nameBranchCache.insert( std::pair< String, Tag*>( fullPath, added ) );
		return;
	}
	// last or first symbol in branch name == delimiter
	if( pos == fullPath.size()-1 || pos == 0 )
		FRL_THROW_S_CLASS( InvalidBranchName );
	String tmpPath = fullPath.substr( 0, pos );
	if ( !isExistBranch(tmpPath) )
	{
		addBranch( tmpPath );
	}	
	Tag *added = getBranch( tmpPath )->addBranch( fullPath );
	nameBranchCache.insert( std::pair< String, Tag*>( fullPath, added ) );
}
예제 #4
0
Tag* AddressSpace::getLeaf( const String& fullPath )
{
	if( fullPath.empty() )
		FRL_THROW_S_CLASS( InvalidLeafName );
	std::map< String, Tag*>::iterator it = nameLeafCache.find( fullPath );
	if( it == nameLeafCache.end() )
		FRL_THROW_S_CLASS( Tag::NotExistTag );
	return (*it).second;
}
예제 #5
0
void GroupManager::renameGroup( const String &name, const String &to_name )
{
	boost::mutex::scoped_lock lock( guard );
	FRL_EXCEPT_GUARD();
	GroupElemNamesMap::iterator end = names_map.end();
	GroupElemNamesMap::iterator it = names_map.find( to_name );
	if( it != end )
		FRL_THROW_S_CLASS( IsExistGroup );
	it = names_map.find( name );
	if( it == end )
		FRL_THROW_S_CLASS( NotExistGroup );
	GroupElem group = it->second;
	names_map.erase( it );
	group->setName( to_name );
	names_map.insert( std::pair< String, GroupElem >( name, group ) );
}
예제 #6
0
frl::opc::GroupElem GroupManager::cloneGroup( String &name, String &to_name )
{
	boost::mutex::scoped_lock lock( guard );
	FRL_EXCEPT_GUARD();
	GroupElemNamesMap::iterator end = names_map.end();
	GroupElemNamesMap::iterator it = names_map.find( to_name );
	if( it != end )
		FRL_THROW_S_CLASS( IsExistGroup );

	it = names_map.find( name );
	if( it == end )
		FRL_THROW_S_CLASS( NotExistGroup );

	GroupElem new_group( it->second->clone() );
	new_group->setName( to_name );
	insert( new_group );
	return new_group;
}
예제 #7
0
Tag* AddressSpace::getBranch( const String& fullPath )
{
	if( fullPath.empty() )
		return rootTag;
	std::map< String, Tag*>::iterator it = nameBranchCache.find( fullPath );
	if( it == nameBranchCache.end() )
		FRL_THROW_S_CLASS( Tag::NotExistTag );
	return (*it).second;
}
예제 #8
0
frl::opc::GroupElem GroupManager::getGroup( String &name )
{
	boost::mutex::scoped_lock lock( guard );
	FRL_EXCEPT_GUARD();
	GroupElemNamesMap::iterator it = names_map.find( name );
	if( it == names_map.end() )
		FRL_THROW_S_CLASS( NotExistGroup );
	return it->second;
}
예제 #9
0
frl::opc::GroupElem GroupManager::getGroup( OPCHANDLE handle )
{
	boost::mutex::scoped_lock lock( guard );
	FRL_EXCEPT_GUARD();
	GroupElemHandlesMap::iterator it = handles_map.find( handle );
	if( it == handles_map.end() )
		FRL_THROW_S_CLASS( NotExistGroup );
	return it->second;
}
예제 #10
0
bool GroupManager::removeGroup( String &name )
{
	boost::mutex::scoped_lock lock( guard );
	FRL_EXCEPT_GUARD();
	GroupElemNamesMap::iterator name_it = names_map.find( name );
	if( name_it == names_map.end() )
		FRL_THROW_S_CLASS( NotExistGroup );
	name_it->second->isDeleted( True );
	OPCHANDLE tmp_handle = name_it->second->getServerHandle();
	names_map.erase( name_it );
	
	GroupElemHandlesMap::iterator handle_it = handles_map.find( tmp_handle );
	if( handle_it == handles_map.end() )
		FRL_THROW_S_CLASS( NotExistGroup );
	Group *ptr = handle_it->second.get();
	ptr->AddRef();
	handles_map.erase( handle_it );
	return ptr->Release() == 0;
}
예제 #11
0
GroupElem GroupManager::addGroup( String &name )
{
	boost::mutex::scoped_lock lock( guard );
	FRL_EXCEPT_GUARD();
	if( names_map.find( name ) != names_map.end() )
		FRL_THROW_S_CLASS( IsExistGroup );
	GroupElem new_group( new Group( name ) );
	insert( new_group );
	return new_group;
}
CLSID ServerConnection::getCLSID()
{
	FRL_EXCEPT_GUARD();
	CLSID server_clsid = GUID_NULL;
	#if( FRL_CHARACTER == FRL_CHARACTER_UNICODE )
		if( FAILED(CLSIDFromProgID( server_id.c_str(), &server_clsid)) )
		{
			if( UuidFromString( (unsigned short*)server_id.c_str(), &server_clsid) != RPC_S_OK )
				FRL_THROW_S_CLASS( NotResolveProgID );
		}
	#else
		if( FAILED(CLSIDFromProgID( string2wstring( server_id ).c_str(), &server_clsid)) )
		{
			if( UuidFromString( (unsigned char*)server_id.c_str(), &server_clsid) != RPC_S_OK )
				FRL_THROW_S_CLASS( NotResolveProgID );
		}	
	#endif // FRL_CHARACTER_UNICODE
	return server_clsid;
}
std::vector< GroupPtr > ServerConnection::getGoupList()
{
	FRL_EXCEPT_GUARD();
	boost::mutex::scoped_lock guard( scope_guard );
	if( ! isConnected() )
		FRL_THROW_S_CLASS( NotConnected );
	std::vector<GroupPtr> vec_tmp( group_list.size() );
	std::transform( group_list.begin(), group_list.end(), vec_tmp.begin(), boost::mem_fn(&GroupList::value_type::second ) );
	return vec_tmp;
}
GroupPtr ServerConnection::getGroupByName( const String& group_name )
{
	FRL_EXCEPT_GUARD();
	boost::mutex::scoped_lock guard( scope_guard );
	checkIsConnect();
	GroupList::iterator it = group_list.find( group_name );
	if( it == group_list.end() )
		FRL_THROW_S_CLASS( GroupNotExist );
	return it->second;
}
예제 #15
0
Tag* AddressSpace::addLeaf( const String &fullPath, Bool createPath )
{
	FRL_EXCEPT_GUARD();
	if( fullPath.empty() )
		FRL_THROW_S_CLASS( InvalidLeafName );
	size_t pos = fullPath.rfind( delimiter + delimiter );
	if ( pos != String::npos )
		FRL_THROW_S_CLASS( InvalidLeafName );
	pos = fullPath.rfind( delimiter );
	if( pos == 0 || pos == fullPath.length()-1 )
		FRL_THROW_S_CLASS( InvalidLeafName );
	if( pos == String::npos )
	{
		if ( rootTag->isExistTag( fullPath ) )
			FRL_THROW_S_CLASS( Tag::IsExistTag );
		rootTag->addLeaf( fullPath );
		Tag *added = rootTag->getLeaf( fullPath );
		nameLeafCache.insert( std::pair< String, Tag*>( fullPath, added ) );
		return added;
	}
	String fullBranchName = fullPath.substr(0, pos );

	try
	{
		//getBranch( fullBranchName )->addLeaf( fullPath );
		if ( !isExistBranch(fullBranchName) )
		{
			addBranch( fullBranchName );
		}
		
		getBranch( fullBranchName )->addLeaf( fullPath );
		Tag *added = getBranch( fullBranchName )->getLeaf( fullPath );
		nameLeafCache.insert( std::pair< String, Tag*>( fullPath, added ) );
		return added;
	}
	catch( Tag::NotExistTag& )
	{
		if( ! createPath )
			FRL_THROW_S_CLASS( Tag::NotExistTag );
	}
	return NULL;
}
void ServerConnection::internalRemoveGroup( const String& group_name, Bool force )
{
	FRL_EXCEPT_GUARD();
	boost::mutex::scoped_lock guard( scope_guard );
	checkIsConnect();
	GroupList::iterator it = group_list.find( group_name );
	if( it == group_list.end() )
		FRL_THROW_S_CLASS( GroupNotExist );
	it->second->removeGroup( force );
	group_list.erase( it );
}
예제 #17
0
	ChannelPtr ChannelMgr::Get( const uint32_t id )
	{
		BOOST_FOREACH(const ChannelPtr& channel, channels_)
		{
			if ( channel->GetId() == id )
			{
				return channel;
			}
		}

		FRL_THROW_S_CLASS( ChannelNotExist );
	}
예제 #18
0
void Document::parseHeader( String &buffer )
{
	FRL_EXCEPT_GUARD();
	if( buffer.empty() )
		FRL_THROW_S_CLASS( Document::EmptyFile );

	String tmpBuffer = buffer;
	size_t headerBegin = buffer.find( FRL_STR("<?xml") );
	if( headerBegin != String::npos )
	{
		headerBegin += 5;
		size_t headerEnd = buffer.find( FRL_STR("?>") );
		if( headerEnd == String::npos )
			FRL_THROW_S_CLASS( Document::BrokenXML );
		headerEnd -= headerBegin;
		if( headerBegin >= headerEnd )
			FRL_THROW_S_CLASS( Document::BrokenXML );
		String tmp = buffer.substr( headerBegin, headerEnd );
		headerEnd += (headerBegin + 2);
		buffer = buffer.substr( headerEnd, buffer.length() - 1 );
		removeSymbolsFromStart( tmp, FRL_STR(' ') );
		removeSymbolsFromEnd( tmp, FRL_STR(' ') );
		try
		{
			version = Parser::getProperty( tmp, FRL_STR("version") );
		}
		catch( ... )
		{
			FRL_THROW_S_CLASS( Document::BrokenXML );
		}
		try
		{
			encoding = Parser::getProperty( tmp, FRL_STR("encoding") );
		}
		catch( ... )
		{
			return;
		}
	}
}
예제 #19
0
void Document::loadFromCurrenttDir( const String& fileName_ )
{
	FRL_EXCEPT_GUARD();
	String currDir = io::fs::getCurrentDirectory();
	io::fs::addSlashToEndPath( currDir );
	fileName = currDir + fileName_;
	String buffer;
	loadFileToString( fileName, buffer );
	buffer.erase( std::remove_if( buffer.begin(), buffer.end(), private_::isCRLF ), buffer.end() ); // remove CRLF
	parseHeader( buffer );
	NodesList tmpMap = Parser::getSubNodes( buffer );
	if( tmpMap.size() > 1 )
		FRL_THROW_S_CLASS( Document::BrokenXML ); // must be one root node
	root = (*tmpMap.begin());
}
GroupPtr ServerConnection::addGroupAsyncIO2( const String& group_name )
{
	FRL_EXCEPT_GUARD();
	boost::mutex::scoped_lock guard( scope_guard );
	checkIsConnect();
	GroupList::iterator it = group_list.find( group_name );
	if( it != group_list.end() )
		FRL_THROW_S_CLASS( GroupAlreadyExist );
	AsyncIO2Group *new_gr = new AsyncIO2Group( group_name, server );
	new_gr->create();
	GroupPtr new_group( new_gr );
	GroupElemPair new_elem( group_name, new_group );
	group_list.insert( new_elem );
	return new_group; 
}
예제 #21
0
std::vector< GroupElem > GroupManager::getGroupEnum()
{
	boost::mutex::scoped_lock lock( guard );
	FRL_EXCEPT_GUARD();
	size_t size = names_map.size();
	if( size == 0 )
		FRL_THROW_S_CLASS( NotExistGroup );
	std::vector< GroupElem > vec;
	vec.reserve( size );
	GroupElemNamesMap::iterator end = names_map.end();
	for(	GroupElemNamesMap::iterator it = names_map.begin();
			it != end;
			++it )
	{
		vec.push_back( it->second );
	}
	return vec;
}
예제 #22
0
Event::Event() : handle( CreateEvent(NULL, FALSE, FALSE, NULL) )
{
	FRL_EXCEPT_GUARD();
	if( handle == NULL )
		FRL_THROW_S_CLASS( Event::InitializeError );
}
void ServerConnection::checkIsConnect()
{
	FRL_EXCEPT_GUARD();
	if( ! isConnected() )
		FRL_THROW_S_CLASS( NotConnected );
}