]> git.vomp.tv Git - vompclient.git/blob - vconnect.cc
DEV var in Makefile
[vompclient.git] / vconnect.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "vconnect.h"
22
23 VConnect::VConnect()
24 {
25   vdr = VDR::getInstance();
26   logger = Log::getInstance();
27
28   setDimensions(400, 200);
29   if (Video::getInstance()->getFormat() == Video::PAL)
30   {
31     setScreenPos(170, 200);
32   }
33   else
34   {
35     setScreenPos(160, 150);
36   }
37
38   exitable = 0;
39   irun = 0;
40 }
41
42 VConnect::~VConnect()
43 {
44   irun = 0;
45   vdr->cancelFindingServer();
46   threadCancel();
47 }
48
49 void VConnect::draw()
50 {
51   VInfo::draw();
52 }
53
54 int VConnect::handleCommand(int command)
55 {
56   return 1;
57 }
58
59 void VConnect::run()
60 {
61   threadStart();
62 }
63
64 void VConnect::threadMethod()
65 {
66   struct timespec ts;
67   int success;
68   irun = 1;
69
70   ViewMan* viewman = ViewMan::getInstance();
71
72   do
73   {
74     setMainText("\n                        Locating server");
75     draw();
76     show();
77
78     vdr->findServers(serverIPs);
79     if (!irun) return;
80
81     if (serverIPs.size() == 1)
82     {
83       selectedServer = 0;
84     }
85     else
86     {
87       selectedServer = -1;
88       VServerSelect* vs = new VServerSelect(&serverIPs);
89       vs->setParent(this);
90       vs->draw();
91       vs->show();
92       viewman->add(vs);
93       threadWaitForSignal();
94     }
95
96     logger->log("Command", Log::NOTICE, "Connecting to server at %s", serverIPs[selectedServer]);
97     vdr->setServerIP(serverIPs[selectedServer]);
98
99     // Clear the serverIPs vector
100     for(UINT k = 0; k < serverIPs.size(); k++)
101     {
102       delete[] serverIPs[k];
103     }
104     serverIPs.clear();
105
106     setMainText("\n                     Connecting to VDR");
107     draw();
108     show();
109
110     success = vdr->connect();
111     if (success)
112     {
113       logger->log("Command", Log::DEBUG, "Connected ok, doing login");
114       success = vdr->doLogin();
115
116       if (success)
117       {
118     //    setMainText("\n                            Connected");
119         ts.tv_sec = 0;
120         ts.tv_nsec = 000000000;
121       }
122       else
123       {
124         vdr->disconnect();
125         setMainText("\n                           Login failed");
126         ts.tv_sec = 3;
127         ts.tv_nsec = 0;
128       }
129     }
130     else
131     {
132       setMainText("\n                      Connection failed");
133       ts.tv_sec = 3;
134       ts.tv_nsec = 0;
135     }
136
137     draw();
138     show();
139     nanosleep(&ts, NULL);
140
141   } while(!success);
142
143   Message* m = new Message();
144   m->from = this;
145   m->message = Message::VDR_CONNECTED;
146   Command::getInstance()->postMessage(m);
147 }
148
149 void VConnect::processMessage(Message* m)
150 {
151   if (m->message == Message::SERVER_SELECTED)
152   {
153     selectedServer = m->parameter;
154     threadSignal();
155   }
156 }