FileDocCategorySizeDatePackage
RIL.javaAPI DocAndroid 1.5 API85199Wed May 06 22:42:02 BST 2009com.android.internal.telephony.gsm

RILRequest

public class RILRequest extends Object
{@hide}

Fields Summary
static final String
LOG_TAG
static int
sNextSerial
static Object
sSerialMonitor
private static Object
sPoolSync
private static RILRequest
sPool
private static int
sPoolSize
private static final int
MAX_POOL_SIZE
int
mSerial
int
mRequest
android.os.Message
mResult
android.os.Parcel
mp
RILRequest
mNext
Constructors Summary
private RILRequest()

    
Methods Summary
static com.android.internal.telephony.gsm.RILRequestobtain(int request, android.os.Message result)
Retrieves a new RILRequest instance from the pool.

param
request RIL_REQUEST_*
param
result sent when operation completes
return
a RILRequest instance from the pool.


                                  
          
        RILRequest rr = null;
        
        synchronized(sPoolSync) {
            if (sPool != null) {
                rr = sPool;
                sPool = rr.mNext;
                rr.mNext = null;
                sPoolSize--;
            }
        }
        
        if (rr == null) {
            rr = new RILRequest();
        }

        synchronized(sSerialMonitor) {
            rr.mSerial = sNextSerial++;
        }
        rr.mRequest = request;
        rr.mResult = result;
        rr.mp = Parcel.obtain();

        if (result != null && result.getTarget() == null) {
            throw new NullPointerException("Message target must not be null");
        }

        // first elements in any RIL Parcel
        rr.mp.writeInt(request);
        rr.mp.writeInt(rr.mSerial);

        return rr;
    
voidonError(int error)

        CommandException ex;

        ex = CommandException.fromRilErrno(error);

        if (RIL.RILJ_LOGD) Log.d(LOG_TAG, serialString() + "< "
            + RIL.requestToString(mRequest) 
            + " error: " + ex);

        if (mResult != null) {
            AsyncResult.forMessage(mResult, null, ex);
            mResult.sendToTarget();
        }

        if (mp != null) {
            mp.recycle();
            mp = null;
        }
    
voidrelease()
Returns a RILRequest instance to the pool. Note: This should only be called once per use.

        synchronized (sPoolSync) {
            if (sPoolSize < MAX_POOL_SIZE) {
                this.mNext = sPool;
                sPool = this;
                sPoolSize++;
            }
        }
    
static voidresetSerial()

        synchronized(sSerialMonitor) {
            sNextSerial = 0;
        }
    
java.lang.StringserialString()

        //Cheesy way to do %04d
        StringBuilder sb = new StringBuilder(8);
        String sn;

        sn = Integer.toString(mSerial);

        //sb.append("J[");
        sb.append('[");
        for (int i = 0, s = sn.length() ; i < 4 - s; i++) {
            sb.append('0");
        }

        sb.append(sn);
        sb.append(']");
        return sb.toString();