Panda3D
cfChannel.cxx
1 // Filename: cfChannel.cxx
2 // Created by: drose (26Mar09)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "cfChannel.h"
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function: CFChannel::Constructor
19 // Access: Public
20 // Description: The DatagramGenerator and DatagramSink should be
21 // newly created on the free store (via the new
22 // operator). The CFChannel will take ownership of
23 // these pointers, and will delete them when it
24 // destructs.
25 ////////////////////////////////////////////////////////////////////
28  _dggen(dggen),
29  _dgsink(dgsink),
30  _reader(dggen),
31  _writer(dgsink)
32 {
33  bool ok1 = _reader.init();
34  bool ok2 = _writer.init();
35  nassertv(ok1 && ok2);
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: CFChannel::Destructor
40 // Access: Public
41 // Description:
42 ////////////////////////////////////////////////////////////////////
43 CFChannel::
44 ~CFChannel() {
45  delete _dggen;
46  delete _dgsink;
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: CFChannel::send_command
51 // Access: Public
52 // Description: Delivers a single command to the process at the other
53 // end of the channel.
54 ////////////////////////////////////////////////////////////////////
55 void CFChannel::
57  bool ok = _writer.write_object(command);
58  nassertv(ok);
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: CFChannel::receive_command
63 // Access: Public
64 // Description: Receives a single command from the process at the other
65 // end of the channel. If no command is ready, the
66 // thread will block until one is. Returns NULL when
67 // the connection has been closed.
68 ////////////////////////////////////////////////////////////////////
69 PT(CFCommand) CFChannel::
70 receive_command() {
71  TypedWritable *obj = _reader.read_object();
72  CFCommand *command;
73  DCAST_INTO_R(command, obj, NULL);
74  return command;
75 }
CFChannel(DatagramGenerator *dggen, DatagramSink *dgsink)
The DatagramGenerator and DatagramSink should be newly created on the free store (via the new operato...
Definition: cfChannel.cxx:27
void send_command(CFCommand *command)
Delivers a single command to the process at the other end of the channel.
Definition: cfChannel.cxx:56
TypedWritable * read_object()
Reads a single object from the Bam file.
Definition: bamReader.cxx:249
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
A single command in the Connected-Frame protocol.
Definition: cfCommand.h:32
bool init()
Initializes the BamReader prior to reading any objects from its source.
Definition: bamReader.cxx:94
This class defines the abstract interface to sending datagrams to any target, whether it be into a fi...
Definition: datagramSink.h:32
bool write_object(const TypedWritable *obj)
Writes a single object to the Bam file, so that the BamReader::read_object() can later correctly rest...
Definition: bamWriter.cxx:152
This class defines the abstract interace to any source of datagrams, whether it be from a file or fro...
bool init()
Initializes the BamWriter prior to writing any objects to its output stream.
Definition: bamWriter.cxx:98