Blender  V2.59
NG_LoopBackNetworkDeviceInterface.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: NG_LoopBackNetworkDeviceInterface.cpp 35172 2011-02-25 13:36:49Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  * LoopbackNetworkDeviceInterface derived from NG_NetworkDeviceInterface
00029  */
00030 
00036 #include "NG_LoopBackNetworkDeviceInterface.h"
00037 #include "NG_NetworkMessage.h"
00038 
00039 // temporary debugging printf's
00040 #ifdef NAN_NET_DEBUG
00041   #include <stdio.h>
00042 #endif
00043 
00044 NG_LoopBackNetworkDeviceInterface::NG_LoopBackNetworkDeviceInterface()
00045 {
00046         m_currentQueue=0;
00047         Online();   // LoopBackdevices are 'online' immediately
00048 }
00049 
00050 NG_LoopBackNetworkDeviceInterface::~NG_LoopBackNetworkDeviceInterface()
00051 {
00052 }
00053 
00054 // perhaps this should go to the shared/common implementation too
00055 void NG_LoopBackNetworkDeviceInterface::NextFrame()
00056 {
00057         // Release reference to the messages while emptying the queue
00058         while (m_messages[m_currentQueue].size() > 0) {
00059 #ifdef NAN_NET_DEBUG
00060         printf("NG_LBNDI::NextFrame %d '%s'\n", m_currentQueue, m_messages[m_currentQueue][0]->GetSubject().ReadPtr());
00061 #endif
00062                 // Should do assert(m_events[0]);
00063                 m_messages[m_currentQueue][0]->Release();
00064                 m_messages[m_currentQueue].pop_front();
00065         }
00066         //m_messages[m_currentQueue].clear();
00067 
00068         m_currentQueue=1-m_currentQueue;
00069 }
00070 
00071 void NG_LoopBackNetworkDeviceInterface::SendNetworkMessage(NG_NetworkMessage* nwmsg)
00072 {
00073 #ifdef NAN_NET_DEBUG
00074         printf("NG_LBNDI::SendNetworkMessage %d, '%s'->'%s' '%s' '%s'\n",
00075                    1-m_currentQueue,
00076                    nwmsg->GetDestinationName().ReadPtr(),
00077                    nwmsg->GetSenderName().ReadPtr(),
00078                    nwmsg->GetSubject().ReadPtr(),
00079                    nwmsg->GetMessageText().ReadPtr());
00080 #endif
00081         int backqueue = 1-m_currentQueue;
00082 
00083         nwmsg->AddRef();
00084         m_messages[backqueue].push_back(nwmsg);
00085 }
00086 
00087 vector<NG_NetworkMessage*> NG_LoopBackNetworkDeviceInterface::RetrieveNetworkMessages()
00088 {
00089         vector<NG_NetworkMessage*> messages;
00090         
00091         std::deque<NG_NetworkMessage*>::iterator mesit=m_messages[m_currentQueue].begin();
00092         for (; !(mesit == m_messages[m_currentQueue].end()); ++mesit)
00093         {
00094 
00095                 // We don't increase the reference count for these messages. We
00096                 // are passing a vector of messages in the interface and not
00097                 // explicitily storing the messgaes for long term usage
00098 
00099                 messages.push_back(*mesit);
00100 
00101 #ifdef NAN_NET_DEBUG
00102                 printf("NG_LBNDI::RetrieveNetworkMessages %d '%s'->'%s' '%s' '%s'\n",
00103                         m_currentQueue,
00104                         (*mesit)->GetDestinationName().ReadPtr(),
00105                         (*mesit)->GetSenderName().ReadPtr(),
00106                         (*mesit)->GetSubject().ReadPtr(),
00107                         (*mesit)->GetMessageText().ReadPtr());
00108 #endif
00109         }
00110         return messages;
00111 }
00112