Пример #1
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);
        }
    }
Пример #2
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());
            }
        }
Пример #3
0
        /// <summary>
        /// Update waze with new GPS coordinates
        /// </summary>
        /// <param name="position"></param>
        private void UpdatePosition(GeoPosition <GeoCoordinate> position)
        {
            try
            {
                UIWorker.addUIEvent(c_pos1,
                                    (int)(position.Location.Latitude * 1000000),
                                    (int)(position.Location.Longitude * 1000000),
                                    0,
                                    0, false);


                DateTime Now = DateTime.Now.ToUniversalTime();
                long     currentTimeMillis = (Now - baseTime).Ticks / 10000;

                UIWorker.addUIEvent(c_pos2,
                                    'A',
                                                                        //(int)(position.Timestamp.Ticks / 1000),
                                                                        //(int)DateTime.Now.Ticks / 10000 / 1000,
                                    (int)currentTimeMillis / 1000,
                                    (int)(position.Location.Speed * 2), // Convert to ~knots
                                    (int)position.Location.Course, false);

                if (meOnMapMenuItem != null)
                {
                    //meOnMapMenuItem.CallCallback();
                }
            }
            catch (Exception ex)
            {
                Logger.log("Exception in do_async_connect_cb: " + ex.ToString());
            }
        }
Пример #4
0
    /**
     *
     * This method provides the functionality of actually parsing
     *
     * through the service books on the handheld and determining
     *
     * which traffic routes are available based on that information.
     *
     * Before 4.2.0, this method is necessary to determine coverage.
     *
     */
    /*todomt
     * private static void parseServiceBooks()
     * {
     * // Add in our new items by scrolling through the ServiceBook API.
     * ServiceBook sb = ServiceBook.getSB();
     * ServiceRecord[] records = sb.findRecordsByCid( IPPP ); // The IPPP service represents the data channel for MDS and BIS-B
     * if( records == null ) {
     * return;
     * }
     * int numRecords = records.length;
     * for( int i = 0; i < numRecords; i++ ) {
     * ServiceRecord myRecord = records[i];
     * string name = myRecord.getName(); // Technically, not needed but nice for debugging.
     * string uid = myRecord.getUid(); // Technically, not needed but nice for debugging.
     * // First of all, the CID itself should be equal to IPPP if this is going to be an IPPP service book.
     * if( myRecord.isValid() && !myRecord.isDisabled() ) {
     *  // Now we need to determine if the service book is Desktop or BIS.  One could check against the
     *  // name but that is unreliable.  The best mechanism is to leverage the security of the service
     *  // book to determine the security of the channel.
     *  int encryptionMode = myRecord.getEncryptionMode();
     *  if( encryptionMode == ServiceRecord.ENCRYPT_RIM ) {
     *   _mdsSupport = true;
     *  } else {
     *   _bisSupport = true;
     *  }
     * }
     * }
     * if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
     * _wifiAvailable = true;
     * Logger.log("WIFI initially connected");
     * }
     * else {
     * Logger.log("WIFI initially not connected state= "+Integer.toString(WLANInfo.getWLANState()));
     * }
     * }
     */

    /**
     *
     * Returns the Connection object specified by the name (e.g. HttpConnection) using the
     *
     * appropriate transport mechanism (MDS, BIS-B, TCP) depending on what service books
     *
     * are currently supported on the handheld and using a priority scale in the following order:
     *
     * <code>
     *
     *      MDS
     *
     *      BIS-B
     *
     *      WAP - To be supported in the future
     *
     *      HTTP over Direct TCP
     *
     * </code>
     *
     * This method does NOT check for the name to ensure that HTTP is being requested and as such
     *
     * it may not work if you request a socket connection over the BIS-B transport protocol.
     *
     */
    public static string getConnectionSuffix(bool print)
    {
        string ConnectionSuffix = null;

        if (WIFI_ENABLED && _wifiAvailable)
        {
            ConnectionSuffix = ";interface=wifi";
        }
        else if (_bisSupport)
        {
            ConnectionSuffix = ";deviceside=false;ConnectionType=mds-public";
        }
        else if (_mdsSupport)
        {
            ConnectionSuffix = ";deviceside=false";
        }
        else if (_wapSupport)
        {
            ConnectionSuffix = "";
        }
        else
        {
            // HTTP over Direct TCP
            ConnectionSuffix = ";deviceside=true";
        }
        if (print)
        {
            UIWorker.addUIEventLog("Connection Suffix length is " + ConnectionSuffix.Length + " , " + _wifiAvailable + " , " + _bisSupport + " , " + _mdsSupport + " , " + _wapSupport);
        }
        return(ConnectionSuffix);
    }
