3 * Interaction thread between director and the GUI
5 * Nicolas Boichat, April 2004
9 Copyright (C) 2004 Kern Sibbald and John Walker
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include "console_thread.h" // class's header file
28 #include <wx/wxprec.h>
30 #include <wx/thread.h>
34 #include "console_conf.h"
38 /* Imported functions */
39 int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons);
42 console_thread::console_thread() {
47 console_thread::~console_thread() {
49 bnet_sig(UA_sock, BNET_TERMINATE); /* send EOF */
58 void* console_thread::Entry() {
59 csprint("Connecting...\n");
62 my_name_is(0, NULL, "console");
63 textdomain("bacula-console");
66 /* TODO (#4#): Allow the user to choose his config file. */
67 parse_config("./console.conf");
70 DIRRES *dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
73 memset(&jcr, 0, sizeof(jcr));
75 UA_sock = bnet_connect(&jcr, 5, 15, "Director daemon", dir->address, NULL, dir->DIRport, 0);
76 if (UA_sock == NULL) {
81 csprint("Connected\n");
83 jcr.dir_bsock = UA_sock;
84 if (!authenticate_director(&jcr, dir, NULL)) {
86 csprint(UA_sock->msg);
95 while(!TestDestroy()) { /* Tests if thread has been ended */
96 if ((stat = bnet_recv(UA_sock)) >= 0) {
97 csprint(UA_sock->msg);
100 csprint(NULL, CS_END);
103 if (is_bnet_stop(UA_sock)) {
104 csprint(NULL, CS_END);
105 break; /* error or term */
109 csprint("Connection terminated\n");
114 void console_thread::Write(const char* str) {
116 UA_sock->msglen = strlen(str);
117 pm_strcpy(&UA_sock->msg, str);
122 void console_thread::Delete() {
125 bnet_sig(UA_sock, BNET_TERMINATE); /* send EOF */