Panda3D
 All Classes Functions Variables Enumerations
mayaToEgg_client.cxx
00001 // Filename: mayaToEgg.cxx
00002 // Adapted by: cbrunner (09Nov09)
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 "mayaToEgg_client.h"
00016 #ifdef _WIN32
00017   #include "pystub.h"
00018 #endif
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //     Function: MayaToEgg::Constructor
00022 //       Access: Public
00023 //  Description:
00024 ////////////////////////////////////////////////////////////////////
00025 MayaToEggClient::
00026 MayaToEggClient() :
00027   SomethingToEgg("Maya", ".mb")
00028 {
00029   qManager = new QueuedConnectionManager();
00030   qReader = new QueuedConnectionReader(qManager, 0);
00031   cWriter = new ConnectionWriter(qManager, 0);
00032   // We assume the server is local and on port 4242
00033   server.set_host("localhost", 4242);
00034 }
00035 
00036 int main(int argc, char *argv[]) {
00037   // We don't want pystub on linux, since it gives problems with Maya's python.
00038 #ifdef _WIN32
00039   // A call to pystub() to force libpystub.so to be linked in.
00040   pystub();
00041 #endif
00042 
00043   MayaToEggClient prog;
00044   // Open a connection to the server process
00045   PT(Connection) con = prog.qManager->open_TCP_client_connection(prog.server,0);
00046   if (con.is_null()) {
00047     nout << "Failed to open port to server process.\nMake sure maya2egg_server is running on localhost\n";
00048     exit(1);
00049   }
00050 
00051   // Add this connection to the readers list
00052   prog.qReader->add_connection(con);
00053 
00054   // Get the current working directory and make sure it's a string
00055   Filename cwd = ExecutionEnvironment::get_cwd();
00056   string s_cwd = (string)cwd.to_os_specific();
00057   NetDatagram datagram;
00058   
00059   // First part of the datagram is the argc
00060   datagram.add_uint8(argc);
00061 
00062   // Add the rest of the arguments as strings to the datagram
00063   int i;
00064   for (i = 0; i < argc; i++) {
00065     datagram.add_string(argv[i]);
00066   }
00067 
00068   // Lastly, add the current working dir as a string to the datagram
00069   datagram.add_string(s_cwd);
00070   
00071   // Send it and close the connection
00072   prog.cWriter->send(datagram, con);
00073   con->flush();
00074   while (true) {
00075     prog.qReader->data_available();
00076     if (prog.qManager->reset_connection_available()) {
00077       PT(Connection) connection;
00078       if (prog.qManager->get_reset_connection(connection)) {
00079         prog.qManager->close_connection(con);
00080         return 0;
00081       }
00082     }
00083     Thread::sleep(0.1);
00084   }
00085 }
00086 
 All Classes Functions Variables Enumerations