Google
Web alhem.net
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

MyApp.cpp File Reference

#include <windows.h>
#include <ListenSocket.h>
#include <config-win.h>
#include <mysql.h>
#include <libmysqlwrapped.h>
#include <stdio.h>
#include <shellapi.h>
#include "resource.h"
#include <socket_include.h>
#include <SocketHandler.h>
#include <HttpGetSocket.h>
#include <process.h>
#include <commctrl.h>
#include <StdoutLog.h>
#include "Mutex.h"
#include "MyErrlog.h"
#include "MySocketsLog.h"
#include "MenuHandler.h"
#include "MyMenu.h"
#include <Utility.h>
#include <libcgi++.h>
#include "FinderHandler.h"
#include "ExecSocket.h"
#include "MyMinionSocket.h"
#include "MyMinderSocket.h"
#include "MyApp.h"

Include dependency graph for MyApp.cpp:

Include dependency graph

Go to the source code of this file.

Defines

#define _WIN32_WINNT   0x0400
#define _WIN32_IE   0x0500
#define D2(x)

Functions

DWORD WINAPI start (LPVOID lpParam)
int CALLBACK MyDlgProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

Variables

HANDLE g_hD2
bool g_bQuit = false
HANDLE g_hMutex
bool g_bRestart = true
HANDLE g_hMutexScan
bool g_bWsRunning = false
MenuHandler g_menuHandler
MyAppg_app = NULL
HWND g_hwndMain


Define Documentation

#define _WIN32_IE   0x0500
 

Definition at line 24 of file MyApp.cpp.

#define _WIN32_WINNT   0x0400
 

File ......... MyApp.cpp Published .... 2004-09-27

Definition at line 23 of file MyApp.cpp.

#define D2  ) 
 

Value:

{ \ Mutex lock(g_hD2); \ if (lock.Locked()) \ { \ FILE *fil = fopen("c:\\deb.log","at"); \ x; \ fclose(fil); \ } \ }

Definition at line 60 of file MyApp.cpp.


Function Documentation

int CALLBACK MyDlgProc HWND  hwnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam
[static]
 

Definition at line 202 of file MyApp.cpp.

References MyApp::ChangeIcon(), D2, g_app, g_hwndMain, g_menuHandler, MyApp::GetDialogData(), MyApp::GetLocalPort(), Menu::Handle(), ID_POPUP_EXIT, MenuHandler::OnCommand(), MenuHandler::OnInitMenu(), MenuHandler::OnInitPopupMenu(), MenuHandler::OnMenuSelect(), MyApp::SetQuit(), WM_CHANGE_ICON, and WM_SHELLNOTIFY.

Referenced by MyApp::Init().

