Example #1
0
/**
 * This is the main entry point of a native application that is using
 * android_native_app_glue.  It runs in its own thread, with its own
 * event loop for receiving input events and doing other things.
 */
void
android_main( struct android_app* state )
{
    // Make sure glue isn't stripped.
    app_dummy();

    char packageDir[ 512 ];
    GetPackageDir( state, packageDir, 512 );

    // Check if we need to perform first time initialization
    int firstRun = IsFirstRun( packageDir );
    if ( 0 == firstRun )
    {
        LOGI( "Performing first run initialization" );

        // Extract to our private storage as desired
        if ( 0 == ExtractAssets( state, packageDir ) )
        {
            return;
        }

        LOGI( "Completed first run initialization" );
    }
    else
    {
        LOGI( "Detected previous run, skipping first run initialization" );
    }

    // Create the platform specific params
    char** platformArgv = NULLPTR;
    int platformArgc = 0;
    CreatePlatformParams( &platformArgv, &platformArgc, state );

    // Start the process of invoking the launch of the platform using the loader
    int appStatus = InvokeLoadAndRunGucefPlatformApp( "gucefPRODMAN", packageDir, platformArgc, platformArgv, 0, NULLPTR );

    // clean up our platform param data
    FreeStringMatrix( platformArgv, platformArgc );

    // Check if we had a successfull run
    if ( 0 != firstRun )
    {
        if ( 0 == appStatus )
        {
            LOGI( "Successfull completed first run, setting first run flag to false" );

            // Set the flag that we completed the first run
            SetFirstRunCompleted( packageDir );
        }
        else
        {
            // If the flag is already set, unset it
            UnSetFirstRunCompleted( packageDir );
        }
    }
    FLOGI( "exit status code: %i", appStatus );

}
Example #2
0
/**
* @brief 首次运行检查
* @param 无
* @return
* @li APP_SUCC
*/
static int FirstRunChk(void)
{
	if (APP_SUCC != IsFirstRun())
	{
		ResetDefaultParam();
	}
	else   //版本升级,新增变量初始化
	{
		VerUpdateChk();
	}
	return APP_SUCC;
}
Example #3
0
/**********************************************
* CpuUsage::GetUsage
* returns the percent of the CPU that this process
* has used since the last time the method was called.
* If there is not enough information, -1 is returned.
* If the method is recalled to quickly, the previous value
* is returned.
***********************************************/
double CpuUsage::GetUsage()
{
	//create a local copy to protect against race conditions in setting the 
	//member variable
	double nCpuCopy = m_nCpuUsage;
	if (::InterlockedIncrement(&m_lRunCount) == 1)
	{
		/*
		If this is called too often, the measurement itself will greatly affect the
		results.
		*/

		if (!EnoughTimePassed())
		{
			::InterlockedDecrement(&m_lRunCount);
			return nCpuCopy;
		}

		FILETIME ftSysIdle, ftSysKernel, ftSysUser;
		FILETIME ftProcCreation, ftProcExit, ftProcKernel, ftProcUser;

		if (!GetSystemTimes(&ftSysIdle, &ftSysKernel, &ftSysUser) ||
			!GetProcessTimes(GetCurrentProcess(), &ftProcCreation, &ftProcExit, &ftProcKernel, &ftProcUser))
		{
			::InterlockedDecrement(&m_lRunCount);
			return nCpuCopy;
		}

		if (!IsFirstRun())
		{
			/*
			CPU usage is calculated by getting the total amount of time the system has operated
			since the last measurement (made up of kernel + user) and the total
			amount of time the process has run (kernel + user).
			*/
			ULONGLONG ftSysKernelDiff = SubtractTimes(ftSysKernel, m_ftPrevSysKernel);
			ULONGLONG ftSysUserDiff = SubtractTimes(ftSysUser, m_ftPrevSysUser);

			ULONGLONG ftProcKernelDiff = SubtractTimes(ftProcKernel, m_ftPrevProcKernel);
			ULONGLONG ftProcUserDiff = SubtractTimes(ftProcUser, m_ftPrevProcUser);

			ULONGLONG nTotalSys =  ftSysKernelDiff + ftSysUserDiff;
			ULONGLONG nTotalProc = ftProcKernelDiff + ftProcUserDiff;

			if (nTotalSys > 0)
			{
				//m_nCpuUsage = (short)((100.0 * nTotalProc) / nTotalSys);
                m_nCpuUsage = (100.0 * nTotalProc) / nTotalSys;
			}
		}
		
		m_ftPrevSysKernel = ftSysKernel;
		m_ftPrevSysUser = ftSysUser;
		m_ftPrevProcKernel = ftProcKernel;
		m_ftPrevProcUser = ftProcUser;
		
		//m_dwLastRun = GetTickCount64();
        DWORD dwLastRun = GetTickCount();
        m_dwLastRun = (ULONGLONG)dwLastRun;

		nCpuCopy = m_nCpuUsage;
	}
	
	::InterlockedDecrement(&m_lRunCount);

	return nCpuCopy;
}