use of org.cyanogenmod.pushsms.socket.GcmSocket in project PushSms by koush.
the class MiddlewareService method findOrCreateGcmSocket.
// given a registration, find/create the gcm socket that manages
// the secure connection between the two devices.
private GcmSocket findOrCreateGcmSocket(Registration registration) {
GcmSocket ret = gcmConnectionManager.findGcmSocket(registration);
if (ret == null) {
final GcmSocket gcmSocket = ret = gcmConnectionManager.createGcmSocket(registration, getNumber());
// parse data from the gcm connection as we get it
ret.setDataCallback(new DataCallback() {
@Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
parseGcmMessage(gcmSocket, bb);
// save the registration info (sequence numbers changed, etc)
registry.register(gcmSocket.registration.endpoint, gcmSocket.registration);
}
});
// on error, fail over any pending messages for this number
ret.setEndCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
for (String pending : new ArrayList<String>(messagesAwaitingAck.keySet())) {
String numberPart = pending.split(":")[0];
if (!PhoneNumberUtils.compare(MiddlewareService.this, numberPart, gcmSocket.getNumber()))
continue;
GcmText gcmText = messagesAwaitingAck.get(pending);
if (gcmText == null)
continue;
gcmText.manageFailure(handler, smsManager);
}
}
});
}
return ret;
}
Aggregations