Bug 831702 - 0001.Add data size calculation function. r=yoshi.

This commit is contained in:
Chuck Lee 2013-01-23 11:42:33 +08:00
parent 1930e5b065
commit dba48d51a9

View File

@ -143,6 +143,55 @@ let Buf = {
// This is the token of last solicited response.
this.lastSolicitedToken = 0;
// Queue for storing outgoing override points
this.outgoingBufferCalSizeQueue = [];
},
/**
* Mark current outgoingIndex as start point for calculation length of data
* written to outgoingBuffer.
* Mark can be nested for here uses queue to remember marks.
*
* @param writeFunction
* Function to write data length into outgoingBuffer, this function is
* also used to allocate buffer for data length.
* Raw data size(in Uint8) is provided as parameter calling writeFunction.
* If raw data size is not in proper unit for writing, user can adjust
* the length value in writeFunction before writing.
**/
startCalOutgoingSize: function startCalOutgoingSize(writeFunction) {
let sizeInfo = {index: this.outgoingIndex,
write: writeFunction};
// Allocate buffer for data lemgtj.
writeFunction.call(0);
// Get size of data length buffer for it is not counted into data size.
sizeInfo.size = this.outgoingIndex - sizeInfo.index;
// Enqueue size calculation information.
this.outgoingBufferCalSizeQueue.push(sizeInfo);
},
/**
* Calculate data length since last mark, and write it into mark position.
**/
stopCalOutgoingSize: function stopCalOutgoingSize() {
let sizeInfo = this.outgoingBufferCalSizeQueue.pop();
// Remember current outgoingIndex.
let currentOutgoingIndex = this.outgoingIndex;
// Calculate data length, in uint8.
let writeSize = this.outgoingIndex - sizeInfo.index - sizeInfo.size;
// Write data length to mark, use same function for allocating buffer to make
// sure there is no buffer overloading.
this.outgoingIndex = sizeInfo.index;
sizeInfo.write(writeSize);
// Restore outgoingIndex.
this.outgoingIndex = currentOutgoingIndex;
},
/**
@ -332,7 +381,7 @@ let Buf = {
}
return strings;
},
readStringDelimiter: function readStringDelimiter(length) {
let delimiter = this.readUint16();
if (!(length & 1)) {
@ -409,7 +458,7 @@ let Buf = {
this.writeString(strings[i]);
}
},
writeStringDelimiter: function writeStringDelimiter(length) {
this.writeUint16(0);
if (!(length & 1)) {
@ -672,7 +721,7 @@ let Buf = {
/**
* The RIL state machine.
*
*
* This object communicates with rild via parcels and with the main thread
* via post messages. It maintains state about the radio, ICC, calls, etc.
* and acts upon state changes accordingly.
@ -756,7 +805,7 @@ let RIL = {
* Application identification for apps in ICC.
*/
this.aid = null;
/**
* Application type for apps in ICC.
*/
@ -830,7 +879,7 @@ let RIL = {
MMI: cbmmi || null
};
},
get muted() {
return this._muted;
},
@ -1608,7 +1657,7 @@ let RIL = {
if (!call) {
return;
}
switch (call.state) {
case CALL_STATE_INCOMING:
Buf.simpleRequest(REQUEST_ANSWER);
@ -1635,7 +1684,7 @@ let RIL = {
if (!call) {
return;
}
switch (call.state) {
case CALL_STATE_INCOMING:
Buf.simpleRequest(REQUEST_UDUB);
@ -1646,7 +1695,7 @@ let RIL = {
break;
}
},
holdCall: function holdCall(options) {
let call = this.currentCalls[options.callIndex];
if (call && call.state == CALL_STATE_ACTIVE) {
@ -2366,7 +2415,7 @@ let RIL = {
// GET_INKEY
// When the ME issues a successful TERMINAL RESPONSE for a GET INKEY
// ("Yes/No") command with command qualifier set to "Yes/No", it shall
// supply the value '01' when the answer is "positive" and the value
// supply the value '01' when the answer is "positive" and the value
// '00' when the answer is "negative" in the Text string data object.
text = response.isYesNo ? 0x01 : 0x00;
} else {
@ -2547,6 +2596,7 @@ let RIL = {
debug("Stk Envelope " + JSON.stringify(options));
}
let token = Buf.newParcel(REQUEST_STK_SEND_ENVELOPE_COMMAND);
let berLen = TLV_DEVICE_ID_SIZE + /* Size of Device Identifier TLV */
(options.itemIdentifier ? TLV_ITEM_ID_SIZE : 0) +
(options.helpRequested ? TLV_HELP_REQUESTED_SIZE : 0) +
@ -4224,12 +4274,12 @@ RIL[REQUEST_HANGUP] = function REQUEST_HANGUP(length, options) {
}
this.getCurrentCalls();
};
};
RIL[REQUEST_HANGUP_WAITING_OR_BACKGROUND] = function REQUEST_HANGUP_WAITING_OR_BACKGROUND(length, options) {
if (options.rilRequestError) {
return;
}
this.getCurrentCalls();
};
RIL[REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND] = function REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND(length, options) {
@ -4251,7 +4301,7 @@ RIL[REQUEST_SWITCH_HOLDING_AND_ACTIVE] = function REQUEST_SWITCH_HOLDING_AND_ACT
return;
}
// XXX Normally we should get a UNSOLICITED_RESPONSE_CALL_STATE_CHANGED parcel
// XXX Normally we should get a UNSOLICITED_RESPONSE_CALL_STATE_CHANGED parcel
// notifying us of call state changes, but sometimes we don't (have no idea why).
// this.getCurrentCalls() helps update the call state actively.
this.getCurrentCalls();
@ -4999,7 +5049,7 @@ RIL[UNSOLICITED_NITZ_TIME_RECEIVED] = function UNSOLICITED_NITZ_TIME_RECEIVED()
// Always print the NITZ info so we can collection what different providers
// send down the pipe (see bug XXX).
// TODO once data is collected, add in |if (DEBUG)|
debug("DateTimeZone string " + dateString);
let now = Date.now();
@ -6106,16 +6156,16 @@ let GsmPDUHelper = {
* The Length of BCD number.
*
* From TS 131.102, in EF_ADN, EF_FDN, the field 'Length of BCD number'
* means the total bytes should be allocated to store the TON/NPI and
* means the total bytes should be allocated to store the TON/NPI and
* the dialing number.
* For example, if the dialing number is 1234567890,
* and the TON/NPI is 0x81,
* The field 'Length of BCD number' should be 06, which is
* The field 'Length of BCD number' should be 06, which is
* 1 byte to store the TON/NPI, 0x81
* 5 bytes to store the BCD number 2143658709.
*
* Here the definition of the length is different from SMS spec,
* TS 23.040 9.1.2.5, which the length means
* Here the definition of the length is different from SMS spec,
* TS 23.040 9.1.2.5, which the length means
* "number of useful semi-octets within the Address-Value field".
*/
readDiallingNumber: function readDiallingNumber(len) {