Ejemplo n.º 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);
     }
 }
Ejemplo n.º 2
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);
    }
Ejemplo n.º 3
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);
    }
Ejemplo n.º 4
0
    /*
     *
     * 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);
    }
Ejemplo n.º 5
0
    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);
    }
Ejemplo n.º 6
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);
    }
Ejemplo n.º 7
0
    /*
     *
     * 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);
    }
Ejemplo n.º 8
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);
                }
            }
        }
    }