Пример #5
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);
        }
    }
Пример #6
0
        private void playNextList()
        {
            lock (sound_lists)
            {
                current_list_id = (current_list_id + 1) % MAX_LISTS;

                if (sound_lists[current_list_id] == null)
                {
                    /* nothing to play */
                    current_list_id = -1;
                }
            }
            if (current_list_id == -1)
            {
                return;
            }

            current_list_item = 0;
            current_list      = (SoundList)CRunTime.getRegisteredObject(sound_lists[current_list_id].Value);
            if ((current_list.streams == null) || (current_list.streams.Length != current_list.count))
            {
                current_list.streams = new Stream[current_list.count];
            }
            for (int i = 0; i < current_list.count; i++)
            {
                try
                {
                    if (_soundDir.Equals(""))
                    {
                        current_list.streams[i] = App.GetResourceStream(new Uri(current_list.list[i], UriKind.Relative)).Stream;
                    }
                    else
                    { // This is a downloaded
                        lock (sound_lists)
                        {
                            if (Syscalls.FileExists(_soundDir + "/" + current_list.list[i]))
                            {
                                current_list.streams[i] = Syscalls.GetFileStream(_soundDir + "/" + current_list.list[i], FileMode.Open);
                            }
                            else
                            {
                                Logger.log("Could not find sound file : " + _soundDir + "/" + current_list.list[i]);
                                UIWorker.addUIEventLog("Could not find sound file : " + _soundDir + "/" + current_list.list[i]);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.log("Error creating sound stream:" + current_list.list[i] + "excp :  " + e);
                    UIWorker.addUIEventLog("Error creating sound stream:" + current_list.list[i] + "excp :  " + e);
                }
            }

            playNextItem();
        }
Пример #7
0
 public static void printOSVersionToLog()
 {
     try
     {
         UIWorker.addUIEventLog(" OS version is : " + Environment.OSVersion);
         //              CodeModuleManager.getModuleVersion(CodeModuleManager.getModuleHandleForObject("")));
     }
     catch (Exception e)
     {
         UIWorker.addUIEventLog("Exception in printOSVersionToLog" + e.ToString());
     }
 }
Пример #8
0
    /*
     *
     * Called when moving returning from background to foreground
     *
     */
    public void activate()
    {
        UIWorker.addUIEventLog("INFO: User returned to foreground");
        //todomt uncomment

        /*  if(locale_before_background != null){
         * Locale.setDefaultInput(locale_before_background);
         * }*/
        if (idTimerBackgroundDialog != 0)
        {     // Background timer open - Cancel it.
            //todomt   UiApplication.getUiApplication().cancelInvokeLater ( idTimerBackgroundDialog );
            idTimerBackgroundDialog = 0;
        }
    }
Пример #9
0
 void gps_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
 {
     gpsStatus = e.Status;
     if (gpsStatus == GeoPositionStatus.Disabled || gpsStatus == GeoPositionStatus.NoData)
     {
         try
         {
             UIWorker.addUIEvent(c_pos2, 'V', 0, 0, 0, false);
         }
         catch (Exception ex)
         {
             Logger.log("Exception in do_async_connect_cb: " + ex.ToString());
         }
     }
 }
Пример #10
0
    public static Timer schedule(int index, int interval, int repeat)
    {
        Timer timer;

        try
        {
            TimerCtx ctx = new TimerCtx(index, interval);
            timer = new Timer(TimerCallback, ctx, interval, interval);//Timeout.Infinite);
        }
        catch (Exception e)
        {
            UIWorker.addUIEventLog("Exception in scheduling task" + e.ToString());
            Logger.log("Exception in scheduling task " + e.ToString());
            return(null);
        }
        return(timer);
    }
Пример #11
0
    public void startRead(int input_id)
    {
        if (lock_object == null)
        {
            UIWorker.addUIEventLog("startRead with no connection!");
            Logger.log("startRead with no connection!");
            eof = true;
            Monitor.Pulse(lock_object);
        }

        this.input_id = input_id;
        lock (lock_object)
        {
            do_read = true;
            Monitor.Pulse(lock_object);
        }
    }
Пример #12
0
        private void ParseMembers()
        {
            settings.members = NetWorker.GetMembers(settings.vkgroupID, settings.token);

            members_Panel.Controls.Clear();
            panel2.Width        = 191;
            members_Panel.Width = 189;

            if (settings.members.Count > 7)
            {
                panel2.Width        = 208;
                members_Panel.Width = 206;
            }

            foreach (var item in settings.members)
            {
                members_Panel.Controls.Add(UIWorker.NewButton(item.Key, settings.members));
            }
        }
Пример #13
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);
        }
    }
