The Winamp Remote Control suite
a remote control client and plugin for Winamp 2.x, 5.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ServerDLLF.cpp
Go to the documentation of this file.
1 /*
2 winamp remote control suite ŠPatrick Michael Martin 2000, 2001, 2002
3 
4 Copyright (C) 2000,2001,2002 Patrick M. Martin
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10 
11 This program 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 this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 
20 Patrick M. Martin may be reached by email at patrickmmartin@gmail.com.
21 */
22 
23 #include <vcl.h>
24 #pragma hdrstop
25 #include <registry.hpp>
26 
27 #include "ServerDLLF.h"
28 #include "rpcthreadDLL.h"
29 #include "waint.h"
30 #include "gen_plugin.h"
31 #include "AboutF.h"
32 #include "RPCBind.h"
33 
34 
35 #pragma package(smart_init)
36 #pragma resource "*.dfm"
38 
40 
41 const int FAIL_TIMEOUT = 15; // seconds
42 
43 
44 
45 void __fastcall TfrmPluginMain::timerMainTimer(TObject *Sender)
46 {
47 
48  int i;
49  TListItem *ListItem;
50  int NowTickCount = GetTickCount();
51 
52  for (i = lvUsers->Items->Count - 1; i >= 0 ; i--)
53  {
54  ListItem = lvUsers->Items->Item[i];
55 
56  //check for timed out clients
57  if ((NowTickCount - (int ) ListItem->Data) > (1000 * FAIL_TIMEOUT)){
58  // looks like it's timing out
59  ListItem->ImageIndex = 0;
60  }
61  else
62  {
63  if (ListItem->ImageIndex == 0)
64  {
65  ListItem->ImageIndex = 1;
66  }
67  }
68 
69  if ((ListItem->ImageIndex > 0) && (ListItem->ImageIndex < imlUsers->Count - 1))
70  {
71  ListItem->ImageIndex = ListItem->ImageIndex + 1;
72  }
73 
74  if ((NowTickCount - (int ) ListItem->Data) > (2000 * FAIL_TIMEOUT))
75  {
76  // looks like it's timing out
77  lvUsers->Items->Delete(i);
78  }
79 
80  } // for
81 
82 }
83 
84 
85 __fastcall TfrmPluginMain::TfrmPluginMain(TComponent* Owner)
86  : TForm(Owner)
87 {
88 }
89 
90 void __fastcall TfrmPluginMain::FormCreate(TObject *Sender)
91 {
92 const BufferSize = 32; //Buffer max size
93 char Computername[BufferSize]; // pointer to system information string
94 DWORD cchBuff; // size of computer or user name
95 bool success;
96 TRegistry * reg;
97 
98  Application->OnException = AppException;
99 
100 
101  try
102  {
103  reg = new TRegistry();
104  reg->OpenKey("software\\PMMSoft\\Winamp controller\\server settings", true);
105  AnsiString EndPoint = reg->ReadString("EndPoint");
106  // issue #3
107  success = true;
108  }
109  __finally
110  {
111  delete reg;
112  }
113 
114  /*
115  Get the computer name. */
116  cchBuff = 32;
117  if (success)
118  {
119  success = success && GetComputerName(Computername, &cchBuff);
120  }
121 
122  if (success)
123  {
124  sbrMain->Panels->Items[1]->Text = AnsiString("name: ") + Computername;
125  CreateThread();
126  }
127 
128 }
129 
130 
131 void __fastcall TfrmPluginMain::AppException(TObject *Sender, Exception *E)
132 
133 {
134  // TODO handle this error
135 }
136 
137 
138 void __fastcall TfrmPluginMain::FormKeyDown(TObject *Sender, WORD &Key,
139  TShiftState Shift)
140 {
141 
142  if ((Key == VK_F4) && (Shift.Contains(ssAlt))){
143  Key = 0;
144  }
145 
146 }
147 
148 
149 void __fastcall TfrmPluginMain::FormShow(TObject *Sender)
150 {
151  lvUsers->Items->Clear();
152 }
153 
155 {
156  serverThread = new TRPCServerDLLThread(true, plugin.hwndParent, pszProtocolSequenceNP);
157  serverThread->Resume();
158 }
159 
160 void __fastcall TfrmPluginMain::StopThread(TObject *Sender)
161 {
162  WAShutdown();
163  serverThread->WaitFor();
164  FreeAndNil(serverThread);
165 
166 }
167 
168 
169 void __fastcall TfrmPluginMain::FormCloseQuery(TObject *Sender, bool &CanClose)
170 {
171 
172 TRegistry * reg;
173 
174  try{
175  reg = new TRegistry();
176  reg->OpenKey("software\\PMMSoft\\Winamp controller\\server settings", true);
177 
178  // should implement end point edits
179  // reg->WriteString("EndPoint", "");
180 
181  reg->WriteString("Visible", Visible?"true":"false");
182  }
183  __finally {
184  delete reg;
185  }
186 
187 }
188 
189 
190 void __fastcall TfrmPluginMain::btnConfigClick(TObject *Sender)
191 {
192  config();
193 }
194 
195 
196 void __fastcall TfrmPluginMain::btnAboutClick(TObject *Sender)
197 {
198  frmAbout = new TfrmAbout(Application);
199 
200  try
201  {
202  frmAbout->Caption = "About winamp remote control server plugin";
203  frmAbout->ShowModal();
204  }
205  __finally
206  {
207  delete frmAbout;
208  frmAbout = NULL;
209  }
210 }
211 
212 
213