Beispiel #1
0
    public AsyncNet(string url, int method, string updateTime,
                    int cb_addr, int context)
    {
        this.url        = url;
        this.method     = method;
        this.updateTime = updateTime;
        this.cb_addr    = cb_addr;
        this.context    = context;

        try
        {
            if (c_do_async_connect_cb == 0)
            {
                c_do_async_connect_cb = CibylCallTable.getAddressByName("do_async_connect_cb");
                c_input_ready_cb      = CibylCallTable.getAddressByName("roadmap_main_input_ready");
            }
        }
        catch (Exception e)
        {
            Logger.log("Exception in do_async_connect_cb: " + e.ToString());

            throw; //todomt
            //Environment.Exit(0);
        }

        if (queue == null)
        {
            // assumes that this is called async
            queue = new NetQueue();
            queue.init();
        }

        queue.add(this);
    }
Beispiel #2
0
    public void run()
    {
        try
        {
            //Workaround an unfortunate Cibyl reliance on a Canvas object in the implementation
            //of reading from resources under fopen
            Logger.log("In start!!!!!!!!!!");
            Syscalls.dummyCanvasHandle = CRunTime.registerObject(new DummyCanvas());

            int c_start = CibylCallTable.getAddressByName("rim_start");
            Logger.log("rim_start: " + c_start);
            //lock (this)
            //{
            CibylCallTable.fcall(c_start, c_sp, 0, 0, 0, 0);
            //}
        }
        catch (Exception t)
        {
            Logger.log("Exception in start: " + t.ToString());
            MessageBox.Show("exception during run " + t);

            /*   Logger.log("Exception in start: " + t);
             * t.printStackTrace();
             * String res = "EXCEPTION in UiWorker startup, message :" + t.getMessage();
             * addUIEventLog(res);*/
            throw;     //todomt
            //Environment.Exit(0);

            //   System.exit(0);
        }

        runEventQueue(true);
    }
Beispiel #3
0
        public static void updateSoundLevel(int offset)
        {
            sound_level += offset;
            if (sound_level > 100)
            {
                sound_level = 100;
            }
            else if (sound_level < 0)
            {
                sound_level = 0;
            }

            try
            {
                if (c_set_sound_level == 0)
                {
                    c_set_sound_level = CibylCallTable.getAddressByName("roadmap_main_set_sound_level");
                }

                UIWorker.addUIEvent(c_set_sound_level, sound_level, 0, 0, 0, false);
            }
            catch (Exception e)
            {
                UIWorker.addUIEventLog("Error in SoundMgr setVolume" + e);
                Logger.log("Exception: " + e.ToString());
            }
        }
Beispiel #4
0
    private static void term()     //throws Exception
    {
        int c_destructors = CibylCallTable.getAddressByName("crt0_run_global_destructors");
        int c_sp          = (CRunTime.memory.Length * 4) - 8;

        CibylCallTable.fcall(c_destructors, c_sp, 0, 0, 0, 0);
    }
Beispiel #5
0
    static void TimerCallback(object ctx)
    {
        TimerCtx _ctx = (TimerCtx)ctx;

        try
        {
            if (c_on_invokeLater == 0)
            {
                c_on_invokeLater = CibylCallTable.getAddressByName("rim_on_scheduledTask");
            }
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine("Exception in run (rim_on_scheduledTask): " + ex.ToString());
            Logger.log(ex.ToString());

            throw; //todomt
            //Environment.Exit(0);
        }

        if (c_on_invokeLater != 0)
        {
            UIWorker.addUIEvent(c_on_invokeLater, _ctx.index, 0, 0, 0, _ctx.interval < 100 ? true : false);
        }
    }
Beispiel #6
0
    public void CallCallback()
    {
        int c_on_menuItem = CibylCallTable.getAddressByName("rim_on_menuItem");

        if (c_on_menuItem != 0)
        {
            UIWorker.addUIEvent(c_on_menuItem, wrapper_callback, callback, 0, 0, true);
        }
    }
Beispiel #7
0
 public static void registerMsgAddr(int addr, int size)
 {
     msgAddr     = addr;
     msgAddrSize = size - 1;     // -1 to allow the terminating null byte.
     try
     {
         c_write_to_log = CibylCallTable.getAddressByName("roadmap_main_write_exception_to_log");
     }
     catch (Exception)
     {
         Logger.log("Could not register roadmap_main_write_exception_to_log");
     }
 }
Beispiel #8
0
    /* Invoke a registered callback */
    public static long invokeCallback(int which, int a0, int a1, int a2, int a3)
    {
        int id = (int)CRunTime.objectRepository[which];

        /* If this callback is not yet registered, just return 0 */
        if (id == 0)
        {
            return(0);
        }

        return(CibylCallTable.fcall(id,
                                    CRunTime.eventStackPointer,
                                    a0, a1, a2, a3)); /* a0 ... a3 */
    }
Beispiel #9
0
 public int UIEventExecuteNow(int addr, int p1, int p2, int p3, int p4)
 {
     //lock (this)
     //{
     try
     {
         return(CibylCallTable.fcall(addr, c_sp, p1, p2, p3, p4));
     }
     catch (Exception e)
     {
         Logger.log("UIWORKER - UIEventExecuteNow, could not finish call to addr : " + addr + " got exception : " + e.ToString());
         return(0);
     }
     //}
 }
Beispiel #10
0
    private static void init()    // throws Exception
    {
        Logger.log("In init!!!!!!!!!!");
        //Class cls = Class.forName("CRunTime");
        Stream isData = Application.GetResourceStream(new Uri("/WazeWP7;component/resources/program.data.bin", UriKind.Relative)).Stream;

        Logger.log("program.data.bin:" + isData);
        CRunTime.init(isData);
        isData.Close();
        CRunTime.publishCallback("Cibyl.atexit");
        int c_start = CibylCallTable.getAddressByName("__start");

        Logger.log("Start: " + c_start);

        /*
         * This is the stack which will be used for all the C calls.
         */
        int c_sp = (CRunTime.memory.Length * 4) - 8;

        Logger.log("c_sp: " + c_sp);
        CibylCallTable.fcall(c_start, c_sp, 0, 0, 0, 0);

        /*
         * The blackberry menu button can be clicked on async when other waze tasks
         * are handled, and we want the response to be immediate. Thus we allocate a special
         * stack for the menu button clicks, to be used by the FreemapMainScreen object.
         */
        int c_malloc_stack = 0;

        try
        {
            c_malloc_stack = CibylCallTable.getAddressByName("roadmap_main_alloc_stack");
        }
        catch (Exception e)
        {
            Logger.log("could not call c_malloc_stack" + e.ToString());
            safe_exit();
            //MessageBox.Show("Exception in c_malloc_stack");
        }
        if (c_malloc_stack != 0)
        {
            int stackAddress = CibylCallTable.fcall(c_malloc_stack, c_sp, 4096, 0, 0, 0);
            GamePage.setStackAddress(stackAddress);
        }
    }
Beispiel #11
0
    /*
     *
     * Called when moving returning from background to foreground.
     *
     * Pressing end key sends to background. To avoid wasting battery when user is unaware,
     *
     * after SECONDS_IN_BACKGROUND_B4_DLG seconds, a confirm dialog willl pop up, telling the
     *
     * user that waze is in background, and advise him to exit. If he doesn't answer - ( since he isn't
     *
     * looking at phone), exit anyway.
     *
     */
    /*todomt
     * public void deactivate(){
     * UIWorker.addUIEventLog("INFO : User went to background");
     * locale_before_background = Locale.getDefaultInput();
     * FreemapMainScreen.revertToInitialLocale();
     * if ( isCharging(DeviceInfo.getBatteryStatus()) == 1 ){
     * Logger.log("Charging, so not adding the background check");
     * return; // if charging, no need to
     * }
     * Application app = Application.getApplication();
     * idTimerBackgroundDialog = app.invokeLater (
     *  new Thread()
     *  {
     *   public void run()
     *   {
     *    if(c_ticker_sound == 0){
     *     try {
     *      c_ticker_sound = CibylCallTable.getAddressByName("roadmap_sound_play_background_sound");
     *     } catch (Exception e) {
     *      UIWorker.addUIEventLog("Exception trying to get Cybil address for c_ticker_sound");
     *      FreemapApp.safe_exit();
     *     }
     *    }
     *    UIWorker.addUIEvent(c_ticker_sound, 0, 0, 0, 0, true);
     *    UiApplication.getApplication().requestForeground();
     *    UIWorker.addUIEventLog("INFO: Waited 10 minutes, asking user if he wants to keep waze open. ");
     *    if(idTimerBackgroundDialog!=0)
     *     UiApplication.getUiApplication().cancelInvokeLater(idTimerBackgroundDialog );
     * //todomt      stayInBackgroundDialog = new Dialog("Waze is still running in the background. To avoid excess battery consumption it will shut down in 30 seconds.",
     *      new string[]{"Exit waze", "Stay in background"},
     *      new int[]{Dialog.YES, Dialog.NO},
     *      Dialog.YES,
     *      new Bitmap(0,0));
     * //todomt      stayInBackgroundDialog.setDialogClosedListener(new DialogClosedListener(){
     *     public void dialogClosed(Dialog d,int dialogReturnValue){
     *      if (dialogReturnValue == Dialog.NO){
     *       UiApplication.getApplication().requestBackground();
     *      }
     *
     *      if (dialogReturnValue == Dialog.YES){
     *       UIWorker.addUIEventLog("INFO : User accepted advice to not run in background. Exit.");
     *       safe_exit();
     *      }
     *     }
     *    });
     *
     * //todomt      stayInBackgroundDialog.show();
     *    resInvokeLaterappBGExit = UiApplication.getUiApplication().invokeLater (
     *      new Runnable()
     *      {
     *       // will be called some time after user hasn't picked his choice in the dialog. exit!
     *       public void run()
     *       {
     *        if(resInvokeLaterappBGExit !=0){
     *         UiApplication.getUiApplication().cancelInvokeLater(resInvokeLaterappBGExit );
     *         resInvokeLaterappBGExit = 0;
     *        }
     */
    //todomt uncomment

    /*          if(stayInBackgroundDialog.isDisplayed()){
     *         UIWorker.addUIEventLog("INFO : Dialog confirm dialog open after waiting for answer, exitting");
     *         safe_exit();
     *        }*/
    /*todomt       }
     *    }, SECONDS_BACKGROUND_DIALOG*1000, false);
     *
     *  if(resInvokeLaterappBGExit == -1)
     *   UIWorker.addUIEventLog("NO MORE TIMERS - resInvokeLaterappBGExit = -1 ");
     * }
     *
     * }, SECONDS_IN_BACKGROUND_B4_DLG*1000, false); // ask user if he wants to exit app.
     *
     * if(idTimerBackgroundDialog == -1)
     * UIWorker.addUIEventLog("NO MORE TIMERS - idTimerBackgroundDialog = -1");
     *
     * }
     */
    /*
     *
     * Exit safely through roadmap_main, so user won't get error messages next time he quits.
     *
     */
    public static void safe_exit()
    {
        try
        {
            if (c_roadmap_main_exit == 0)
            {
                c_roadmap_main_exit = CibylCallTable.getAddressByName("roadmap_main_exit");
            }
            if (c_roadmap_main_exit != 0)
            {
                int c_sp = (CRunTime.memory.Length * 4) - 8;
                UIWorker.addUIEvent(c_roadmap_main_exit, 0, 0, 0, 0, true);
            }
        }
        catch (Exception t)
        {
            UIWorker.addUIEventLog("FreeMapMainScreen Safe Exit exception" + t.ToString());
            //   t.printStackTrace();
            throw;     //todomt
            //Environment.Exit(0);
        }
    }
Beispiel #12
0
    private void runEventQueue(bool forever)
    {
        Item o;

        while (!should_quit)
        {
            o = null;

            lock (lockQueues)
            {
                if (priorityQueue.Count > 0)
                {
                    o = priorityQueue.Dequeue() as Item;
                }
                else if (queue.Count > 0)
                {
                    o = queue.Dequeue() as Item;
                }
                else
                {
                    // Making sure no elements
                    // adds to the queues will querying the queues
                    if (forever)
                    {
                        try
                        {
                            isWaiting = true;

                            // Wait until another thread insert new elements to the queue
                            Monitor.Wait(lockQueues);
                            isWaiting = false;
                        }
                        catch (Exception e)
                        {
                            Logger.log("Exception: " + e.ToString());
                        }
                    }
                }

                //cur_item = o;
                if ((o != null) && o.user_draw)
                {
                    userDrawCount--;
                }
            }

            if (!forever && (o == null))
            {
                return;
            }

            if (o != null)
            {
                try
                {
                    if (o.logString != null)
                    {
                        byte[] str_bytes;
                        int    length;

                        str_bytes = Syscalls.StringToAscii(o.logString);
                        if (str_bytes.Length > msgAddrSize)
                        {
                            // do not overflow size of buffer in roadmap_main
                            length = msgAddrSize;
                        }
                        else
                        {
                            length = str_bytes.Length;
                        }

                        //lock (this)
                        //{
                        CRunTime.memcpy(msgAddr, str_bytes, 0, length);
                        CRunTime.memoryWriteByte(msgAddr + length, 0);
                        try
                        {
                            CibylCallTable.fcall(o.addr, c_sp, o.p1, o.p2, o.p3, o.p4);
                        }
                        catch (Exception e)
                        {
                            Logger.log("UIWORKER - print to log file :  Could not print out to log, message :" + o.logString + " Exception : " + e.ToString());
                        }
                        //}
                    }
                    else if ((o.validity_check == null) || (o.validity_check.isValid()))
                    {
                        //lock (this)
                        //{
                        //long start = DateTime.Now.Ticks;// System.currentTimeMillis();
                        //Logger.log("calling addres "+ Integer.toHexString(o.addr));
                        CibylCallTable.fcall(o.addr, c_sp, o.p1, o.p2, o.p3, o.p4);

                        /* todomt
                         * long end = DateTime.Now.Ticks;// System.currentTimeMillis();
                         * if ((end - start) > 750)
                         * {
                         *  if ((end - start) > 3000)
                         *  {
                         *      Logger.log("UIWorker Callback took too long!!! " + (end - start) + " UIWorker Callback addr:" + o.addr);
                         *      addUIEventLog("UIWorker Callback took too long!!! " + (end - start) + " UIWorker Callback addr:" + o.addr);
                         *  }
                         *  else
                         *  {
                         *      Logger.log("UIWorker Callback took too long!!! " + (end - start));
                         *      Logger.log("UIWorker Callback addr:" + o.addr);
                         *  }
                         * }
                         */

                        //}
                    }
                }
                catch (Exception t)
                {
                    //Console.WriteLine("Exception in UI action: " + t);
                    //t.printStackTrace();
                    String res = "EXCEPTION in UiWorker, cb addr: " + o.addr +
                                 ", toString() : " + t.ToString();
                    Logger.log(res);
                    addUIEventLog(res);
                }
            }
        }
    }