Пример #14
0
 public static void init(bool run_in_thread)
 {
     uiWorker = new UIWorker(run_in_thread);
 }
Пример #15
0
    private static void messageBoxBuilder(string titleText, int titleSize,
                                          string msgText, int textSize, string buttonText,
                                          int callback, int numberOfSeconds, int isModal)
    {
        // if numberOfSeconds is non zero we should auto close, but MessageBox is always Modal and does not support closing from code.
        // we will need to implement a non modal message box calss for this scenario.

        MessageBoxResult res = MessageBoxResult.None;

        mre.Reset();
        System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            if (numberOfSeconds > 0)
            {
                Syscalls.rtlDialog.Show(titleText, msgText);

                // Auto hide on timeout.
                Thread threadAutoHide = new Thread(new ThreadStart(
                                                       delegate()
                {
                    Thread.Sleep(numberOfSeconds * 1000);

                    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        Syscalls.rtlDialog.Hide();
                        res = Syscalls.rtlDialog.Result;
                    });

                    // If we were asked to display an error, try to handle it gracefully by trying to navigate again.
                    if (titleText.Contains("אופס") || titleText.Contains("Oops"))
                    {
                        //TODO: Try to navigate to latest destination again.
                    }
                }));

                threadAutoHide.Start();
            }
            else
            {
                // Show dialog
                Syscalls.rtlDialog.Show(titleText, msgText);


                //res = MessageBox.Show(msgText, titleText, MessageBoxButton.OK);
            }
        });

        if (numberOfSeconds == 0)
        {
            // Wait for use to press OK
            while (Syscalls.rtlDialog.Result == MessageBoxResult.None)
            {
                Thread.Sleep(100);
            }

            // Get result
            res = Syscalls.rtlDialog.Result;
        }

        System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            if (res == MessageBoxResult.OK || res == MessageBoxResult.Yes)
            {
                Logger.log("Messagebox: " + msgText);
                if (callback != 0)
                {
                    UIWorker.addUIEvent(callback, 0, 0, 0, 0, true);
                }
            }

            mre.Set();
        }

                                                                 );
        mre.WaitOne();

        /* todomt
         *
         * UiApplication.getUiApplication().invokeLater(new Runnable()
         * {
         *
         *
         * public void run()
         * {
         * Font font;
         * PopupScreen screen = new PopupScreen(new VerticalFieldManager(Manager.VERTICAL_SCROLL),Field.FOCUSABLE);
         * if(titleText.length() > 0 ){
         * // Add the title
         * RichTextField title = new RichTextField(" "+titleText+ " ",RichTextField.TEXT_ALIGN_HCENTER|Field.FIELD_HCENTER|Field.NON_FOCUSABLE)
         *  {
         *     protected void paint(Graphics g)
         *     {
         *     g.setColor(Colors.WHITE);
         *     invalidate();
         *     super.paint(g);
         *     }
         *  };
         *  font = Font.getDefault().derive(Font.PLAIN,titleSize,Ui.UNITS_pt);
         *  title.setFont(font);
         *  screen.add(title);
         *
         *  // Add separator between title and text
         *  screen.add(new SeparatorField());
         * }
         *
         * // Add the message text
         * RichTextField text = new RichTextField(" "+msgText+" ",RichTextField.TEXT_ALIGN_HCENTER|Field.FIELD_HCENTER|Field.NON_FOCUSABLE)
         * {
         *    protected void paint(Graphics g)
         *    {
         *    g.setColor(Colors.WHITE);
         *    invalidate();
         *    super.paint(g);
         *    }
         * };
         * font = Font.getDefault().derive(Font.PLAIN,textSize,Ui.UNITS_pt);
         * text.setFont(font);
         * screen.add(text);
         *
         * if(numberOfSeconds>0)
         *       screen.add(new PopupScreenButton(screen, buttonText,callback,numberOfSeconds,0,0));
         * else
         *       screen.add(new PopupScreenButton(screen, buttonText,callback,0,0));
         *
         * pushScreen(isModal==1, screen);
         *
         * }
         * });*/
    }
