home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / OMemu.cpp < prev    next >
C/C++ Source or Header  |  1997-04-05  |  6KB  |  209 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OMemu.cpp
  5.  
  6. /*
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  13.  *    endorse or promote products derived from this software
  14.  *    without specific prior written permission.
  15.  * 3. See OCL.INF for a detailed copyright notice.
  16.  *
  17.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  18.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27.  * SUCH DAMAGE.
  28.  */
  29.  
  30.  
  31. // $Header: W:/Projects/OCL/Source/rcs/OMemu.cpp 1.50 1996/08/11 23:49:22 B.STEIN Release $
  32.  
  33.  
  34. #define __OCL_SOURCE__
  35.  
  36. #define OINCL_OSTRING
  37. #define OINCL_BASE
  38.  
  39. #include <ocl.hpp>
  40. #include <OMemu.hpp>
  41. #include <OMessage.hpp>
  42.  
  43.  
  44. #if defined(__EMX__)
  45.   template class OList<gi_process_data_s>;
  46. #endif
  47.  
  48.  
  49. OMemu::OMemu()
  50.   : memu_library(NULL),
  51.     EP_get_general_info(NULL),
  52.     EP_get_process_info(NULL)
  53. {
  54.  HFILE  hf;
  55.  ULONG  dummy;
  56.  
  57.  if(!DosOpen("OS20MMU$", &hf, &dummy, 0L, FILE_NORMAL, FILE_OPEN,
  58.              OPEN_ACCESS_WRITEONLY | 
  59.              OPEN_SHARE_DENYNONE | 
  60.              OPEN_FLAGS_FAIL_ON_ERROR, 0L))
  61.   {
  62.    try
  63.     {
  64.      memu_library = new ODynamicLib("OS20MEMU");
  65.      EP_get_general_info = (PMEMU_GGI) memu_library->queryFn("EP_get_general_info"); 
  66.      EP_get_process_info = (PMEMU_GPI) memu_library->queryFn("EP_get_process_info"); 
  67.     }
  68.    catch(OVioException& ex)
  69.     {
  70.      if (memu_library)
  71.        delete memu_library;
  72.      throw ex;
  73.     }
  74.    DosClose(hf); 
  75.   }
  76.  else
  77.   throw OVioException(OCL::error(77), ERROR_FILE_NOT_FOUND);
  78. }
  79.  
  80.  
  81. OMemu::~OMemu()
  82. {
  83.  reset();
  84.  if (memu_library)
  85.    delete memu_library;
  86. }
  87.  
  88.  
  89. PSZ OMemu::isOfType() const
  90.  return("OMemu"); 
  91. }
  92.  
  93.  
  94.  
  95. BOOL OMemu::querySystem()
  96. {
  97.  pos20memu_general_info  pgi = NULL;
  98.  pgi_process_data_s temp = NULL;
  99.  
  100.  reset();
  101.  
  102.  if (DosAllocMem((PPVOID)&pgi, 0x0000ffffL, 
  103.      PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_TILE))
  104.    return(FALSE);
  105.  
  106.  pgi->gi_cpids = 0x0000ffffL - sizeof(os20memu_general_info);
  107.  
  108.  if (EP_get_general_info(pgi) == ERROR_FAULT_OCCURRED)
  109.   {
  110.    DosFreeMem(pgi);
  111.    return(FALSE);
  112.   }
  113.  
  114.  gi_version             = pgi->gi_version;
  115.  gi_phys_mem            = pgi->gi_phys_mem;
  116.  gi_free_mem            = pgi->gi_free_mem;
  117.  gi_tot_res             = pgi->gi_tot_res;
  118.  gi_res_sys_mem         = pgi->gi_res_sys_mem;
  119.  gi_swp_sys_mem         = pgi->gi_swp_sys_mem;
  120.  gi_swappable_sys_mem   = pgi->gi_swappable_sys_mem;
  121.  gi_inmem_swp           = pgi->gi_inmem_swp;
  122.  gi_inmem_dsc           = pgi->gi_inmem_dsc;
  123.  gi_ondisk_dsc          = pgi->gi_ondisk_dsc;
  124.  gi_ondisk_swp          = pgi->gi_ondisk_swp;
  125.  gi_notacc_swp          = pgi->gi_notacc_swp;
  126.  gi_slock_swp           = pgi->gi_slock_swp;
  127.  gi_slock_dsc           = pgi->gi_slock_dsc;
  128.  gi_llock_swp           = pgi->gi_llock_swp;
  129.  gi_llock_dsc           = pgi->gi_llock_dsc;
  130.  gi_swapfile_size       = pgi->gi_swapfile_size;
  131.  gi_swapfile_inuse      = pgi->gi_swapfile_inuse;
  132.  gi_swapfile_max_inuse  = pgi->gi_swapfile_max_inuse;
  133.  gi_app_sys_mem_res     = pgi->gi_app_sys_mem_res;
  134.  gi_app_sys_mem_im      = pgi->gi_app_sys_mem_im;
  135.  gi_app_sys_mem_od      = pgi->gi_app_sys_mem_od;
  136.  gi_shr_sys_mem_res     = pgi->gi_shr_sys_mem_res;
  137.  gi_shr_sys_mem_im      = pgi->gi_shr_sys_mem_im;
  138.  gi_shr_sys_mem_od      = pgi->gi_shr_sys_mem_od;
  139.  gi_cshr_im             = pgi->gi_cshr_im;
  140.  gi_cshr_od             = pgi->gi_cshr_od;
  141.  gi_cshr_nt             = pgi->gi_cshr_nt;
  142.  gi_cpids               = pgi->gi_cpids;
  143.  
  144.  for(ULONG i = 0; i < gi_cpids; i++) {
  145.    temp = new gi_process_data_s;
  146.    memcpy((PVOID)temp, (PVOID)&pgi->gi_process_data[i], sizeof(gi_process_data_s)); 
  147.    add(temp); }
  148.  
  149.  DosFreeMem(pgi);
  150.  return(TRUE); 
  151. }
  152.  
  153.  
  154. BOOL OMemu::queryGeneralInfo()
  155. {
  156.  os20memu_general_info info;
  157.  
  158.  memset(&info, 0, sizeof(os20memu_general_info));
  159.  if (EP_get_general_info(&info) == ERROR_FAULT_OCCURRED)
  160.    return(FALSE);
  161.  
  162.  gi_version             = info.gi_version;
  163.  gi_phys_mem            = info.gi_phys_mem;
  164.  gi_free_mem            = info.gi_free_mem;
  165.  gi_tot_res             = info.gi_tot_res;
  166.  gi_res_sys_mem         = info.gi_res_sys_mem;
  167.  gi_swp_sys_mem         = info.gi_swp_sys_mem;
  168.  gi_swappable_sys_mem   = info.gi_swappable_sys_mem;
  169.  gi_inmem_swp           = info.gi_inmem_swp;
  170.  gi_inmem_dsc           = info.gi_inmem_dsc;
  171.  gi_ondisk_dsc          = info.gi_ondisk_dsc;
  172.  gi_ondisk_swp          = info.gi_ondisk_swp;
  173.  gi_notacc_swp          = info.gi_notacc_swp;
  174.  gi_slock_swp           = info.gi_slock_swp;
  175.  gi_slock_dsc           = info.gi_slock_dsc;
  176.  gi_llock_swp           = info.gi_llock_swp;
  177.  gi_llock_dsc           = info.gi_llock_dsc;
  178.  gi_swapfile_size       = info.gi_swapfile_size;
  179.  gi_swapfile_inuse      = info.gi_swapfile_inuse;
  180.  gi_swapfile_max_inuse  = info.gi_swapfile_max_inuse;
  181.  gi_app_sys_mem_res     = info.gi_app_sys_mem_res;
  182.  gi_app_sys_mem_im      = info.gi_app_sys_mem_im;
  183.  gi_app_sys_mem_od      = info.gi_app_sys_mem_od;
  184.  gi_shr_sys_mem_res     = info.gi_shr_sys_mem_res;
  185.  gi_shr_sys_mem_im      = info.gi_shr_sys_mem_im;
  186.  gi_shr_sys_mem_od      = info.gi_shr_sys_mem_od;
  187.  gi_cshr_im             = info.gi_cshr_im;
  188.  gi_cshr_od             = info.gi_cshr_od;
  189.  gi_cshr_nt             = info.gi_cshr_nt;
  190.  gi_cpids               = info.gi_cpids;
  191.  
  192.  return(TRUE);
  193. }
  194.  
  195.  
  196. ULONG OMemu::makeKByte(ULONG pages)
  197. {
  198.  ULONG bytes = pages * 4096;
  199.  
  200.  if (bytes < 1024)
  201.    return(0);
  202.  else
  203.    return(bytes/1024);
  204. }
  205.  
  206.  
  207. // end of source
  208.