home *** CD-ROM | disk | FTP | other *** search
/ Netscape Plug-Ins Developer's Kit / Netscape_Plug-Ins_Developers_Kit.iso / source / Chap09 / NPTREE / NPTREE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-21  |  2.1 KB  |  127 lines

  1.  
  2. //
  3. // nptree.cpp - CPU Monitor Plug-in
  4. //
  5.  
  6. #include "..\inc\stdafx.h"
  7. #include "nptree.h"
  8. #include "npwindow.h"
  9.  
  10.  
  11. //
  12. // Constructor - Initialize variables. Get the instance pointer for any
  13. //               NPP type calls.
  14. //
  15. CCpuMon::CCpuMon (NPP pInstance)
  16. {
  17.     this->pInstance = pInstance;
  18.  
  19.     bRunningCGIProgram = FALSE;
  20. }
  21.  
  22.  
  23. //
  24. // Destructor
  25. //
  26. CCpuMon::~CCpuMon ()
  27. {
  28. }
  29.  
  30.  
  31. //
  32. // Open - Get ready for data, called from Netscape's NPP_NewStream
  33. //
  34. BOOL CCpuMon::Open (NPStream* pStream)
  35. {
  36.     this->pStream = pStream;
  37.  
  38.     return TRUE;
  39. }
  40.  
  41.  
  42. //
  43. // EndOfStream - Called from NPP_DestroyStream. The stream is done. Our plug-in
  44. //               has all the data.
  45. //
  46. BOOL CCpuMon::EndOfStream (void)
  47. {
  48.     // CPU Monitor is file based, just return.
  49.  
  50.     return TRUE;
  51. }
  52.  
  53.  
  54. //
  55. // GotFileName - Called from NPP_StreamAsFile with a local filename 
  56. //
  57. BOOL CCpuMon::GotFileName (const char* fname)
  58. {
  59.     // Open the file in ASCII read only
  60.  
  61.     FILE* fp = fopen (fname, "r");
  62.  
  63.     if (fp)
  64.     {
  65.         if (bRunningCGIProgram)
  66.         {
  67.             // CGI program is running, update the graphic
  68.  
  69. //            pWindow->UpdateChart (fp);
  70.             fclose (fp);
  71.  
  72.             return TRUE;
  73.         }
  74.         
  75.         if (fgets (ProgramURL, sizeof(ProgramURL), fp))
  76.         {
  77.             // The first file starts us. It must contain the URL
  78.             // for the CGI program.
  79.  
  80.             fclose (fp);
  81.  
  82.             char* p = strchr(ProgramURL, '\n');  // Remove newline
  83.  
  84.             if (p)
  85.                 *p = NULL;
  86.  
  87.             // Flag the CGI program as running and get the URL
  88.             
  89.             bRunningCGIProgram = TRUE;
  90.  
  91.             NPError rc = NPN_GetURL (pInstance, ProgramURL, NULL);
  92.         }
  93.     }
  94.  
  95.     return TRUE;
  96. }
  97.  
  98.  
  99. //
  100. // RequestUpdate - Called from CPluginWindow::OnUpdate when the update button
  101. //                 is clicked.  
  102. //
  103. BOOL CCpuMon::RequestUpdate (void)
  104. {
  105.     if (!bRunningCGIProgram)
  106.         return FALSE;
  107.  
  108.     NPError rc = NPN_GetURL (pInstance, ProgramURL, NULL);
  109.  
  110.     if (rc)
  111.         return FALSE;
  112.  
  113.     return TRUE;
  114. }
  115.  
  116.  
  117. //
  118. // Close - Called from NPP_Destroy. This plug-in instance is history. Free
  119. //         all resources.
  120. //
  121. BOOL CCpuMon::Close (void)
  122. {
  123.     return TRUE;    
  124. }
  125.  
  126.  
  127.