⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netdiagnostics.c

📁 基于高通的brew平台上的手机网络诊断程序netdiagnostics
💻 C
📖 第 1 页 / 共 4 页
字号:
   }

   for (i = 0; i < ARRAY_SIZE(pApp->m_ppszHistory); ++i) {
      FREE(pApp->m_ppszHistory[i]);
   }
   
   // Release memory buffers
   FREE(pApp->m_pszFormData);    // FREE(NULL) is okay in BREW

   // Release other interfaces
   ReleaseObj((void**)&pApp->m_pFileMgr);
   ReleaseObj((void**)&pApp->m_pHTMLViewer);
   ReleaseObj((void**)&pApp->m_pINetMgr);
   ReleaseObj((void**)&pApp->m_pIWeb);
}

//*****************************************************************************
// EVENT HANDLING FUNCTIONS
//*****************************************************************************

/*===========================================================================

FUNCTION: ND_HandleEvent

DESCRIPTION:
	This is the main EventHandler for this app. All events to this app are handled in this
	function. All APPs must supply an Event Handler.  Key events are passed to specific
  event-handers depending on the current state of the application.

PARAMETERS:
	pi [in] - Pointer to the AEEApplet structure. This structure contains information specific
  	to this applet. It was initialized during the AEEClsCreateInstance() function.

	eCode [in] - Specifies the Event sent to this applet

  wParam [in] - Event specific data.

  dwParam [in] - Event specific data.

DEPENDENCIES:
  None

RETURN VALUE:
  TRUE - If the app has processed the event
  FALSE - If the app did not process the event

SIDE EFFECTS:
  None
===========================================================================*/

static boolean ND_HandleEvent(CNetDiagnosticsApp* pApp, AEEEvent eCode, uint16 wParam, uint32 dwParam )
{
   if (pApp->m_pIStatic && ISTATIC_HandleEvent(pApp->m_pIStatic, eCode, wParam, dwParam))
      return TRUE;
   if (IHTMLVIEWER_HandleEvent(pApp->m_pHTMLViewer, eCode, wParam, dwParam))
      return TRUE;

   switch(eCode)
   {
      case EVT_APP_START:
         ND_DisplaySplashScreen(pApp);
         return TRUE;

      case EVT_APP_STOP:
         return TRUE;

      case EVT_APP_SUSPEND:
         // Stop any current network or web access processes.  These functions
         // also cancel all appropriate callbacks.

         ND_EchoCleanup( pApp);
         ND_HTTPCleanup( pApp);

         // Cleanup all timers

         ISHELL_CancelTimer( pApp->a.m_pIShell, (PFNNOTIFY)ND_DisplaySplashScreenCB, pApp);

         // Set all controls to the inactive state

         if( pApp->m_pHTMLViewer )
            IHTMLVIEWER_SetActive( pApp->m_pHTMLViewer, FALSE );

         return TRUE;

      case EVT_APP_RESUME:
         IHTMLVIEWER_SetRect( pApp->m_pHTMLViewer, &pApp->m_rc );
         IHTMLVIEWER_SetActive( pApp->m_pHTMLViewer, TRUE );
         return TRUE;

      case EVT_KEY:
         switch (wParam)
         {
            case AVK_CLR:
               // call cleanup function
               if( pApp->m_cntHistory > 1 )
               {
                 ND_GoTo(pApp, NULL);
                 return TRUE;
               }
         }
         break;
   }
   return FALSE;
}

//*****************************************************************************
// HTML VIEWER NOTIFICATION CALLBACK FUNCTIONS
//****************************************************************************
static void ND_NotifyCB( void* pvUser, HViewNotify* pNotify )
{
   CNetDiagnosticsApp* pApp = (CNetDiagnosticsApp*) pvUser;

   switch( pNotify->code )
   {

   case HVN_REDRAW_SCREEN:
      IDISPLAY_ClearScreen(pApp->a.m_pIDisplay);
      IHTMLVIEWER_Redraw(pApp->m_pHTMLViewer);
      break;

   case HVN_JUMP:
   case HVN_SUBMIT:
      ND_GoTo(pApp, pNotify->u.jump.pszURL);
      break;

   case HVN_DONE:
      IHTMLVIEWER_SetRect(pApp->m_pHTMLViewer, &pApp->m_rc);
      IHTMLVIEWER_Redraw( pApp->m_pHTMLViewer );
      break;

   }
}



