Fields Summary |
---|
private static final String | KEY_CIR_HTTP_ADDRESS |
private static final String | KEY_CIR_TCP_PORT |
private static final String | KEY_CIR_TCP_ADDRESS |
private static final String | KEY_CIR_METHOD |
private static final String | KEY_SERVER_POLL_MIN |
private static final String | KEY_PASSWORD |
private static final String | KEY_USERNAME |
private static final String | KEY_KEEP_ALIVE_TIME |
private static final String | KEY_SESSION_COOKIE |
private static final String | KEY_SESSION_ID |
private static final int | DEFAULT_TCP_PORT |
private ImpsConnection | mConnection |
private String | mId |
private String | mCookie |
private long | mKeepAliveTime |
private com.android.im.imps.ImpsConnectionConfig.CirMethod | mCurrentCirMethod |
private String | mCirTcpAddress |
private int | mCirTcpPort |
private long | mServerPollMin |
private String | mCirHttpAddress |
private com.android.im.engine.LoginInfo | mLoginInfo |
private boolean | mCapablityRequest |
private List | mSupportedCirMethod |
private com.android.im.engine.Contact | mLoginUser |
PrimitiveElement | mServiceTree |
private boolean | mNewFlag that indicates this is a new created session or not. |
Methods Summary |
---|
private Primitive | buildCapabilityRequest()
Primitive capabilityRequest = new Primitive(ImpsTags.ClientCapability_Request);
PrimitiveElement list = capabilityRequest.addElement(ImpsTags.CapabilityList);
list.addChild(ImpsTags.ClientType, ImpsClientCapability.getClientType());
list.addChild(ImpsTags.AcceptedContentLength, Integer
.toString(ImpsClientCapability.getAcceptedContentLength()));
list.addChild(ImpsTags.ParserSize,
Integer.toString(ImpsClientCapability.getParserSize()));
list.addChild(ImpsTags.MultiTrans,
Integer.toString(ImpsClientCapability.getMultiTrans()));
// TODO: MultiTransPerMessage is IMPS 1.3
//list.addChild(ImpsTags.MultiTransPerMessage,
// Integer.toString(ImpsClientCapability.getMultiTransPerMessage()));
list.addChild(ImpsTags.InitialDeliveryMethod,
ImpsClientCapability.getInitialDeliveryMethod());
list.addChild(ImpsTags.ServerPollMin, Long.toString(mServerPollMin));
for(TransportType supportedBear : ImpsClientCapability.getSupportedBearers()) {
list.addChild(ImpsTags.SupportedBearer, supportedBear.toString());
}
for(CirMethod supportedCirMethod : ImpsClientCapability.getSupportedCirMethods()) {
list.addChild(ImpsTags.SupportedCIRMethod, supportedCirMethod.toString());
if (CirMethod.SUDP.equals(supportedCirMethod)) {
list.addChild(ImpsTags.UDPPort,
Integer.toString(mConnection.getConfig().getUdpPort()));
}
}
return capabilityRequest;
|
private Primitive | buildServiceRequest()
Primitive serviceRequest = new Primitive(ImpsTags.Service_Request);
PrimitiveElement functions = serviceRequest.addElement(ImpsTags.Functions);
PrimitiveElement features = functions.addChild(ImpsTags.WVCSPFeat);
features.addChild(ImpsTags.FundamentalFeat);
features.addChild(ImpsTags.PresenceFeat);
features.addChild(ImpsTags.IMFeat);
features.addChild(ImpsTags.GroupFeat);
serviceRequest.addElement(ImpsTags.AllFunctionsRequest, true);
return serviceRequest;
|
void | extractCapability(Primitive capabilityResponse)
mSupportedCirMethod = new ArrayList<CirMethod>();
PrimitiveElement agreedList = capabilityResponse.getContentElement()
.getFirstChild();
for (PrimitiveElement element : agreedList.getChildren()) {
String tag = element.getTagName();
if (tag.equals(ImpsTags.SupportedCIRMethod)) {
try {
mSupportedCirMethod.add(CirMethod.valueOf(element.getContents()));
} catch (IllegalArgumentException e) {
ImpsLog.log("Unrecognized CIR method " + element.getContents());
}
} else if (tag.equals(ImpsTags.TCPAddress)) {
mCirTcpAddress = element.getContents();
} else if (tag.equals(ImpsTags.TCPPort)) {
mCirTcpPort = (int)ImpsUtils.parseLong(element.getContents(),
DEFAULT_TCP_PORT);
} else if (tag.equals(ImpsTags.ServerPollMin)) {
long defaultPollMin = mConnection.getConfig().getDefaultServerPollMin();
mServerPollMin = ImpsUtils.parseLong(element.getContents(),
defaultPollMin);
if (mServerPollMin <= 0) {
mServerPollMin = defaultPollMin;
}
} else if (tag.equals(ImpsTags.CIRHTTPAddress)
|| tag.equals(ImpsTags.CIRURL)) {
// This tag is CIRHTTPAddress in 1.3 and CIRURL in 1.2
mCirHttpAddress = element.getChildContents(ImpsTags.URL);
}
}
|
public java.lang.String | getCirHttpAddress()Gets the URL used for standalone HTTP binding of CIR channel.
return mCirHttpAddress;
|
public java.lang.String | getCirTcpAddress()Gets the IP address for standalone TCP/IP CIR method.
return mCirTcpAddress;
|
public int | getCirTcpPort()Gets the port number for the standalone TCP/IP CIR method.
return mCirTcpPort;
|
public java.util.HashMap | getContext()
HashMap<String, String> values = new HashMap<String, String>();
values.put(KEY_SESSION_ID, mId);
values.put(KEY_SESSION_COOKIE, mCookie);
values.put(KEY_KEEP_ALIVE_TIME, Long.toString(mKeepAliveTime));
values.put(KEY_USERNAME, mLoginInfo.getUserName());
values.put(KEY_PASSWORD, mLoginInfo.getPassword());
values.put(KEY_SERVER_POLL_MIN, Long.toString(mServerPollMin));
values.put(KEY_CIR_METHOD, mCurrentCirMethod.name());
if(mCurrentCirMethod == CirMethod.STCP) {
values.put(KEY_CIR_TCP_ADDRESS, mCirTcpAddress);
values.put(KEY_CIR_TCP_PORT, Integer.toString(mCirTcpPort));
} else if (mCurrentCirMethod == CirMethod.SHTTP) {
values.put(KEY_CIR_HTTP_ADDRESS, mCirHttpAddress);
}
return values;
|
public java.lang.String | getCookie()
return mCookie;
|
public com.android.im.imps.ImpsConnectionConfig.CirMethod | getCurrentCirMethod()
return mCurrentCirMethod;
|
public java.lang.String | getID()Gets the unique id of the session.
return mId;
|
public long | getKeepAliveTime()Gets the auto logout timer value.
return mKeepAliveTime;
|
public com.android.im.engine.LoginInfo | getLoginInfo()
return mLoginInfo;
|
public com.android.im.engine.Contact | getLoginUser()
return mLoginUser;
|
public ImpsUserAddress | getLoginUserAddress()
return (ImpsUserAddress) mLoginUser.getAddress();
|
public java.lang.String | getPassword()
return mLoginInfo.getPassword();
|
public long | getServerPollMin()Gets the minimum time interval (in seconds) that MUST pass before two
subsequent PollingRequest transactions.
return mServerPollMin;
|
public PrimitiveElement | getServiceTree()Gets the service tree of the features and functions that the server
supports.
return mServiceTree;
|
public java.util.List | getSupportedCirMethods()Gets a collection of CIR methods that are supported by both the client
and the server.
return mSupportedCirMethod;
|
public java.lang.String | getUserName()
return mLoginInfo.getUserName();
|
public boolean | isCapablityRequestRequired()Gets if further capability request is required in the session.
return mCapablityRequest || mNew;
|
public void | negotiateCapabilityAsync(AsyncCompletion completion)Perform client capability negotiation with the server asynchronously.
Primitive capabilityRequest = buildCapabilityRequest();
AsyncTransaction tx = new AsyncTransaction(
mConnection.getTransactionManager(), completion) {
@Override
public void onResponseOk(Primitive response) {
extractCapability(response);
}
@Override
public void onResponseError(ImpsErrorInfo error) { }
};
tx.sendRequest(capabilityRequest);
|
public void | negotiateServiceAsync(AsyncCompletion completion)Perform service negotiation with the server asynchronously.
Primitive serviceRequest = buildServiceRequest();
AsyncTransaction tx = new AsyncTransaction(
mConnection.getTransactionManager(), completion) {
@Override
public void onResponseOk(Primitive response) {
mServiceTree = response.getElement(ImpsTags.AllFunctions).getFirstChild();
}
@Override
public void onResponseError(ImpsErrorInfo error) { }
};
tx.sendRequest(serviceRequest);
|
public void | setCapablityRequestRequired(boolean required)
mCapablityRequest = required;
|
public void | setCurrentCirMethod(com.android.im.imps.ImpsConnectionConfig.CirMethod cirMethod)
mCurrentCirMethod = cirMethod;
|
public void | setId(java.lang.String id)
mId = id;
|
public void | setKeepAliveTime(long keepAliveTime)
mKeepAliveTime = keepAliveTime;
|
private void | setLoginInfo(com.android.im.engine.LoginInfo loginInfo)Sets the Login information. After login successfully, the login
information should be saved in the session context so that we can auto
login when reconnect to the server.
try {
ImpsAddress address = new ImpsUserAddress(loginInfo.getUserName());
mLoginUser = new Contact(address, address.getScreenName());
mLoginInfo = loginInfo;
} catch (IllegalArgumentException e) {
throw new ImException(ImErrorInfo.INVALID_USERNAME,
"Invalid username");
}
|