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); }
/** * Publish a new callback. This is supposed to be called from Java * during startup to get a callback identifier. * * @param name the name of the callback * * @return a callback ID */ public static int publishCallback(String name) { int id = CRunTime.registerObject(0); /* Used to get an id, 0 means nothing here */ int intObject = id; CRunTime.callbacksByName.Add(name, intObject); /* Register name:id */ return(id); }
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); } } }
//public void playerUpdate(Player p, string theevent, Object eventData) { // //System.out.println("playerUpdate: " + event); // if ((theevent != END_OF_MEDIA) && (theevent != STOPPED) && (theevent != ERROR) && (theevent != CLOSED)) return; // if (theevent != CLOSED) // { // new Thread() // { // public void run() // { // setPriority(Thread.MAX_PRIORITY); // try // { // if (p.getState() == p.PREFETCHED) p.stop(); // } // catch (Exception e) { } // try { p.close(); } // catch (Exception e) { } // if (event == STOPPED) current_list_item--; // } // }.start(); // } // else // { // new Thread() // { // public void run() // { // setPriority(Thread.MAX_PRIORITY); // playNextItem(); // } // }.start(); // } //} #endregion OldPlayerUpdate Code public int listCreate(int flags) { SoundList list = new SoundList(flags); return(CRunTime.registerObject(list)); }