/*===========================================================================

FUNCTION: ND_GoTo

DESCRIPTION:

   Activate the appropriate view as described by the given URL.  This adds an
   entry onto the history list, or returns to the previous history entry.

PARAMETERS:
   pszURL = URL describing the view to activate and add to the history,
            or NULL to indicate that the previous history entry should be used

   pData [in] - The user data pointer that is passed as the only parameter
    to the callback.

DEPENDENCIES:
  None

RETURN VALUE:
  None

SIDE EFFECTS:
  Causes the phone display to be updated.
===========================================================================*/

static void ND_GoTo(CNetDiagnosticsApp *pApp, const char *pszURL)
{
   int pos = pApp->m_cntHistory;    // pos = number of hist entries = next history entry

   if (pszURL == NULL) {
      // go back
      if (pos < 2)
         return;
      --pos;
      pszURL = pApp->m_ppszHistory[pos-1];   // use 'top' entry
   } else {
      // add new entry to history
      if (pos >= MAX_HIST)
         return;
      ++pos;
      StrReplace(&pApp->m_ppszHistory[pos-1], pszURL);
   }

   // Cleanup previous state

   if (pApp->m_pfnViewCleanup) {
      pApp->m_pfnViewCleanup(pApp);
      pApp->m_pfnViewCleanup = NULL;
   }

   // Activate appropriate state
   
   pApp->m_cntHistory = pos;

   if (STRBEGINS("test:", pszURL)) {
      // read form data and begin test
      ND_StartTest(pApp, pszURL);
   } else /*if (STRBEGINS("file:", pszURL))*/ {
      // read and display file
      ND_DisplayMenu(pApp, pszURL);
   }
}


//*****************************************************************************
// DISPLAY MANIPULATION FUNCTIONS
//****************************************************************************

/*===========================================================================

FUNCTION: ND_DisplaySplashScreen

DESCRIPTION:
	This function clears the device screen and displays the application's 
  splash screen in the center of the display.  The function then sets a callback
  ND_DisplaySplashScreenCB to start the application's main menu screen.

  If the splash image fails to load, then just display the menu and 
  skip the callback.

PARAMETERS:
	pData [in] - The user data pointer that is passed as the only parameter
    to the callback.

DEPENDENCIES:
  None

RETURN VALUE:
  None

SIDE EFFECTS:
  Causes the phone display to be updated.
===========================================================================*/
static void ND_DisplaySplashScreenCB(CNetDiagnosticsApp* pApp)
{
   // Display main form
   ND_GoTo(pApp, JUMP_MAIN);
}

static void ND_DisplaySplashScreen(CNetDiagnosticsApp* pApp)
{
   IImage* pSplash = NULL;
   AEEImageInfo rImageInfo;

   if((pSplash = ISHELL_LoadResImage( pApp->a.m_pIShell, NETDIAGNOSTICS_RES_FILE, IDB_SPLASH)) != NULL)
   {
      // Get image information
      IIMAGE_GetInfo(pSplash, &rImageInfo);

      // Clear Device screen
      IDISPLAY_ClearScreen(pApp->a.m_pIDisplay);

      // Draw the image in the center of the screen
      IIMAGE_Draw(pSplash, (pApp->m_rc.dx/2) - (rImageInfo.cx/2), (pApp->m_rc.dy/2) - (rImageInfo.cy/2));

      // The image is no longer needed so release it
      IIMAGE_Release(pSplash);

      // Set the callback timer
      ISHELL_SetTimer( pApp->a.m_pIShell, SPLASH_TIMER_DURATION, (PFNNOTIFY)ND_DisplaySplashScreenCB, pApp);
    
      // Update Display
      IDISPLAY_Update(pApp->a.m_pIDisplay);

      return;
   }
   else
   {
     ND_GoTo( pApp, JUMP_MAIN );
   }
}