00203 { 00204 switch (uMsg) 00205 { 00206 case WM_INITDIALOG: 00207 break; 00208 00209 case WM_SHELLNOTIFY: 00210 if (lParam == WM_LBUTTONDBLCLK) 00211 { 00212 char cmd[100]; 00213 sprintf(cmd, "http://127.0.0.1:%d/", g_app->GetLocalPort()); 00214 ::ShellExecute(NULL, NULL, cmd, NULL, "", SW_SHOW); 00215 } 00216 else 00217 if (lParam == WM_RBUTTONDOWN) 00218 { 00219 MyMenu m(g_menuHandler); // 'Menu' constructor adds new object to handler 00220 POINT pt; 00221 00222 GetCursorPos(&pt); 00223 SetForegroundWindow(g_hwndMain); 00224 int cmd = TrackPopupMenuEx(m.Handle(), 00225 TPM_RIGHTALIGN|TPM_BOTTOMALIGN|TPM_RIGHTBUTTON|TPM_RETURNCMD, 00226 pt.x, pt.y, g_hwndMain, NULL); 00227 if (cmd) 00228 { 00229 if (!g_menuHandler.OnCommand( cmd )) 00230 { 00231 ::PostMessage(g_hwndMain, WM_COMMAND, cmd, 0); 00232 } 00233 } 00234 ::PostMessage(g_hwndMain, WM_NULL, 0, 0); 00235 } 00236 break; // WM_SHELLNOTIFY 00237 case WM_INITMENU: 00238 D2(fprintf(fil,"WM_INITMENU %08lx %08lx\n",wParam,lParam);) 00239 { 00240 HMENU hMenu = (HMENU)wParam; 00241 g_menuHandler.OnInitMenu(hMenu); 00242 } 00243 break; 00244 case WM_INITMENUPOPUP: 00245 D2(fprintf(fil,"WM_INITMENUPOPUP %08lx %08lx\n",wParam,lParam);) 00246 { 00247 HMENU hMenu = (HMENU)wParam; 00248 int relpos = lParam & 0xffff; 00249 int winmenu = (lParam >> 16) & 0xffff; 00250 D2(fprintf(fil," relpos: %d winmenu: %d\n",relpos,winmenu);); 00251 { 00252 MENUITEMINFO info; 00253 ::GetMenuItemInfo(hMenu, relpos, true, &info); 00254 } 00255 g_menuHandler.OnInitPopupMenu(hMenu, relpos, winmenu ? true : false); 00256 } 00257 break; 00258 case WM_MENUSELECT: 00259 D2(fprintf(fil,"WM_MENUSELECT %08lx %08lx\n",wParam,lParam);) 00260 { 00261 HMENU hMenu = (HMENU)lParam; 00262 int index = wParam & 0xffff; 00263 int flags = (wParam >> 16) & 0xffff; 00264 g_menuHandler.OnMenuSelect(hMenu, index, flags); 00265 } 00266 break; 00267 // 00268 case WM_CHANGE_ICON: 00269 g_app->ChangeIcon( wParam ); 00270 break; 00271 case WM_COMMAND: 00272 switch (wParam) 00273 { 00274 case IDOK: 00275 g_app->GetDialogData(); 00276 case IDCANCEL: 00277 ShowWindow(g_hwndMain, SW_HIDE); 00278 break; 00279 case ID_POPUP_EXIT: 00280 g_app->SetQuit(); 00281 break; 00282 00283 default: 00284 break; 00285 } 00286 break; 00287 } 00288 return 0; 00289 }

DWORD WINAPI start LPVOID  lpParam  ) 
 

Definition at line 112 of file MyApp.cpp.

References MyApp::ApplyChanges(), FinderHandler::BeginTop(), MyApp::BindLocal(), MyApp::CreateTop(), FinderHandler::EndTop(), g_app, g_bQuit, g_bRestart, g_bWsRunning, MyApp::GetLocalPort(), MyApp::GetMinionPort(), MyApp::minion_connect(), MyApp::NoMinder(), MyApp::reg_minder(), and MyApp::SetCreateTop().

Referenced by MyApp::Init().

00113 { 00114 mysql_thread_init(); 00115 MyErrlog log; 00116 g_bWsRunning = true; 00117 { 00118 Database db("fd",&log); 00119 while (g_bRestart) 00120 { 00121 MySocketsLog log; 00122 FinderHandler h(db); 00123 h.RegStdLog(&log); 00124 h.ResolveLocal(); 00125 ListenSocket<ExecSocket> l(h); 00126 ListenSocket<MyMinionSocket> l2(h); 00127 // apply changes 00128 g_app->ApplyChanges(); 00129 // bind 00130 std::string address = g_app->BindLocal() ? "127.0.0.1" : "0.0.0.0"; 00131 l.Bind(address, g_app->GetLocalPort()); 00132 h.Add(&l); 00133 if (!g_app->NoMinder()) 00134 { 00135 int port = g_app->GetMinionPort(); 00136 while (l2.Bind( port )) 00137 { 00138 port++; 00139 } 00140 h.Add(&l2); 00141 h.SetLocalPort( port ); 00142 g_app->reg_minder(h, "Hello"); 00143 } 00144 // times 00145 time_t tminder = time(NULL); 00146 time_t tminion = time(NULL) - 30; 00147 time_t ttop = time(NULL); 00148 // reg new sockets 00149 h.Select(1,0); 00150 // reset restart 00151 g_bRestart = false; 00152 while (h.GetCount() && !g_bQuit && !g_bRestart) 00153 { 00154 h.Select(1,0); 00155 time_t tnow = time(NULL); 00156 if (!g_app->NoMinder()) 00157 { 00158 if (tnow - tminder > 15 * 60 ) 00159 { 00160 g_app->reg_minder(h, "Hello"); 00161 tminder = tnow; 00162 } 00163 if (tnow - tminion > 60 ) 00164 { 00165 g_app->minion_connect(h); 00166 tminion = tnow; 00167 } 00168 if (g_app->CreateTop()) 00169 { 00170 if (ttop < tnow) 00171 { 00172 h.BeginTop(); 00173 ttop = tnow + 15; 00174 } 00175 else 00176 if (ttop == tnow) 00177 { 00178 h.EndTop(); 00179 g_app->SetCreateTop( false ); 00180 } 00181 } 00182 } // if (!g_app->NoMinder()) 00183 } 00184 if (!g_app->NoMinder()) 00185 { 00186 g_app->reg_minder(h, "Goodbye"); 00187 h.Select(1,0); 00188 while (h.MinderSockets()) 00189 { 00190 h.Select(1,0); 00191 } 00192 } 00193 } // while (g_bRestart) 00194 } 00195 // 00196 g_bWsRunning = false; 00197 mysql_thread_end(); 00198 return 0; 00199 }


Variable Documentation

MyApp* g_app = NULL
 

Definition at line 80 of file MyApp.cpp.

Referenced by MyApp::MyApp(), MyDlgProc(), MyMinionSocket::OnAccept(), MyMenu::OnCommand(), MyMinionSocket::OnConnect(), MyMinionSocket::OnVerifiedLine(), and start().

bool g_bQuit = false [static]
 

Definition at line 72 of file MyApp.cpp.

Referenced by MyApp::Init(), and start().

bool g_bRestart = true [static]
 

Definition at line 74 of file MyApp.cpp.

Referenced by MyApp::GetDialogData(), and start().

bool g_bWsRunning = false [static]
 

Definition at line 76 of file MyApp.cpp.

Referenced by MyApp::Init(), and start().

HANDLE g_hD2 [static]
 

Definition at line 58 of file MyApp.cpp.

Referenced by MyApp::Init().

HANDLE g_hMutex [static]
 

Definition at line 73 of file MyApp.cpp.

Referenced by MyApp::Init().

HANDLE g_hMutexScan [static]
 

Definition at line 75 of file MyApp.cpp.

Referenced by MyApp::Init().

HWND g_hwndMain
 

Definition at line 81 of file MyApp.cpp.

Referenced by MyApp::ApplyChanges(), MyApp::ChangeIcon(), MyApp::GetDialogData(), MyApp::Init(), MyDlgProc(), MyMenu::OnCommand(), MyMinderSocket::OnConnect(), MyMinderSocket::OnConnectFailed(), MyApp::reg_minder(), MyApp::SetDialogData(), MyApp::ShowBalloonTip(), and MyApp::ShowTaskBar().

MenuHandler g_menuHandler [static]
 

Definition at line 77 of file MyApp.cpp.

Referenced by MyDlgProc().


Generated on Thu Feb 10 22:42:37 2005 for Distributed URL Classification Tool by doxygen 1.3.7