Пример #16
0
    public void runNetLoop()
    {
        http_response_sync = new ManualResetEvent(false);
        resp = null;
        conn = null;

        //bool wait = true;
        //while (wait)
        //{
        //    lock (concurrent_conns_lock)
        //    {
        //        if (concurrent_conns <= 6)
        //        {
        //            wait = false;
        //            concurrent_conns++;
        //        }
        //    }
        //    if (wait)
        //        Thread.Sleep(1000);
        //}


        int registeredHandle = 0;

        try
        {
            lock_object = new object();
            conn        = (HttpWebRequest)WebRequest.Create(url);//todomt (HttpConnection)Connector.open(url);
            conn.AllowReadStreamBuffering = false;
            conn.AllowAutoRedirect        = true;

            //System.Net.ServicePointManager.Expect100Continue = false;

            if (method == 0)
            {
                conn.Method = "GET";
            }
            else
            {
                conn.Method = "POST";
            }

            if (updateTime != null && updateTime.Trim().Length > 0)
            {
                conn.Headers["IfModifiedSince"] = updateTime;
            }

            registeredHandle = CRunTime.registerObject(conn);
        }
        catch (Exception e)
        {
            quit = true;
            Logger.log(e.ToString());
            UIWorker.addUIEventLog("Async Net : Exception opening URL " + e.ToString());
        }

        UIWorker.addUIEventValid(c_do_async_connect_cb, registeredHandle, cb_addr, context, 0, false, this);
        if (quit)
        {
            return;
        }

        while (!quit)
        {
            lock (lock_object)
            {
                if (!do_read)
                {
                    try
                    {
                        Monitor.Wait(lock_object);
                    }
                    catch (SynchronizationLockException e)
                    {
                        Logger.log(e.ToString());
                    }
                    if (quit)
                    {
                        return;
                    }
                    if (!do_read)
                    {
                        continue;
                    }
                }
            }

            Dictionary <string, string> conn_props;
            if (Syscalls.connection_properties.TryGetValue(registeredHandle, out conn_props))
            {
                foreach (string key in conn_props.Keys)
                {
                    string value = conn_props[key];
                    if (key.Equals("Content-type"))
                    {
                        conn.ContentType = value;
                    }
                    else if (key.Equals("User-Agent"))
                    {
                        ((HttpWebRequest)(conn)).UserAgent = value;
                    }
                }
                Syscalls.connection_properties.Remove(registeredHandle);
            }

            try
            {
                if (Stream == null)
                {
                    resp = null;
                    Exception exp = null;
                    try
                    {
                        if (conn.Method == "POST")
                        {
                            http_response_sync.Reset();

                            byte[] buffer;
                            if (Syscalls.buffered_requests.TryGetValue(registeredHandle, out buffer))
                            {
                                conn.BeginGetRequestStream(delegate(IAsyncResult result)
                                {
                                    var request = (WebRequest)result.AsyncState;
                                    using (var str = request.EndGetRequestStream(result))
                                    {
                                        Syscalls.buffered_requests.Remove(registeredHandle);
                                        str.Write(buffer, 0, (int)buffer.Length);
#if DEBUG
                                        Logger.log("http put: " + System.Text.Encoding.UTF8.GetString(buffer, 0, buffer.Length));
#endif
                                    }
                                    http_response_sync.Set();
                                }, conn);
                            }
                            else
                            {
                                http_response_sync.Set();
                            }


                            http_response_sync.WaitOne();
                        }

                        http_response_sync.Reset();

                        Logger.log("Start downloading " + method + " " + conn.RequestUri);
                        conn.BeginGetResponse(delegate(IAsyncResult result)
                        {
                            try
                            {
                                var request = (HttpWebRequest)result.AsyncState;
                                Logger.log("Downloading " + request.RequestUri);
                                resp = (HttpWebResponse)request.EndGetResponse(result);
                                Logger.log("Finish getting response " + request.RequestUri);
                                http_response_sync.Set();
                            }
                            catch (Exception we)
                            {
                                exp             = we;
                                int status_code = -1;
                                if (resp != null)
                                {
                                    status_code = (int)resp.StatusCode;
                                }

                                Logger.log("status code " + status_code);

                                if (we is WebException)
                                {
                                    WebException wwe = (WebException)we;
                                    Logger.log("status - " + wwe.Status);
                                    if (wwe.Response != null)
                                    {
                                        Logger.log(" url:" + wwe.Response.ResponseUri);
                                    }

                                    Logger.log(wwe.ToString());

                                    if (wwe.Data != null)
                                    {
                                        Logger.log(wwe.Data.ToString());
                                    }
                                }
                                else
                                {
                                    Logger.log(we.ToString());
                                }

                                if (we.InnerException != null)
                                {
                                    Logger.log("Inner exception " + we.InnerException.ToString());
                                }

                                if (resp != null)
                                {
                                    resp.Dispose();
                                }
                                resp = null;
                                http_response_sync.Set();
                            }
                        }, conn);
                    }
                    catch (Exception ioe)
                    {
                        int status_code = -1;
                        if (resp != null)
                        {
                            resp.Dispose();
                            status_code = (int)resp.StatusCode;
                        }
                        exp = ioe;
                        Logger.log("status code2 " + status_code + " " + ioe.ToString());
                        if (ioe.InnerException != null)
                        {
                            Logger.log("and inner exception " + ioe.InnerException.ToString());
                        }

                        resp = null;
                        http_response_sync.Set();
                    }

                    http_response_sync.WaitOne();

                    if (resp != null)
                    {
                        Stream = resp.GetResponseStream();
                        int    status          = (int)resp.StatusCode;
                        long   data_size       = resp.ContentLength;
                        string lastModifiedStr = resp.Headers["Last-Modified"];
                        Logger.log("Finish getting response stream for " + url);
                        //Logger.log("Java header, s is " + lastModifiedStr);

                        /*
                         * We need to send c a complete header string, so we fake it by creating the
                         * res string. More header fields can be added later on besides the content length and last-modified
                         *
                         */
                        string res = "HTTP/1.1 " + status + " OK\r\nContent-Length: " + data_size + "\r\n";
                        if (lastModifiedStr != null)
                        {
                            res += "Last-Modified:" + lastModifiedStr + "\r\n\r\n";
                        }
                        else
                        {
                            res += "\r\n";
                        }

                        buffer = new byte[4096];
                        byte[] res_bytes = Syscalls.StringToAscii(res);
                        res_bytes.CopyTo(buffer, 0);
                        buffer_len     = res_bytes.Length;
                        buffer_cur_ptr = 0;
                    }
                    else
                    {
                        UIWorker.addUIEventLog("Exception in async net read: " + exp);
                        eof  = true;
                        quit = true;
                        //lock (concurrent_conns_lock)
                        //{
                        //    concurrent_conns--;
                        //}

                        ////buffer = new byte[4096];
                        //string res = "HTTP/1.1 404 Not Found\r\n";
                        ///*byte[] res_bytes*/buffer = Syscalls.StringToAscii(res);
                        ////res_bytes.CopyTo(buffer, 0);
                        //buffer_len = /*res_bytes.Length;*/buffer.Length;
                        //buffer_cur_ptr = 0;
                        //do_read = false;
                    }
                }
                else
                {
                    if (buffer_cur_ptr == buffer_len)
                    {
                        buffer_len = Stream.Read(buffer, 0, buffer.Length);
                        if (buffer_len == 0)
                        {
                            eof = true;
                            Stream.Close();
                            //lock (concurrent_conns_lock)
                            //{
                            //    concurrent_conns--;
                            //}
                        }
                        buffer_cur_ptr = 0;
                    }
                }
            }
            catch (Exception e)
            {
                UIWorker.addUIEventLog("Exception in async net read: " + e.ToString());
                eof  = true;
                quit = true;
            }
            lock (lock_object)
            {
                do_read = false;
            }

            // Call read CB
            if (is_valid)
            {
                UIWorker.addUIEventValid(c_input_ready_cb, input_id, 0, 0, 0, false, this);
            }
        }
    }
Пример #17
0
 static public void init(bool run_in_thread)
 {
     uiWorker = new UIWorker(run_in_thread);
 }
Пример #18
0
 public static void addCallback(int addr, int p1, int p2, int p3, int p4)
 {
     UIWorker.addUIEvent(addr, p1, p2, p3, p4, false);
 }
Пример #19
0
 private static void start()
 {
     UIWorker.init(true);
 }