/*===========================================================================

FUNCTION: ND_DisplayMenu

DESCRIPTION:
	This function clears the device screen and displays the components of
  the application's Main Menu screen.  This consists of updating the 
  title bar text at the top of the screen and the HTML Viewer Control in the 
  remaining space on the screen.
  
  An HTML file is opened via the IFILE interface and its stream is passed
  to the HTML Viewer control which reads the text and displays it.  This text
  includes links which make up the user selectable options of the Main Menu.

PARAMETERS:
	pApp [in] - Pointer to the CNetDiagnosticsApp structure. This structure contains 
    information specific to this applet. 

DEPENDENCIES:
  Assumes the displayed controls have been previously created and 
  initialized.

RETURN VALUE:
  None

SIDE EFFECTS:
  Causes the phone display to be updated.
===========================================================================*/
static void ND_DisplayMenu(CNetDiagnosticsApp* pApp, const char *pszURL)
{
   IFile *pf;
   const char *pszFileName = pszURL;

   if (STRBEGINS("file:", pszFileName))
      pszFileName += STRLEN("file:");

   if (STRBEGINS("///", pszFileName))
      pszFileName += STRLEN("///");

   pf = IFILEMGR_OpenFile(pApp->m_pFileMgr, pszFileName, _OFM_READ);

   if (pf) {

      // Set the file from which the viewer will get its text
      IHTMLVIEWER_LoadStream( pApp->m_pHTMLViewer, (IAStream*)pf);

      // Release our reference to the file.  (The HTML viewer is responsible for
      // its own reference count while it uses the stream.)
      IFILE_Release(pf);

   } else {
      
      // Set the file from which the viewer will get its text
      IHTMLVIEWER_SetData( pApp->m_pHTMLViewer, "<h1>Error</h1>File Not Found", -1);

   }
}


/*===========================================================================

FUNCTION: ND_EchoCleanup

DESCRIPTION:
	Cleanup when exiting Network Access test state

PARAMETERS:
	pApp [in] - Pointer to the CNetDiagnosticsApp structure. This structure contains 
    information specific to this applet. 

DEPENDENCIES:

RETURN VALUE:
  None

SIDE EFFECTS:
  Causes the phone display to be updated.
===========================================================================*/
static void ND_EchoCleanup(CNetDiagnosticsApp *pApp)
{
   // Note: Socket is being deleted; otherwise we would cancel socket
   // callbacks.

   // Cancel DNS Callback
   CALLBACK_Cancel(&pApp->m_cb);

   // Release Socket
   ReleaseObj((void**)&pApp->m_pISocket);

   // Release Static Control
   ReleaseObj((void**)&pApp->m_pIStatic);
}


/*===========================================================================

FUNCTION: ND_HTTPCleanup

DESCRIPTION:
	Cleanup when exiting the HTTP test state.

PARAMETERS:
	pApp [in] - Pointer to the CNetDiagnosticsApp structure. This structure contains 
    information specific to this applet. 

DEPENDENCIES:
  Assumes the displayed controls have been previously created and 
  initialized.

RETURN VALUE:
  None

SIDE EFFECTS:
  Causes the phone display to be updated.
===========================================================================*/
static void ND_HTTPCleanup(CNetDiagnosticsApp* pApp)
{
   FOR_ALL_WEBACTIONS(pApp, p, WebAction_Stop(p));

   // Release Static Control
   ReleaseObj((void**)&pApp->m_pIStatic);
}


/*===========================================================================

FUNCTION: ND_StartTest

DESCRIPTION:
	Read results submitted from a form, and begin a test.

PARAMETERS:
	pApp [in] - Pointer to the CNetDiagnosticsApp structure. This structure contains 
              information specific to this applet.

   pszSubmit [in] - URL naming the test and including submitted form data.

              "test:echo?..." begins an echo test
              "test:http?..." begins an HTTP test

DEPENDENCIES:
  Assumes the displayed controls have been previously created and 
  initialized.

RETURN VALUE:
  None

SIDE EFFECTS:
  Causes the phone display to be updated.
===========================================================================*/
static void ND_StartTest(CNetDiagnosticsApp* pApp, const char* pszSubmit)
{
   AEERect rc;
   IStatic * pStatic = NULL;
   char *pszIter;

   // Reset values before reading form results

   pApp->m_bRS = pApp->m_bRT = pApp->m_bTCP = FALSE;
   pApp->m_pszHost = "";
   pApp->m_pszURL = "";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -