コード例 #1
0
 public int loadTile(int fips, int tile_index, int store_id, int data_addr)
 {
     try
     {
         byte[] data        = recordstore[getStoreID(store_id)].getRecord(getRecordID(store_id));
         int    store_index = -1;
         if (data.Length > 4)
         {
             store_index = (data[3] & 0xff) | ((data[2] & 0xff) << 8) | ((data[1] & 0xff) << 16) | (data[0] << 24);
         }
         if (store_index != tile_index)
         {
             Logger.log("tile storage corrupted! initialize.");
             eraseStorage();
             initialize();
             return(-1);
         }
         CRunTime.memcpy(data_addr, data, 4, data.Length - 4);
         listSetFirst(store_id);
         return(0);
     }
     catch (Exception e)
     {
         Logger.log("Error reading tile - " + e.ToString() + ". Initialize.");
         eraseStorage();
         initialize();
         return(-1);
     }
 }
コード例 #2
0
 public static void assertMemoryWrite(String type, int pc, int address, int ins)
 {
     if (address >= CRunTime.memoryReadWord(16) && address < CRunTime.memoryReadWord(20))
     {
         Logger.log(type + " on 0x" + pc + " memory[0x" + address + "] = 0x" + ins + "");
     }
 }
コード例 #3
0
    public int read()
    {
        if (buffer_ptr < 4)
        {
            m_addr++;
            return(buffer[buffer_ptr++]);
        }

        if (((m_addr & 0x3) == 0) && ((m_end - m_addr) > 3))
        {
            int i = CRunTime.memory[m_addr >> 2];

            for (int j = 0; j < 4; j++)
            {
                int b = unchecked (i & 0xff);
                buffer[3 - j] = b;
                i             = (unchecked (i >> 8));
            }

            buffer_ptr = 1;
            m_addr++;
            return(buffer[0]);
        }

        if (m_addr < m_end)
        {
            return(CRunTime.memoryReadByteUnsigned(m_addr++));
        }

        return(-1);
    }
コード例 #4
0
ファイル: SoundMgr.cs プロジェクト: glennneiger/WazeWP7
        public int playList(int _list, string soundDir)
        {
            _soundDir = soundDir;
            lock (sound_lists)
            {
                if (current_list_id != -1)
                {
                    /* playing */
                    int next = (current_list_id + 1) % MAX_LISTS;

                    if (sound_lists[next] != null)
                    {
                        SoundList list =
                            (SoundList)CRunTime.getRegisteredObject(sound_lists[next].Value);

                        if ((list.flags & SoundList.SOUND_LIST_NO_FREE) == 0)
                        {
                            listFree(sound_lists[next].Value);
                        }
                    }

                    sound_lists[next] = new int?(_list);

                    return(0);
                }
            }

            /* not playing */
            sound_lists[0] = new int?(_list);
            playNextList();

            return(0);
        }
コード例 #5
0
 public static void memoryWriteWordLeft(int address, int rtVal)
 {
     CRunTime.memoryWriteByte(address + 3, (rtVal));
     CRunTime.memoryWriteByte(address + 2, (rtVal >> 8));
     CRunTime.memoryWriteByte(address + 1, (rtVal >> 16));
     CRunTime.memoryWriteByte(address + 0, (rtVal >> 24));
 }
コード例 #6
0
ファイル: UIWorker.cs プロジェクト: glennneiger/WazeWP7
    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);
    }
コード例 #7
0
    public static void stringToCharPtr(string str, int address)
    {
        byte[] str_bytes = Encoding.UTF8.GetBytes(str);
        int    length    = str_bytes.Length;

        CRunTime.memcpy(address, str_bytes, 0, length);
        CRunTime.memoryWriteByte(address + length, 0);
    }
コード例 #8
0
 public static void emitFunctionEnterTrace(String str)
 {
     for (int i = 0; i < CRunTime.functionNesting; i++)
     {
         str = " " + str;
     }
     CRunTime.functionNesting++;
     CRunTime.emitTrace(str);
 }
コード例 #9
0
    /**
     * 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);
    }
コード例 #10
0
    /* The nasty lwl/lwr and swl/swr instructions */
    public static int memoryReadWordLeft(int address)
    {
        int b0 = CRunTime.memoryReadByteUnsigned(address + 3);
        int b1 = CRunTime.memoryReadByteUnsigned(address + 2);
        int b2 = CRunTime.memoryReadByteUnsigned(address + 1);
        int b3 = CRunTime.memoryReadByteUnsigned(address + 0);

        return(b0 | (b1 << 8) | (b2 << 16) | (b3 << 24));
    }
コード例 #11
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();
        }
コード例 #12
0
    /**
     * Register a callback function for a particular string.
     *
     * @param charPtr a C char* with the name of the callback
     * @param fnPtr the function pointer that implements the callback
     *
     * @return the callback id
     */
    public static int registerCallback(int charPtr, int fnPtr)
    {
        String name = CRunTime.charPtrToString(charPtr);
        int    id   = (int)CRunTime.callbacksByName[name];
        int    old  = (int)CRunTime.objectRepository[id];

        CRunTime.objectRepository[id] = fnPtr;     /* Replace with the fn ptr */

        return(old);
    }
コード例 #13
0
    public int storeTile(int fips, int tile_index, int data_addr, int size)
    {
        int id = findTile(fips, tile_index, 0);

        if (id == -1)
        {
            id = listAllocID();
        }

        byte[] data = new byte[size + 4];

        uint i = (uint)tile_index;

        data[3] = (byte)i;
        i       = i >> 8;
        data[2] = (byte)i;
        i       = i >> 8;
        data[1] = (byte)i;
        i       = i >> 8;
        data[0] = (byte)i;

        CRunTime.memcpy(data, 4, data_addr, size);

        try
        {
            recordstore[getStoreID(id)].setRecord(getRecordID(id), data, 0, data.Length);
            ids[id] = tile_index;
            writeIndex();
        }
        catch (RecordStoreNotOpenException e)
        {
            Logger.log(e.ToString());
            Logger.log("RecordStoreNotOpenException");
            return(-1);
        }
        catch (RecordStoreFullException e)
        {
            Logger.log(e.ToString());
            Logger.log("RecordStoreFullException");
            return(-1);
        }
        catch (InvalidRecordIDException e)
        {
            Logger.log(e.ToString());
            Logger.log("InvalidRecordIDException");
            return(-1);
        }
        catch (Exception e)
        {
            Logger.log("Error storing record!! " + e.ToString());
            return(-1);
        }
        //dumpIndex();
        return(0);
    }
コード例 #14
0
    public static void memcpy(byte[] bytes, int off, int addr, int size)
    {
        while (size > 0)
        {
            bytes[off++] = (byte)CRunTime.memoryReadByte(addr);
            addr++;
            size--;
        }

        return;
    }
コード例 #15
0
ファイル: SoundMgr.cs プロジェクト: glennneiger/WazeWP7
        public int listAdd(int _list, string name)
        {
            SoundList list = (SoundList)CRunTime.getRegisteredObject(_list);

            if (list.count == SoundList.MAX_SOUND_LIST)
            {
                return(-1);
            }
            list.list[list.count] = name + ".wav";
            list.count++;
            return(list.count - 1);
        }
コード例 #16
0
    public static int memoryReadShort(int address)
    {
        int lout = CRunTime.memoryReadShortUnsigned(address);

        /* Sign-extend */
        if ((lout & (1 << 15)) != 0)
        {
            return((int)(lout | 0xffff0000));
        }

        return(lout);
    }
コード例 #17
0
ファイル: FreemapApp.cs プロジェクト: glennneiger/WazeWP7
    /*
     *
     * Pushes the file Connection path to be used for Waze ( for config files, icons, logs, etc. ).
     *
     * Prefers SD-card over device memory
     *
     * Returns :
     *
     * The length of the path.
     *
     */

    public static int fileConnectionPath(int addr)
    {
        /*todomt
         * string root = null;
         * bool sdcard_exists = false;
         * bool internal_exists = false;
         * bool path_found = false;
         * byte[] str_bytes;
         * string valid_path = new string();
         * string FILE_SYSTEM_ROOT = "file:///store/home/user";
         * string FILE_SYSTEM_WAZE = "file:///store/home/user/waze";
         * string SDCARD_WAZE = "file:///SDCard/BlackBerry/waze";
         * try{
         * Enumeration e = FileSystemRegistry.listRoots();
         * while (e.hasMoreElements()) {
         * root = (string) e.nextElement();
         * if( root.equalsIgnoreCase("sdcard/") ) {
         * sdcard_exists = true;
         * }
         * else if( root.equalsIgnoreCase("store/") ) {
         * internal_exists =true;
         * }
         * }
         * if(sdcard_exists){
         * if(createPath(SDCARD_WAZE) == 1){
         * valid_path = SDCARD_WAZE;
         * path_found = true;
         * }
         * }
         * if(!path_found){
         * if(internal_exists){
         * if(createPath(FILE_SYSTEM_WAZE) == 1){
         * valid_path = FILE_SYSTEM_WAZE;
         * }else{
         * valid_path = FILE_SYSTEM_ROOT;
         * }
         * }else{
         * Logger.log("WAZE ERROR: No sd-card or internal memory");
         * }
         * }
         * str_bytes = valid_path.getBytes();
         * CRunTime.memcpy(addr,str_bytes,0,str_bytes.length);
         * return str_bytes.length;
         * }catch(Exception e){
         * Logger.log("WAZE ERROR: Exception in fileConnectionPath : " + e);
         * return 0;
         * }*/
        byte[] str_bytes = Syscalls.StringToAscii("Userstore://");
        CRunTime.memcpy(addr, str_bytes, 0, str_bytes.Length);
        return(str_bytes.Length);
    }
コード例 #18
0
    /* Misc. utils */
    public static String charPtrToString(int address)
    {
        int startAddress = address;
        int i            = 0;
        int len          = 0;

        if (address == 0)
        {
            return("");
        }

        while (CRunTime.memoryReadByte(startAddress + len) != 0)
        {
            len++;
        }

        if (len == 0)
        {
            return("");
        }

        byte[] vec = new byte[len];

        for (i = 0; i < len; i++)
        {
            vec[i] = (byte)CRunTime.memoryReadByte(startAddress + i);
        }
        try
        {
            String str;
            if (CibylConfig.stringEncoding == null)
            {
                str = new System.Text.UTF8Encoding().GetString(vec, 0, vec.Length);
            }
            else
            {
                str = BitConverter.ToString(vec);     // tofix new String(vec, CibylConfig.stringEncoding);
            }
            return(str);
        }
        catch (Exception e)
        {
            Logger.log(e.ToString());
            return("UnSupportedEncodingException happened");
        }
    }
コード例 #19
0
    public static Object deRegisterObject(int handle)
    {
        Object lout = CRunTime.getRegisteredObject(handle);

        if (handle == 0)
        {
            return(lout);
        }

        if (CRunTime.firstFree > handle)
        {
            CRunTime.firstFree = handle;
        }
        CRunTime.objectRepository[handle] = null;

        return(lout);
    }
コード例 #20
0
ファイル: FreemapApp.cs プロジェクト: glennneiger/WazeWP7
    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);
        }
    }
コード例 #21
0
ファイル: UIWorker.cs プロジェクト: glennneiger/WazeWP7
    public static void writeMsgToBuffer(String msg)
    {
        byte[] str_bytes = Syscalls.StringToAscii(msg);
        int    length;


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

        CRunTime.memcpy(msgAddr, str_bytes, 0, length);
        CRunTime.memoryWriteByte(msgAddr + length, 0);
    }
コード例 #22
0
    public int read(int addr, int len)
    {
        if (eof || (buffer_len == 0))
        {
            return(-1);
        }

        if (len > buffer_len - buffer_cur_ptr)
        {
            len = buffer_len - buffer_cur_ptr;
        }

        CRunTime.memcpy(addr, buffer, buffer_cur_ptr, len);
        buffer_cur_ptr += len;

        lock (lock_object)
        {
            do_read = true;
            Monitor.Pulse(lock_object);
        }

        return(len);
    }
