Blender V2.61 - r43446

NG_LoopBackNetworkDeviceInterface.cpp

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