Panda3D
mayaToEgg_client.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file mayaToEgg_client.cxx
10  * @author cbrunner
11  * @date 2009-11-09
12  */
13 
14 #include "mayaToEgg_client.h"
15 
16 /**
17  *
18  */
19 MayaToEggClient::
20 MayaToEggClient() :
21  SomethingToEgg("Maya", ".mb")
22 {
23  qManager = new QueuedConnectionManager();
24  qReader = new QueuedConnectionReader(qManager, 0);
25  cWriter = new ConnectionWriter(qManager, 0);
26  // We assume the server is local and on port 4242
27  server.set_host("localhost", 4242);
28 }
29 
30 int main(int argc, char *argv[]) {
31  MayaToEggClient prog;
32  // Open a connection to the server process
33  PT(Connection) con = prog.qManager->open_TCP_client_connection(prog.server,0);
34  if (con.is_null()) {
35  nout << "Failed to open port to server process.\nMake sure maya2egg_server is running on localhost\n";
36  exit(1);
37  }
38 
39  // Add this connection to the readers list
40  prog.qReader->add_connection(con);
41 
42  // Get the current working directory and make sure it's a string
44  std::string s_cwd = (std::string)cwd.to_os_specific();
45  NetDatagram datagram;
46 
47  // First part of the datagram is the argc
48  datagram.add_uint8(argc);
49 
50  // Add the rest of the arguments as strings to the datagram
51  int i;
52  for (i = 0; i < argc; i++) {
53  datagram.add_string(argv[i]);
54  }
55 
56  // Lastly, add the current working dir as a string to the datagram
57  datagram.add_string(s_cwd);
58 
59  // Send it and close the connection
60  prog.cWriter->send(datagram, con);
61  con->flush();
62  while (true) {
63  prog.qReader->data_available();
64  if (prog.qManager->reset_connection_available()) {
65  PT(Connection) connection;
66  if (prog.qManager->get_reset_connection(connection)) {
67  prog.qManager->close_connection(con);
68  return 0;
69  }
70  }
71  Thread::sleep(0.1);
72  }
73 }
A specific kind of Datagram, especially for sending across or receiving from a network.
Definition: netDatagram.h:40
bool send(const Datagram &datagram, const PT(Connection) &connection, bool block=false)
Enqueues a datagram for transmittal on the indicated socket.
get_cwd
Returns the name of the current working directory.
This flavor of ConnectionManager will queue up all of the reset-connection messages from the Connecti...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool get_reset_connection(PT(Connection) &connection)
If a previous call to reset_connection_available() returned true, this function will return informati...
bool reset_connection_available() const
Returns true if one of the readers/writers/listeners reported a connection reset recently.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
bool data_available()
Returns true if a datagram is available on the queue; call get_data() to extract the datagram.
void add_string(const std::string &str)
Adds a variable-length string to the datagram.
Definition: datagram.I:219
This class handles threaded delivery of datagrams to various TCP or UDP sockets.
static void sleep(double seconds)
Suspends the current thread for at least the indicated amount of time.
Definition: thread.I:192
bool add_connection(Connection *connection)
Adds a new socket to the list of sockets the ConnectionReader will monitor.
This flavor of ConnectionReader will read from its sockets and queue up all of the datagrams read for...
void add_uint8(uint8_t value)
Adds an unsigned 8-bit integer to the datagram.
Definition: datagram.I:50
This is the general base class for a file-converter program that reads some model file format and gen...
Represents a single TCP or UDP socket for input or output.
Definition: connection.h:29
std::string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
Definition: filename.cxx:1123