Some code fixes done to multicast service classes.
[tourist.git] / Message / src / MessageTypeData.cpp
blob43e8b6a786bf7164d72c5153f51af8e7a801f0b3
1 /*
2 * This file is part of TouristP2PImpl
4 * Copyright (C) 2007,2008 NUST Institute of Information Technology
5 * Author: Faisal Khan <faisal.khan at [niit.edu.pk | cern.ch ]>
7 * TouristP2PImpl is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * TouristP2PImpl is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with TouristP2PImpl; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "Tourist/Message/MessageTypeData.h"
22 #include "Tourist/Message/MsgCacheXferRequest.h"
23 #include "Tourist/Message/MsgCacheXferReply.h"
24 #include "Tourist/Message/MsgPeerAnnouncement.h"
25 #include "Tourist/Message/MsgBootstrapRequest.h"
26 #include "Tourist/Message/MsgBootstrapReply.h"
27 #include "Tourist/Message/MsgMulticast.h"
28 #include "Tourist/Util/Util.h"
29 #include "Poco/Exception.h"
30 #include "Poco/Instantiator.h"
32 using Poco::Instantiator;
34 namespace Tourist {
35 namespace Message {
37 const int MessageTypeData::PEER_ANNOUNCE = 0;
38 const int MessageTypeData::CACHE_XFER_REQ = 1;
39 const int MessageTypeData::CACHE_XFER_REP = 2;
40 const int MessageTypeData::BOOTSTRAP_REQ = 3;
41 const int MessageTypeData::BOOTSTRAP_REP = 4;
42 const int MessageTypeData::MULTICAST = 5;
44 MessageTypeData::MessageTypeData()
46 registerBuiltIns();
49 MessageTypeData::~MessageTypeData()
54 int MessageTypeData::registerMessageObj(int type, MessageInstantiator *instance)
56 int status = 0;
57 try
59 dynFactory.registerClass(Util::toString(type), instance);
61 catch (Poco::ExistsException &e)
63 status = -1;
65 return status;
68 AbstractMessage* MessageTypeData::createInstance(int type)
70 AbstractMessage * instance = NULL;
71 try
73 instance = dynFactory.createInstance(Util::toString(type));
75 catch (Poco::NotFoundException &e)
77 //TODO: throw log
79 return instance;
82 void MessageTypeData::registerBuiltIns()
84 this -> registerMessageObj(PEER_ANNOUNCE,
85 new Instantiator<MsgPeerAnnouncement, AbstractMessage>);
87 this -> registerMessageObj(CACHE_XFER_REQ,
88 new Instantiator<MsgCacheXferRequest, AbstractMessage>);
90 this -> registerMessageObj(CACHE_XFER_REP,
91 new Instantiator<MsgCacheXferReply, AbstractMessage>);
93 this -> registerMessageObj(BOOTSTRAP_REQ,
94 new Instantiator<MsgBootstrapRequest, AbstractMessage>);
96 this -> registerMessageObj(BOOTSTRAP_REP,
97 new Instantiator<MsgBootstrapReply, AbstractMessage>);
100 this -> registerMessageObj(MULTICAST,
101 new Instantiator<MsgMulticast, AbstractMessage>);
104 } // namespace Message
105 } // namespace Tourist