home *** CD-ROM | disk | FTP | other *** search
/ PC Press 1997 July / Sezamfile97_2.iso / windows / program / activex / axtsamp.exe / TSBRANCH.EXE / FRESERVE / SERVER.CPP < prev    next >
C/C++ Source or Header  |  1996-12-29  |  6KB  |  230 lines

  1. /*+==========================================================================
  2.   File:      SERVER.CPP
  3.  
  4.   Summary:   Implementation file for the CServer server-related utility
  5.              C++ object.  This object encapsulates the server's internal
  6.              control of global server object and lock counts.
  7.  
  8.              For a comprehensive tutorial code tour of this module's
  9.              contents and offerings see the tutorial FRESERVE.HTM
  10.              file. For more specific technical details on the internal
  11.              workings see the comments dispersed throughout the module's
  12.              source code.
  13.  
  14.   Classes:   CServer.
  15.  
  16.   Functions:
  17.  
  18.   Origin:    4-5-96: atrent - Editor-inheritance from SERVER.CPP in
  19.                the DLLSERVE Tutorial Code Sample.
  20.  
  21. ----------------------------------------------------------------------------
  22.   This file is part of the Microsoft ActiveX Tutorial Code Samples.
  23.  
  24.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  25.  
  26.   This source code is intended only as a supplement to Microsoft
  27.   Development Tools and/or on-line documentation.  See these other
  28.   materials for detailed information regarding Microsoft code samples.
  29.  
  30.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  31.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  32.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  33.   PARTICULAR PURPOSE.
  34. ==========================================================================+*/
  35.  
  36. /*---------------------------------------------------------------------------
  37.   We include WINDOWS.H for all Win32 applications.
  38.   We include OLE2.H because we will be calling the COM/OLE Libraries.
  39.   We include APPUTIL.H because we will be building this DLL using
  40.     the convenient Virtual Window and Dialog classes and other
  41.     utility functions in the APPUTIL Library (ie, APPUTIL.LIB).
  42.   We include SERVER.H for the object class declarations for the
  43.     C++ CServer server control object.
  44. ---------------------------------------------------------------------------*/
  45. #include <windows.h>
  46. #include <ole2.h>
  47. #include <apputil.h>
  48. #include "server.h"
  49.  
  50.  
  51. /*---------------------------------------------------------------------------
  52.   Implementation the internal CServer C++ object.  Used to encapsulate
  53.   some server data and the methods for Lock and Object count incrementing
  54.   and decrementing.
  55. ---------------------------------------------------------------------------*/
  56.  
  57. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  58.   Method:   CServer::CServer
  59.  
  60.   Summary:  CServer Constructor.
  61.  
  62.   Args:     void
  63.  
  64.   Modifies: .
  65.  
  66.   Returns:  void
  67. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  68. CServer::CServer(void)
  69. {
  70.   // Zero the Object and Lock counts for this attached process.
  71.   m_cObjects = 0;
  72.   m_cLocks = 0;
  73.  
  74.   return;
  75. }
  76.  
  77.  
  78. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  79.   Method:   CServer::~CServer
  80.  
  81.   Summary:  CServer Destructor.
  82.  
  83.   Args:     void
  84.  
  85.   Modifies: .
  86.  
  87.   Returns:  void
  88. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  89. CServer::~CServer(void)
  90. {
  91.   return;
  92. }
  93.  
  94.  
  95. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  96.   Method:   CServer::Lock
  97.  
  98.   Summary:  Increment the Server's Lock count.
  99.  
  100.   Args:     void
  101.  
  102.   Modifies: .
  103.  
  104.   Returns:  void
  105. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  106. void CServer::Lock(void)
  107. {
  108.   LONG cLocks;
  109.  
  110.   if (OwnThis())
  111.   {
  112.     cLocks = ++m_cLocks;
  113.  
  114.     UnOwnThis();
  115.   }
  116.  
  117.   return;
  118. }
  119.  
  120.  
  121. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  122.   Method:   CServer::Unlock
  123.  
  124.   Summary:  Decrement the Server's Lock count.
  125.  
  126.   Args:     void
  127.  
  128.   Modifies: .
  129.  
  130.   Returns:  void
  131. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  132. void CServer::Unlock(void)
  133. {
  134.   LONG cLocks;
  135.  
  136.   if (OwnThis())
  137.   {
  138.     cLocks = --m_cLocks;
  139.  
  140.     UnOwnThis();
  141.   }
  142.  
  143.   return;
  144. }
  145.  
  146.  
  147. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  148.   Method:   CServer::ObjectsUp
  149.  
  150.   Summary:  Increment the Server's living Object count.
  151.  
  152.   Args:     void
  153.  
  154.   Modifies: .
  155.  
  156.   Returns:  void
  157. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  158. void CServer::ObjectsUp(void)
  159. {
  160.   LONG cObjects;
  161.  
  162.   if (OwnThis())
  163.   {
  164.     cObjects = ++m_cObjects;
  165.  
  166.     UnOwnThis();
  167.   }
  168.  
  169.   return;
  170. }
  171.  
  172.  
  173. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  174.   Method:   CServer::ObjectsDown
  175.  
  176.   Summary:  Decrement the Server's living object count.
  177.  
  178.   Args:     void
  179.  
  180.   Modifies: .
  181.  
  182.   Returns:  void
  183. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  184. void CServer::ObjectsDown(void)
  185. {
  186.   LONG cObjects;
  187.  
  188.   if (OwnThis())
  189.   {
  190.     cObjects = --m_cObjects;
  191.  
  192.     UnOwnThis();
  193.   }
  194.  
  195.   return;
  196. }
  197.  
  198.  
  199. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  200.   Method:   CServer::CanUnloadNow
  201.  
  202.   Summary:  Checke if we can unload the server (ie, if there are no longer
  203.             any living COM objects and no locks.
  204.  
  205.   Args:     void
  206.  
  207.   Modifies: .
  208.  
  209.   Returns:  HRESULT
  210.               S_OK if this server can be unloaded.
  211.               S_FALSE if this server can not be unloaded.
  212. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  213. HRESULT CServer::CanUnloadNow(void)
  214. {
  215.   HRESULT hr = S_FALSE;
  216.   LONG cObjects, cLocks;
  217.  
  218.   if (OwnThis())
  219.   {
  220.     cObjects = m_cObjects;
  221.     cLocks = m_cLocks;
  222.  
  223.     hr = (0L==cObjects && 0L==cLocks) ? S_OK : S_FALSE;
  224.  
  225.     UnOwnThis();
  226.   }
  227.  
  228.   return hr;
  229. }
  230.