Panda3D
 All Classes Functions Variables Enumerations
cfChannel.cxx
00001 // Filename: cfChannel.cxx
00002 // Created by:  drose (26Mar09)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "cfChannel.h"
00016 
00017 ////////////////////////////////////////////////////////////////////
00018 //     Function: CFChannel::Constructor
00019 //       Access: Public
00020 //  Description: The DatagramGenerator and DatagramSink should be
00021 //               newly created on the free store (via the new
00022 //               operator).  The CFChannel will take ownership of
00023 //               these pointers, and will delete them when it
00024 //               destructs.
00025 ////////////////////////////////////////////////////////////////////
00026 CFChannel::
00027 CFChannel(DatagramGenerator *dggen, DatagramSink *dgsink) :
00028   _dggen(dggen),
00029   _dgsink(dgsink),
00030   _reader(dggen),
00031   _writer(dgsink)
00032 {
00033   bool ok1 = _reader.init();
00034   bool ok2 = _writer.init();
00035   nassertv(ok1 && ok2);
00036 }
00037 
00038 ////////////////////////////////////////////////////////////////////
00039 //     Function: CFChannel::Destructor
00040 //       Access: Public
00041 //  Description: 
00042 ////////////////////////////////////////////////////////////////////
00043 CFChannel::
00044 ~CFChannel() {
00045   delete _dggen;
00046   delete _dgsink;
00047 }
00048 
00049 ////////////////////////////////////////////////////////////////////
00050 //     Function: CFChannel::send_command
00051 //       Access: Public
00052 //  Description: Delivers a single command to the process at the other
00053 //               end of the channel.
00054 ////////////////////////////////////////////////////////////////////
00055 void CFChannel::
00056 send_command(CFCommand *command) {
00057   bool ok = _writer.write_object(command);
00058   nassertv(ok);
00059 }
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //     Function: CFChannel::receive_command
00063 //       Access: Public
00064 //  Description: Receives a single command from the process at the other
00065 //               end of the channel.  If no command is ready, the
00066 //               thread will block until one is.  Returns NULL when
00067 //               the connection has been closed.
00068 ////////////////////////////////////////////////////////////////////
00069 PT(CFCommand) CFChannel::
00070 receive_command() {
00071   TypedWritable *obj = _reader.read_object();
00072   CFCommand *command;
00073   DCAST_INTO_R(command, obj, NULL);
00074   return command;
00075 }
 All Classes Functions Variables Enumerations