User Manual, Developers Guide and API Documentation

OpcodeSetter.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #include <WNS/ldk/multiplexer/OpcodeSetter.hpp>
00029 
00030 #include <WNS/pyconfig/Parser.hpp>
00031 
00032 #include <sstream>
00033 
00034 using namespace wns::ldk;
00035 using namespace wns::ldk::multiplexer;
00036 
00037 STATIC_FACTORY_REGISTER_WITH_CREATOR(OpcodeSetter, wns::ldk::FunctionalUnit,
00038                      "wns.multiplexer.OpcodeSetter",
00039                      wns::ldk::FUNConfigCreator);
00040 
00041 OpcodeSetter::OpcodeSetter(fun::FUN* fuNet, const pyconfig::View& _config) :
00042         CommandTypeSpecifier<>(fuNet),
00043         HasReceptor<>(),
00044         HasConnector<>(),
00045         HasDeliverer<>(),
00046         Processor<OpcodeSetter>(),
00047         Cloneable<OpcodeSetter>(),
00048 
00049         config(_config),
00050         opcode(config.get<int>("opcode")),
00051 
00052         logger("WNS", "OpcodeSetter")
00053 {
00054     friends.opcodeProvider = 0;
00055 }
00056 
00057 
00058 OpcodeSetter::OpcodeSetter(fun::FUN* fuNet, FunctionalUnit* _opcodeProvider, const pyconfig::View& _config, int _opcode) :
00059         CommandTypeSpecifier<>(fuNet),
00060         HasReceptor<>(),
00061         HasConnector<>(),
00062         HasDeliverer<>(),
00063         Processor<OpcodeSetter>(),
00064         Cloneable<OpcodeSetter>(),
00065 
00066         config(_config),
00067         opcode(_opcode),
00068 
00069         logger(_config.get("opcodeLogger"))
00070 {
00071     friends.opcodeProvider = _opcodeProvider;
00072 
00073     // give each opcodeProvider a unique rolename
00074     std::stringstream commandName;
00075     commandName << friends.opcodeProvider->getName() << "_opcode_" << opcode;
00076 
00077     setName(commandName.str());
00078 }
00079 
00080 
00081 void
00082 OpcodeSetter::onFUNCreated()
00083 {
00084     if(friends.opcodeProvider)
00085         return;
00086 
00087     std::string name = config.get<std::string>("opcodeProvider");
00088     friends.opcodeProvider = getFUN()->findFriend<OpcodeProvider*>(name);
00089     assure(friends.opcodeProvider, "required friend not found.");
00090 } // onFUNCreated
00091 
00092 
00093 void
00094 OpcodeSetter::processOutgoing(const CompoundPtr& compound)
00095 {
00096     OpcodeCommand* command =
00097         dynamic_cast<OpcodeCommand*>(friends.opcodeProvider->activateCommand(compound->getCommandPool()));
00098     command->peer.opcode = opcode;
00099 
00100     MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00101     m << " this is OpcodeSetter writing opcode " << opcode;
00102     MESSAGE_END();
00103 } // processOutgoing
00104 
00105 
00106 void
00107 OpcodeSetter::processIncoming(const CompoundPtr& /* compound */)
00108 {
00109     MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00110     m << " this is OpcodeSetter receiving opcode " << opcode;
00111     MESSAGE_END();
00112 } // processIncoming
00113 
00114 
00115 

Generated on Fri May 25 03:31:46 2012 for openWNS by  doxygen 1.5.5