Panda3D
Loading...
Searching...
No Matches
directd.h
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 directd.h
10 * @author skyler
11 * @date 2002-04-08
12 */
13
14#include <process.h>
15#include "pandabase.h"
16#include "directsymbols.h"
19#include "connectionWriter.h"
21#include <windows.h>
22
23
24#ifdef CPPPARSER //[
25// hack for interrogate
26typedef int intptr_t;
27typedef int HANDLE;
28#endif //]
29
30
31/**
32 * DirectD is a client/server app for starting panda/direct.
33 *
34 * Usage: Start a directd server on each of the machines you which to start
35 * panda on.
36 *
37 * Start a directd client on the controlling machine or import ShowBaseGlobal
38 * with the xxxxx flag in your Configrc. The client will connect each of the
39 * servers in the xxxxx list in your Configrc.
40 *
41 * There are two API groups in this class, they are:
42 *
43 * listen_to() client_ready() or tell_server() wait_for_servers()
44 * server_ready()
45 *
46 * and:
47 *
48 * connect_to() send_command() disconnect_from()
49 *
50 * The second group was from a more general implementation of DirectD. The
51 * first group summarizes the main intents of DirectD. Both groups are
52 * presented in order chronologically by their intended usage. The first
53 * group will probably provide everthing needed for DirectD.
54 */
55class EXPCL_DIRECT_DIRECTD DirectD {
56PUBLISHED:
57 DirectD();
58 ~DirectD();
59
60/**
61 * Call listen_to in the server. port is a rendezvous port.
62 *
63 * backlog refers to how many connections can queue up before you handle them.
64 * Consider setting backlog to the count you send to wait_for_servers(); or
65 * higher.
66 */
67 void listen_to(int port, int backlog=8);
68
69/**
70 * Call this function from the client when import ShowbaseGlobal is nearly
71 * finished. cmd: a cli command that will be executed on the remote machine.
72 * A new connection will be created and closed. If you want to send more than
73 * one command, you should use connect_to(), send_command(), and
74 * disconnect_from().
75 */
76 int client_ready(const std::string& server_host, int port, const std::string& cmd);
77
78/**
79 * Tell the server to do the command cmd. cmd is one of the following:
80 * "k[<n>]" Kill the most recent application started with client_ready() or
81 * "!". Or kill the nth most recent or 'a' for All. E.g. "k", "k0", "k2",
82 * "ka". "q" Tell the server to quit. "!cmd" Exectue the cmd on
83 * the server (this is a dos shell command; if you want a bash command,
84 * include bash in the command e.g. "!bash pwd"). When you call
85 * client_ready(), it prefixes "!" for you. A new connection will be created
86 * and closed.
87 */
88 int tell_server(const std::string& server_host, int port, const std::string& cmd);
89
90/**
91 * Call this function from the client after calling <count> client_ready()
92 * calls.
93 *
94 * Call listen_to(port) prior to calling wait_for_servers() (or better yet,
95 * prior to calling client_ready()).
96 *
97 * timeout_ms defaults to two minutes.
98 */
99 bool wait_for_servers(int count, int timeout_ms=2*60*1000);
100
101/**
102 * Call this function from the server when import ShowbaseGlobal is nearly
103 * finished.
104 */
105 int server_ready(const std::string& client_host, int port);
106
107/**
108 * Call connect_to from client for each server. returns the port number of
109 * the connection (which is different from the rendezvous port used in the
110 * second argument). The return value can be used for the port arguemnt in
111 * disconnect_from().
112 */
113 int connect_to(const std::string& server_host, int port);
114
115/**
116 * This is the counterpart to connect_to(). Pass the same server_host as for
117 * connect_to(), but pass the return value from connect_to() for the port, not
118 * the port passed to connect_to().
119 */
120 void disconnect_from(const std::string& server_host, int port);
121
122/**
123 * Send the same command string to all current connections.
124 */
125 void send_command(const std::string& cmd);
126
127protected:
128 void start_app(const std::string& cmd);
129 void kill_app(int index);
130 void kill_all();
131 virtual void handle_command(const std::string& cmd);
132 void handle_datagram(NetDatagram& datagram);
133 void send_one_message(const std::string& host_name,
134 int port, const std::string& message);
135
138 ConnectionWriter _writer;
139 QueuedConnectionListener _listener;
140
141 // Start of old stuff: This is used to switch to the original method of
142 // starting applications. It can be used on old systems that don't support
143 // job objects. Eventually this stuff should be removed.
144 bool _useOldStuff;
145 typedef pvector< long /*intptr_t*/ > PidStack;
146 PidStack _pids;
147 // End of old stuff
148
149 typedef pset< PT(Connection) > ConnectionSet;
150 ConnectionSet _connections;
151 HANDLE _jobObject;
152 bool _shutdown;
153
154 void check_for_new_clients();
155 void check_for_datagrams();
156 void check_for_lost_connection();
157};
This class handles threaded delivery of datagrams to various TCP or UDP sockets.
Represents a single TCP or UDP socket for input or output.
Definition connection.h:29
DirectD is a client/server app for starting panda/direct.
Definition directd.h:55
A specific kind of Datagram, especially for sending across or receiving from a network.
Definition netDatagram.h:40
This flavor of ConnectionListener will queue up all of the TCP connections it established for later d...
This flavor of ConnectionManager will queue up all of the reset-connection messages from the Connecti...
This flavor of ConnectionReader will read from its sockets and queue up all of the datagrams read for...
This is our own Panda specialization on the default STL set.
Definition pset.h:49
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.