home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Samples / Balloons / Source / server.cpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  5KB  |  213 lines

  1. // Server.cpp (Server.EXE)
  2. // OCL Sample - Server Apllication for Balloons
  3.  
  4. #define __OCL_RESOLVE_TEMPLATES__
  5. #include "..\Source\server.hpp"
  6.  
  7. #include <..\source\obook.cpp>
  8.  
  9. // globals
  10.  
  11. BalloonServer server;
  12.  
  13. // code
  14.  
  15. void main(void)
  16. {
  17.  try
  18.   {
  19.    server.init();
  20.   }
  21.  
  22.  catch(OPMException err)
  23.   {
  24.    err.exMsg.error(err.errRes);
  25.    _exit(1);
  26.   }
  27.  
  28.  OApp::current().run();
  29. }
  30.  
  31.  
  32. BPipeServer::BPipeServer()
  33.   : OPipeSvr(2*sizeof(PIPEMSG),   // inSize
  34.              2*sizeof(PIPEMSG),   // outSize
  35.              sizeof(PIPEMSG),     // packet size
  36.              SVR_PIPE_OPEN_DEFAULT,
  37.              SVR_PIPE_PIPE_DEFAULT,
  38.              PIPE_TIMEOUT_DEFAULT,
  39.              5)                  // max allowed clients
  40.   {}
  41.  
  42. BPipeServer::~BPipeServer()
  43.   {}
  44.  
  45.  
  46. void BPipeServer::OPipeCommand(PVOID pvData) 
  47.   {}
  48.  
  49.  
  50.  
  51. BalloonServer::BalloonServer()
  52.  : OBook(ID_ICON),
  53.    secondPage(FALSE, "Count"),
  54.    thirdPage(TRUE, "Speed") 
  55.  {}
  56.    
  57.  
  58.    
  59. BalloonServer::~BalloonServer() 
  60. {
  61.  if (svrSem) 
  62.    delete svrSem;
  63. }
  64.  
  65.  
  66.  
  67. void BalloonServer::init()
  68. {
  69.  try
  70.   {
  71.    svrSem = new ONSem(BALL_SEM);
  72.   }
  73.  catch(OVioException ex)
  74.   {
  75.    throw OPMException(SERVER_RUNNING, 0);
  76.   }
  77.  
  78.  Buffer = &pipeMessage;
  79.  if (!beginPiping(BALL_PIPE))
  80.    throw OPMException(PIPE_FAILED, 0);
  81.  
  82.  Pages.add(&firstPage);
  83.  Pages.add(&secondPage);
  84.  Pages.add(&thirdPage);
  85.  
  86.  try 
  87.   {
  88.    createBook("Balloons Server", 270, 170, NB_STANDARD);
  89.   }
  90.  
  91.  catch(OPMException err)
  92.   {
  93.    err.viewError();
  94.    throw err;
  95.   }
  96.  
  97.  showFrame();
  98. }
  99.  
  100.  
  101.  
  102. // notebook pages
  103.  
  104. // control panel
  105.  
  106. BOOL BalloonServer::OCommand(ULONG msg, MPARAM mp1, MPARAM mp2)
  107. {
  108.  switch(msg)
  109.   {
  110.    case WM_CLOSE:
  111.     if (connectedClients > 0) {
  112.       pipeMessage.Type = PIPE_SERVER_EXIT;
  113.       pipeMessage.Data = 0;
  114.       postPipe(&pipeMessage, 0); }   // post to all clients
  115.     OBook::OCommand(msg, mp1, mp2);
  116.     stopPiping();
  117.     forceQuit();
  118.     break;
  119.  
  120.    default:
  121.     return(OBook::OCommand(msg, mp1, mp2));
  122.   }
  123.  return(TRUE);
  124. }
  125.  
  126.  
  127. BOOL CtrlPanel::OCommand(ULONG msg, MPARAM mp1, MPARAM mp2)
  128. {
  129.  switch(msg)
  130.   {
  131.    case WM_COMMAND:
  132.     switch(SHORT1FROMMP(mp1))
  133.      {
  134.       case CONTROL_STOP:
  135.        if (server.connectedClients > 0) {
  136.          server.pipeMessage.Type = PIPE_STOP_BALLOONS;
  137.          server.pipeMessage.Data = 0;
  138.          server.postPipe(&server.pipeMessage, 0); }   // post to all clients
  139.        break;
  140.  
  141.       case CONTROL_START:
  142.        if (server.connectedClients > 0) {
  143.          server.pipeMessage.Type = PIPE_START_BALLOONS;
  144.          server.pipeMessage.Data = 0;
  145.          server.postPipe(&server.pipeMessage, 0); }   // post to all clients
  146.        break;
  147.  
  148.       case CONTROL_XSERV:
  149.        WinSendMsg(server.hwnd, WM_CLOSE, NULL, NULL);
  150.        break;
  151.  
  152.       case CONTROL_XCLIENT:
  153.        if (server.connectedClients > 0) {
  154.          server.pipeMessage.Type = PIPE_STOP_CLIENT;
  155.          server.pipeMessage.Data = 0;
  156.          server.postPipe(&server.pipeMessage, 0); }   // post to all clients
  157.        break;
  158.       }
  159.     break;
  160.  
  161.    default:
  162.     return(OBookPage::OCommand(msg, mp1, mp2));
  163.   }
  164.  return(TRUE);
  165. }
  166.  
  167.  
  168. BOOL NumSpeedControl::OCommand(ULONG msg, MPARAM mp1, MPARAM mp2)
  169. {
  170.  switch(msg)
  171.   {
  172.    case WM_INITDLG: {
  173.     SWP swp;
  174.  
  175.     slider = new OSlider(NUM_SLIDER, hwnd, 5, 0, 5, 0,
  176.                          SLS_HORIZONTAL | SLS_CENTER | SLS_SNAPTOINCREMENT |
  177.                          SLS_BUTTONSLEFT | SLS_HOMELEFT | SLS_PRIMARYSCALE1 |
  178.                          SLS_RIBBONSTRIP);
  179.     WinQueryWindowPos(WinWindowFromID(hwnd, NUM_SLIDER_PLACE), &swp);
  180.     slider->createSlider(swp.x, swp.y, swp.cx, swp.cy);
  181.     slider->setTickSize(5);
  182.     slider->setFont("8.Helv");
  183.     slider->setSliderScaleText("1", 0);
  184.     slider->setSliderScaleText("2", 1);
  185.     slider->setSliderScaleText("3", 2);
  186.     slider->setSliderScaleText("4", 3);
  187.     slider->setSliderScaleText("5", 4);
  188.     if (isSpeedCtrl)
  189.       WinSetDlgItemText(hwnd, NUM_TXT1, "Select the speed of flying balloons...");
  190.     break; }
  191.  
  192.    case WM_CONTROL:
  193.     switch(SHORT2FROMMP(mp1)) {
  194.      case SLN_CHANGE:
  195.        if (server.connectedClients > 0) {
  196.         if (isSpeedCtrl)
  197.           server.pipeMessage.Type = PIPE_SET_SPEED;
  198.         else
  199.           server.pipeMessage.Type = PIPE_SET_NUM;
  200.         server.pipeMessage.Data = 1 + slider->getSliderArmPos();
  201.         server.postPipe(&server.pipeMessage, 0); }     // post to all clients
  202.       break; }
  203.     break;
  204.  
  205.    default:
  206.     return(OBookPage::OCommand(msg, mp1, mp2));
  207.   }
  208.  return(TRUE);
  209. }
  210.  
  211.  
  212. // end of source
  213.