t_rpc_client.cpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002 *                                                                             *
00003 *  Name   : test_rpc_client                                                   *
00004 *  Author : Chris Koeritz                                                     *
00005 *                                                                             *
00006 *******************************************************************************
00007 * Copyright (c) 1995-$now By Author.  This program is free software; you can  *
00008 * redistribute it and/or modify it under the terms of the GNU General Public  *
00009 * License as published by the Free Software Foundation; either version 2 of   *
00010 * the License or (at your option) any later version.  This is online at:      *
00011 *     http://www.fsf.org/copyleft/gpl.html                                    *
00012 * Please send any updates to: fred@gruntose.com                               *
00013 \*****************************************************************************/
00014 
00015 #include "shared_code.rh"
00016 #include "t_rpc_client.h"
00017 
00018 #include <basis/chaos.h>
00019 #include <basis/guards.h>
00020 #include <geometric/rectangle.cpp>
00021 #include <mfc_ext/debugging_console_window.h>
00022 #include <mfc_ext/debugging_frame.h>
00023 #include <opsystem/path_configuration.h>
00024 #include <data_struct/static_memory_gremlin.h>
00025 #include <win_ext/event_ex.h>
00026 
00027 HOOPLE_STARTUP_CODE;
00028 
00029 using namespace geometric;
00030 
00031 const int CLIENT_WIN_TIMER_ID = 298;
00032   // the identifier for our window's timer.
00033 
00035 
00036 const u_int point_alert = POINT_ALERT();
00037 
00038 BEGIN_MESSAGE_MAP(test_rpc_client, CFrameWnd)
00039   //{{AFX_MSG_MAP(test_rpc_client)
00040   ON_WM_CREATE()
00041   ON_WM_CLOSE()
00042   ON_WM_TIMER()
00043   //}}AFX_MSG_MAP
00044   ON_COMMAND(CM_FILE_OPEN_CLI, menu_open_rpc)
00045   ON_COMMAND(CM_FILE_CLOSE_CLI, menu_close_rpc)
00046   ON_COMMAND(CM_FILE_QUIT_CLI, menu_exit_program)
00047   ON_COMMAND(CM_START_RANDOM, menu_start_random)
00048   ON_COMMAND(CM_STOP_RANDOM, menu_stop_random)
00049   ON_REGISTERED_MESSAGE(point_alert, handle_update)
00050 END_MESSAGE_MAP()
00051 
00053 
00054 test_rpc_client::test_rpc_client()
00055 : CFrameWnd(),
00056 #ifdef DEBUG_RPC
00057   console(new debugging_frame()),
00058 #endif
00059   my_client(NIL),
00060   rando(new chaos)
00061 {}
00062 
00063 test_rpc_client::~test_rpc_client()
00064 {
00065   WHACK(rando);
00066   WHACK(my_client);
00067 }
00068 
00069 void test_rpc_client::start_timer(int interval)
00070 { SetTimer(CLIENT_WIN_TIMER_ID, interval, NIL); }
00071 
00072 void test_rpc_client::stop_timer() { ::KillTimer(GetSafeHwnd(), CLIENT_WIN_TIMER_ID); }
00073 
00074 void test_rpc_client::menu_start_random() { start_timer(40); }
00075 
00076 void test_rpc_client::menu_stop_random() { stop_timer(); }
00077 
00078 int test_rpc_client::OnCreate(LPCREATESTRUCT lpCreateStruct)
00079 {
00080   if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1;
00081 
00082 #ifdef DEBUG_RPC
00083   console->console().name(path_configuration::make_logfile_name
00084       ("t_rpccli.log"));
00085   if (!console->Create(NIL, "RPC Client Bug Console")) return -1;
00086   console->show();
00087 #endif
00088 
00089   the_menu.LoadMenu(CLIENT_MENU);
00090   SetMenu(&the_menu);
00091 
00092   HICON icon = LoadIcon(AfxGetInstanceHandle(),
00093       MAKEINTRESOURCE(RPC_tester_icon));
00094   SetIcon(icon, true);  // large icon.
00095   SetIcon(icon, false);  // small icon.
00096 
00097   return 0;
00098 }
00099 
00100 void test_rpc_client::OnClose()
00101 {
00102   menu_close_rpc();
00103   stop_timer();
00104   CFrameWnd::OnClose();
00105 }
00106 
00107 void test_rpc_client::OnTimer(u_int formal(timer_id))
00108 {
00109   stop_timer();
00110   if (!my_client) return;
00111   if (rando->inclusive(0, 999) < 200) {
00112     RECT temp;
00113     GetClientRect(&temp);
00114     screen_rectangle window_size(temp.left, temp.top, temp.right, temp.bottom);
00115     rpc_point to_fill(rando->inclusive(0, window_size.width()),
00116         rando->inclusive(0, window_size.height()));
00117     my_client->add_point(to_fill);
00118   }
00119   menu_start_random();
00120 }
00121 
00122 void test_rpc_client::menu_exit_program() { PostMessage(WM_CLOSE); }
00123 
00124 void test_rpc_client::menu_open_rpc()
00125 {
00126   if (my_client) {
00127 #ifdef DEBUG_RPC
00128     console->console().print("the rpc client is already open.");
00129 #endif
00130     return;
00131   }
00132   window_handle recip = NIL;
00133 #ifdef DEBUG_RPC
00134   recip = console->GetSafeHwnd();
00135 #endif
00136   my_client = new example_rpc_client(this, recip);
00137 }
00138 
00139 void test_rpc_client::menu_close_rpc()
00140 {
00141   stop_timer();
00142   if (my_client) {
00143     delete my_client;
00144     my_client = NIL;
00145   }
00146 }
00147 
00148 LRESULT test_rpc_client::handle_update(WPARAM formal(wp), LPARAM formal(lp))
00149 {
00150   FUNCDEF("handle_update");
00151   if (!my_client)
00152     deadly_error(name().s(), func, "no rpc client to get points from!");
00153   my_client->updates_waiting();
00154   return 0;
00155 }
00156 
00158 
00159 class rpc_client_test_application : public CWinApp
00160 {
00161 public:
00162   rpc_client_test_application() : CWinApp() {}
00163 
00164   virtual BOOL InitInstance();
00165 };
00166 
00167 
00168 BOOL rpc_client_test_application::InitInstance()
00169 {
00170   test_rpc_client *new_main = new test_rpc_client();
00171   ASSERT_VALID(new_main);
00172   if (new_main) {
00173     new_main->Create(NIL, "rpc client test");  // invoke the creator.
00174 
00175     // assign the main window pointer to our new window.
00176     m_pMainWnd = new_main;  // assign the root window to our new one.
00177 
00178     // make the window visible.
00179     m_pMainWnd->ShowWindow(m_nCmdShow);
00180   }
00181   return true;
00182 }
00183 
00184 rpc_client_test_application theApp;

Generated on Fri Nov 28 04:29:34 2008 for HOOPLE Libraries by  doxygen 1.5.1