Пример #1
0
/***********************************************************************
 * main function
 ***********************************************************************/
UInt32
PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
{
  UInt16 error = RomVersionCompatible (MINVERSION, launchFlags);
  if (error) return (error);

  /***
  * NORMAL STARTUP
  ****/
  if ( cmd == sysAppLaunchCmdNormalLaunch ) {
    error = StartApplication ();
    if (error) {
      // PalmOS before 3.5 will continuously relaunch this app unless we switch to
      // another safe one.
      if (error != dmErrCorruptDatabase) {
        FrmCustomAlert(ALERT_debug, "Please reports this bug! Give your Palm device and PalmOS version, this BadBug(TM) should not happen.", "", "");
      }
      StopApplication();
      AppLaunchWithCommand(sysFileCDefaultApp, sysAppLaunchCmdNormalLaunch, NULL);
      return error;
    }

    FrmGotoForm(FORM_main);

    AppEventLoop ();
    StopApplication ();

    /***
     * FIND
     ****/
    /*
      } else if (cmd == sysAppLaunchCmdSaveData) {
      FrmSaveAllForms();
      } else if (cmd == sysAppLaunchCmdFind) {
      PalmGlobalFind((FindParamsPtr)cmdPBP);
    */

    /***
     * GoTo
     ****/
    /*
      } else if (cmd == sysAppLaunchCmdGoTo) {
      Boolean launched = launchFlags & sysAppLaunchFlagNewGlobals;
	
      if (launched) {
      error = StartApplication();
      if (! error) {
      GoToItem((GoToParamsPtr)cmdPBP, launched);
      AppEventLoop();
      StopApplication();
      }
      } else {
      GoToItem((GoToParamsPtr)cmdPBP, launched);
      }
    */

    /***
     * BEAMING
     ****/
  } else if (cmd == sysAppLaunchCmdSyncNotify) {
    // Register with the Exchange Manager
    ExgRegisterData(APP_CREATOR, exgRegExtensionID, "umx");
  } else if (cmd == sysAppLaunchCmdExgAskUser) {
    // Always assume "Yes" as answer to the accept dialog since we display our
    // own on which the user can cancel the data
    ExgAskParamType *exgAskParam = (ExgAskParamType *)cmdPBP;
    exgAskParam->result=exgAskOk;
  } else if (cmd == sysAppLaunchCmdExgReceiveData) {
    DmOpenRef cats=NULL, dogs=NULL;
    // Is app active?
    if (launchFlags & sysAppLaunchFlagSubCall) {
      // Quit Forms
      FrmSaveAllForms();

      cats = DatabaseGetRefN(DB_MAIN);
      dogs = DatabaseGetRefN(DB_DATA);
      error = BeamReceive(cats, dogs, (ExgSocketPtr) cmdPBP);
      CacheReset();
      FrmGotoForm(FORM_main);

    } else {
      // Another app was running when we were called
      cats = DmOpenDatabaseByTypeCreator(DATABASE_TYPE, APP_CREATOR, dmModeReadWrite);
      dogs = DmOpenDatabaseByTypeCreator(DATABASE_DATA_TYPE, APP_CREATOR, dmModeReadWrite);
      if (! (cats && dogs)) {
        FrmAlert(ALERT_beamdbfail);
      } else {
        error=BeamReceive(cats, dogs, (ExgSocketPtr)cmdPBP);
      }
      if (cats)  DmCloseDatabase(cats);
      if (dogs)  DmCloseDatabase(dogs);
    }

    /***
     * ALARM
     ****/
  } else if (cmd == sysAppLaunchCmdAlarmTriggered) {
    // Is app active?
    if (launchFlags & sysAppLaunchFlagSubCall) {
      AlarmTriggered(DatabaseGetRefN(DB_MAIN), (SysAlarmTriggeredParamType *)cmdPBP);
    } else {
      DmOpenRef cats = DmOpenDatabaseByTypeCreator(DATABASE_TYPE, APP_CREATOR, dmModeReadWrite);
      AlarmTriggered(cats, (SysAlarmTriggeredParamType *)cmdPBP);
      DmCloseDatabase(cats);
    }

    /***
     * ATTENTION
     ****/
  } else if (cmd == sysAppLaunchCmdAttention) {
    // Is app active?
    if (launchFlags & sysAppLaunchFlagSubCall) {
      AttentionBottleNeckProc(DatabaseGetRefN(DB_MAIN), (AttnLaunchCodeArgsType *)cmdPBP);
    } else {
      // Another app was running when we were called
      DmOpenRef cats = DmOpenDatabaseByTypeCreator(DATABASE_TYPE, APP_CREATOR, dmModeReadWrite);
      AttentionBottleNeckProc(cats, (AttnLaunchCodeArgsType *)cmdPBP);
      DmCloseDatabase(cats);
    }

    /***
     * ATTENTION GOTO
     ****/
  } else if (cmd == appLaunchCmdAlarmEventGoto) {
    error = StartApplication ();
    if (error) {
      // PalmOS before 3.5 will continuously relaunch this app unless we switch to
      // another safe one.
      if (error != dmErrCorruptDatabase) {
        FrmCustomAlert(ALERT_debug, "Please reports this bug! Give your Palm device and PalmOS version, this BadBug(TM) should not happen.", "", "");
      }
      StopApplication();
      AppLaunchWithCommand(sysFileCDefaultApp, sysAppLaunchCmdNormalLaunch, NULL);
      return error;
    }

    ExamSetGoto(*(UInt32 *)cmdPBP);
    FrmGotoForm(FORM_exams);

    AppEventLoop ();
    StopApplication ();


  /***
  * TIME CHANGE
  ****/
  // Launch code sent when the system time is changed.
  } else if (cmd == sysAppLaunchCmdTimeChange) {
    // reset the trigger for the next alarm to fire
    if (launchFlags & sysAppLaunchFlagSubCall) {
      AlarmReset(DatabaseGetRefN(DB_MAIN));
      // Remove any "future" alarms from the attention manager queue
      // (ie alarms that will trigger after the new time setting)
      //AlarmUpdatePosted(DeviceTimeChanged);
    } else {
      // Another app was running when we were called
      DmOpenRef cats = DmOpenDatabaseByTypeCreator(DATABASE_TYPE, APP_CREATOR, dmModeReadWrite);
      if (cats != 0) {
        AlarmReset(cats);
        //AlarmUpdatePosted(DeviceTimeChanged);
        DmCloseDatabase(cats);
      }
    }
    
  
  /***
  * RESET
  ****/
  // This action code is sent after the system is reset.
  } else if (cmd == sysAppLaunchCmdSystemReset) {
    if (! ((SysAppLaunchCmdSystemResetType*)cmdPBP)->hardReset) {
      if (launchFlags & sysAppLaunchFlagSubCall) {
        AlarmReset(DatabaseGetRefN(DB_MAIN));
      } else {
        // Another app was running when we were called
        DmOpenRef cats = DmOpenDatabaseByTypeCreator(DATABASE_TYPE, APP_CREATOR, dmModeReadWrite);
        if (cats != 0) {
          AlarmReset(cats);
          DmCloseDatabase(cats);
        }
      }
    }

  }

  return 0;
}
Пример #2
0
/*----------------------------------------------------CIRexxApp::InitInstance-+
| Called when application is invoked                                          |
+----------------------------------------------------------------------------*/
Err CIRexxApp::InitInstance()
{
   // true instance vars
   //none

   // really global vars
   // if we didn't get a new global segment for this instance,
   // then don't re-initialize the existing ones!
   if (m_wLaunchFlags & sysAppLaunchFlagNewGlobals) {
      m_rexx = 0;
      m_memoDB = 0;
      m_pedit32DB = 0;
      m_rexxDB = 0;
      m_scriptIndexDB = 0;
      m_memoCategory = dmRecNumCategories;
      m_pedit32Category = dmRecNumCategories;
      m_rexxCategory = dmRecNumCategories;
      m_script = 0;
      m_args = 0;
      m_isScriptDirty = false;
      m_scriptInsertPosition = m_scriptSrcollPosition =
      m_scriptSelect1Position = m_scriptSelect2Position = 0;
      m_fromForm = EditForm;
      m_loadRow = 0;
      m_isRexxRunning = false;
      m_isScriptIndexDBInitialized = false;
      g_pBeamerStreamBuf = 0;
   }

   // If Rexx is running, then this implies that we were launched
   // without a new set of globals and with sysAppLaunchFlagSubCall.
   // So, there are certain things we're not going to be able to do,
   // like a GoTo command because we cannot re-enter Rexx
   // while it's running unless we kill the running Rexx.
   // I'm not sure exactly why we cannot re-enter it,
   // but I do know it doesn't work and can look into
   // this later--I think it's a console issue.
   if (m_isRexxRunning) {  // handled below for individual commands
                           // but left here just for comments
   }

   // NOTE:  LOOK OUT BELOW...do not do anything that will cause a
   //        cross-segment call in non-global launches.  Hopefully,
   //        CW9 will allow cross-segment calls under non-normal launches.
   //        It's kind of a ridiculuous issue.  I.e., CW will allow you
   //        to set up globals (a5) for expanded mode, but there doesn't
   //        seem to be a way to initialize what else the app needs,
   //        e.g., the cross-segment jump table.

   UInt32 romVersion;
   switch(m_wCommand) {

   case sysAppLaunchCmdNormalLaunch:   // irexx ide
// enable this for easier testing of notify/rexxets on palm os 5
// the reason this is easier is that the way to cause this to
// happen on os 5 is to reset the device, which is a pain
// when testing (see call to RegisterForNotifications below)
// STATUS:  NOT YET WORKING.  NEED TO SEE PALM OS 5 STARTUP CODE
// TO SEE WHY REXX CANNOT FIND IT'S RESOURCES WHEN SELF-LAUNCHED
// UNDER THE NOTIFICATION HANDLER.  PERHAPS, CW_SETUP IS
// NOT DOING THE RIGHT THING SINCE IT'S A SUBCALL?
// LAUNCH CODES INFO I DISCOVERED FOR FUTURE REF:
//
// 32 when stroke is made (32 is undocumented)
//    32 = 0x20 = UNDOCUMENTED
// 166 when self-launched
//    166 = a6
//    x6 = 0x04|0x02 = sysAppLaunchFlagNewStack|sysAppLaunchFlagNewGlobals
//    Ax = 0x80|0x20 = sysAppLaunchFlagDataRelocated|UNDOCUMENTED
//
// SO, STILL USING SEPARATE NOHACK VERSON OF REXXLET LAUNCHER.
//RegisterForNotifications(); 
      return CPalmStApp<CIRexxApp>::InitInstance();

   case rexxAppNoop:                   // noop
      return errNone;
   case rexxAppLaunchRexxlet:          // rexxlet (sublaunch)
      return RexxletLaunch();
   case rexxAppLaunchRexxapp:          // rexxapp (uiappswitch)
      return RexxappLaunch();

   case sysAppLaunchCmdFind:
      return FindLaunch((FindParamsPtr)m_pCommandPBP);

   case sysAppLaunchCmdGoTo:
      // We cannot yet use Find when a rexxlet is running,
      // so considering that here is moot for now,
      // but if we could then we should not allow it.
      //<<<JAL Does this handle a waiting-on-return rexxlet console?
      if (m_isRexxRunning) {
         FrmCustomAlert(ErrorAlert, getRexxAppMessage(msgRexxIsRunning), 0, 0);
         return errNone;
      }
      // If we have new globals, then we weren't running (!sysAppLaunchFlagSubCall),
      // so start up as if in a normal launch and automatically run the script.
      // I know it's not obvious, but InitInstance will handle this
      // launch code as well and end up invoking GotoLaunch().
      // I could have placed GotoLaunch() here directly,
      // but might as well stick with POL.
      if (m_wLaunchFlags & sysAppLaunchFlagNewGlobals) {
         return CPalmStApp<CIRexxApp>::InitInstance();
      }
      // Finally, if we were running (sysAppLaunchFlagSubCall),
      // and the Rexx interpreter wasn't (!m_isRexxRunning),
      // then just load the script the user wanted and BALR.
      copyScriptFromFindResult((GoToParamsPtr)m_pCommandPBP);
      BALR(EditForm, ConsoleForm);
      return errNone;

   // The following is for Palm OS 5, and is not working correctly.
   //
   // http://www.palmos.com/dev/support/docs/recipes/notifications.html
   /*
   Be very careful when registering for notifications on system resets.
   If you have a bug in how you handle resets (like accessing global variables),
   you may crash the Palm OS and force another reset, creating an infinite loop.
   Many users won't know to do a no-notify reset so that they can delete your application.

   There is a special 'no-notify' reset (also referred to as a warm reset)
   which you invoke by holding the UP button on the device and poking the
   reset (i.e. it's like doing a hard reset except that you hold the UP
   button instead of the power button).

   This type of reset will NOT send the reset message out to loaded
   applications and it will NOT cause the loss of any data. At that point,
   you can do a HotSync to make sure that all your current data is saved
   before you proceed.

   When it comes back up, start removing applications--in an attempt to
   find the culprit (i.e. remove say two applications, do a soft reset and
   see if loops out again--if so, do another no-notify reset and try
   removing more apps till you find it surviving a soft reset).
   */
   case sysAppLaunchCmdSystemReset:
   case sysAppLaunchCmdSyncNotify: // sent when our app is installed
      FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
      if (romVersion >= sysMakeROMVersion(5, 0, 0, sysROMStageRelease, 0)) {
//         RegisterForNotifications();
      }
      //<<<JAL TODO: why do we register now?
      // don't we only want to register if rexx is running?
      // we cannot receive data if rexx isn't.
      //Cannot make cross-segment calls and possibly calls that require globals
      //during non-normal launch codes.
      //BeamerStreamBuf::registerData();
      //we know we're at least palm os 3.0, so no need to check again
      ExgRegisterData(CREATORID, exgRegExtensionID, "REX");
      break;
      
   case sysAppLaunchCmdNotify:
      FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
      if (romVersion >= sysMakeROMVersion(5, 0, 0, sysROMStageRelease, 0)) {
         HandleNotification((SysNotifyParamType *)m_pCommandPBP);
      }
      break;
      
   // Exchange Manager
   case sysAppLaunchCmdExgAskUser:
      ((ExgAskParamPtr)m_pCommandPBP)->result = 
         (g_pBeamerStreamBuf && g_pBeamerStreamBuf->isReceiving())? exgAskOk : exgAskCancel;
      break;
   case sysAppLaunchCmdExgReceiveData:
      if (g_pBeamerStreamBuf && g_pBeamerStreamBuf->isReceiving()) {
         return g_pBeamerStreamBuf->receiveData((ExgSocketPtr)m_pCommandPBP);
      }
      break;

   default:
      return errNone;
   }
   return errNone;
}
Пример #3
0
/***********************************************************************
 *
 * FUNCTION:     RegisterExtensions
 *
 * DESCRIPTION:  This routine registers the database types that can be received.
 *
 * PARAMETERS:   None.
 *
 * RETURNED:     Nothing.
 *
 ***********************************************************************/
void RegisterExtensions(void)
{
	ExgRegisterData(CCBCreator, exgRegExtensionID, "ccb");
}