コード例 #23
0
ファイル: FreemapApp.cs プロジェクト: glennneiger/WazeWP7
    /*
     *
     * Adds the needed suffix to the url string. The connection Timeout parameter
     *
     * determines how long before a timeout is thrown.
     */
    /*todomt
     * public static string str2Add2Url(bool printInfo){
     * string st = "";
     * st += ";ConnectionTimeout=25000";
     * //The Device is a simultaor --> TCP
     * if (DeviceInfo.isSimulator())
     * {
     * st += ";deviceside=true";
     * }
     * else if ( ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_BIS_B ) == CoverageInfo.COVERAGE_BIS_B )||
     *    ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT ) == CoverageInfo.COVERAGE_DIRECT ) )
     * { //A carrier is providing us with the data service
     * st += getConnectionSuffix(printInfo);
     * }else if (WIFI_ENABLED && _wifiAvailable){
     * st += ";interface=wifi";
     * }else{
     * UIWorker.addUIEventLog("FreemapApp - getConnectionString - No network Coverage");
     * return "";
     * }
     * return st;
     * }
     */

    /*
     * If called with updateAddr 0, don't update the static connection string address
     */
    public static int getConnectionString(int updateAddr, int addr, int size)
    {
        int strSize;

        if (updateAddr != 0)
        {
            connStringAddr = addr;
            connStringSize = size;
        }
        strSize = connStringSize;
        string st = "";

        st += "";  //todomt str2Add2Url(false);
        byte[] bytes = Syscalls.StringToAscii(st);
        strSize--;
        if (strSize > bytes.Length)
        {
            strSize = bytes.Length;
        }
        CRunTime.memcpy(connStringAddr, bytes, 0, strSize);
        CRunTime.memoryWriteByte(connStringAddr + strSize, 0);
        return(0);
    }
コード例 #24
0
    public static void memcpy(int addr, byte[] bytes, int off, int size)
    {
        while (((addr & 0x3) != 0) && (size > 0))
        {
            byte b = bytes[off++];
            CRunTime.memoryWriteByte(addr, b);
            addr++;
            size--;
            if (size == 0)
            {
                return;
            }
        }

        while (size > 3)
        {
            int i = 0;
            for (int j = 0; j < 4; j++)
            {
                i = i << 8;
                int b = bytes[off++] & 0xff;
                i |= b;
            }

            CRunTime.memoryWriteWord(addr, i);
            addr += 4;
            size -= 4;
        }

        while (size > 0)
        {
            byte b = bytes[off++];
            CRunTime.memoryWriteByte(addr, b);
            addr++;
            size--;
        }
    }
コード例 #25
0
    public static void init(Stream codeStream)
    {
        CRunTime.memory           = null;
        CRunTime.objectRepository = null;
        //System.gc();

        int memorySize = 512 * 1024 * 10;    // (int)(51200000 * 4 /* Runtime.getRuntime().freeMemory() */ * CibylConfig.cibylMemoryProportion);

        if (CibylConfig.memorySize != 0)
        {
            memorySize = CibylConfig.memorySize;
        }

        if (CibylConfig.faultMemoryIn)
        {
            memorySize = (int)CRunTime.faultMemoryIn(CibylConfig.memorySize);
        }

        /* See to it that the memory is aligned to 8. This caused a very
         * fun bug before in printf when called with "%f".
         *
         * Also setup the event stack at the very top of the memory
         */
        memorySize -= (memorySize & 7);
        CRunTime.eventStackPointer = memorySize - 8;

        int len = (int)codeStream.Length / 4;

        if (len < 5)
        {
            /* This binary is broken - we need the header data */
            throw new Exception("Data input is too small");
        }

        CRunTime.init(codeStream, memorySize);
    }
コード例 #26
0
    public int findTile(int fips, int tile_index, int size_addr)
    {
        for (int i = 1; i < numRecords; i++)
        {
            if (ids[i] == tile_index)
            {
                if (size_addr != 0)
                {
                    try
                    {
                        CRunTime.memoryWriteWord(size_addr, recordstore[getStoreID(i)].getRecordSize(getRecordID(i)) - 4);
                    }
                    catch (RecordStoreException e)
                    {
                        Logger.log(e.ToString());
                        return(-1);
                    }
                }
                return(i);
            }
        }

        return(-1);
    }
コード例 #27
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);
            }
        }
    }
コード例 #28
0
ファイル: SoundMgr.cs プロジェクト: glennneiger/WazeWP7
 public void listFree(int?_list)
 {
     CRunTime.deRegisterObject(_list.Value);
 }
コード例 #29
0
ファイル: SoundMgr.cs プロジェクト: glennneiger/WazeWP7
        public int listCount(int _list)
        {
            SoundList list = (SoundList)CRunTime.getRegisteredObject(_list);

            return(list.count);
        }
コード例 #30
0
ファイル: SoundMgr.cs プロジェクト: glennneiger/WazeWP7
        //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));
        }