/*
* Copyright (C) 2010 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
*
* This file is part of imsdroid Project (http://code.google.com/p/imsdroid)
*
* imsdroid is free software: you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* imsdroid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package org.doubango.imsdroid.Services.Impl;
import java.nio.ByteBuffer;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import org.doubango.imsdroid.CustomDialog;
import org.doubango.imsdroid.IMSDroid;
import org.doubango.imsdroid.R;
import org.doubango.imsdroid.Model.Configuration;
import org.doubango.imsdroid.Model.HistorySMSEvent;
import org.doubango.imsdroid.Model.Configuration.CONFIGURATION_ENTRY;
import org.doubango.imsdroid.Model.Configuration.CONFIGURATION_SECTION;
import org.doubango.imsdroid.Model.HistoryEvent.StatusType;
import org.doubango.imsdroid.Screens.ScreenAV;
import org.doubango.imsdroid.Screens.ScreenMsrpInc;
import org.doubango.imsdroid.Services.IConfigurationService;
import org.doubango.imsdroid.Services.INetworkService;
import org.doubango.imsdroid.Services.ISipService;
import org.doubango.imsdroid.events.EventHandler;
import org.doubango.imsdroid.events.IInviteEventHandler;
import org.doubango.imsdroid.events.IRegistrationEventHandler;
import org.doubango.imsdroid.events.ISubscriptionEventHandler;
import org.doubango.imsdroid.events.InviteEventArgs;
import org.doubango.imsdroid.events.InviteEventTypes;
import org.doubango.imsdroid.events.RegistrationEventArgs;
import org.doubango.imsdroid.events.RegistrationEventTypes;
import org.doubango.imsdroid.events.SubscriptionEventArgs;
import org.doubango.imsdroid.events.SubscriptionEventTypes;
import org.doubango.imsdroid.media.MediaType;
import org.doubango.imsdroid.sip.MyAVSession;
import org.doubango.imsdroid.sip.MyInviteSession;
import org.doubango.imsdroid.sip.MyMsrpSession;
import org.doubango.imsdroid.sip.MyPublicationSession;
import org.doubango.imsdroid.sip.MyRegistrationSession;
import org.doubango.imsdroid.sip.MySipStack;
import org.doubango.imsdroid.sip.MySubscriptionSession;
import org.doubango.imsdroid.sip.PresenceStatus;
import org.doubango.imsdroid.sip.MySipStack.STACK_STATE;
import org.doubango.imsdroid.sip.MySubscriptionSession.EVENT_PACKAGE_TYPE;
import org.doubango.imsdroid.utils.ContentType;
import org.doubango.imsdroid.utils.StringUtils;
import org.doubango.imsdroid.utils.UriUtils;
import org.doubango.tinyWRAP.CallSession;
import org.doubango.tinyWRAP.DDebugCallback;
import org.doubango.tinyWRAP.DialogEvent;
import org.doubango.tinyWRAP.InviteEvent;
import org.doubango.tinyWRAP.InviteSession;
import org.doubango.tinyWRAP.MessagingEvent;
import org.doubango.tinyWRAP.MessagingSession;
import org.doubango.tinyWRAP.MsrpSession;
import org.doubango.tinyWRAP.OptionsEvent;
import org.doubango.tinyWRAP.OptionsSession;
import org.doubango.tinyWRAP.PublicationEvent;
import org.doubango.tinyWRAP.RPMessage;
import org.doubango.tinyWRAP.RegistrationEvent;
import org.doubango.tinyWRAP.SMSData;
import org.doubango.tinyWRAP.SMSEncoder;
import org.doubango.tinyWRAP.SipCallback;
import org.doubango.tinyWRAP.SipMessage;
import org.doubango.tinyWRAP.SipSession;
import org.doubango.tinyWRAP.SipStack;
import org.doubango.tinyWRAP.StackEvent;
import org.doubango.tinyWRAP.SubscriptionEvent;
import org.doubango.tinyWRAP.SubscriptionSession;
import org.doubango.tinyWRAP.tinyWRAPConstants;
import org.doubango.tinyWRAP.tsip_invite_event_type_t;
import org.doubango.tinyWRAP.tsip_message_event_type_t;
import org.doubango.tinyWRAP.tsip_options_event_type_t;
import org.doubango.tinyWRAP.tsip_subscribe_event_type_t;
import org.doubango.tinyWRAP.twrap_media_type_t;
import org.doubango.tinyWRAP.twrap_sms_type_t;
import android.content.DialogInterface;
import android.os.ConditionVariable;
import android.util.Log;
import android.widget.Toast;
public class SipService extends Service
implements ISipService, tinyWRAPConstants {
private final static String TAG = SipService.class.getCanonicalName();
// Services
private final IConfigurationService configurationService;
private final INetworkService networkService;
// Event Handlers
private final CopyOnWriteArrayList<IRegistrationEventHandler> registrationEventHandlers;
private final CopyOnWriteArrayList<ISubscriptionEventHandler> subscriptionEventHandlers;
private final CopyOnWriteArrayList<IInviteEventHandler> inviteEventHandlers;
private byte[] reginfo;
private byte[] winfo;
private MySipStack sipStack;
private final MySipCallback sipCallback;
private MyRegistrationSession regSession;
private MySubscriptionSession subReg;
private MySubscriptionSession subWinfo;
private MySubscriptionSession subMwi;
//private MySubscriptionSession subDebug;
private MyPublicationSession pubPres;
private final CopyOnWriteArrayList<MySubscriptionSession> subPres;
private final SipPrefrences preferences;
private final DDebugCallback debugCallback;
private ConditionVariable condHack;
public SipService() {
super();
this.sipCallback = new MySipCallback(this);
// FIXME: to be set to null in the release version
this.debugCallback = new DDebugCallback();
this.registrationEventHandlers = new CopyOnWriteArrayList<IRegistrationEventHandler>();
this.subscriptionEventHandlers = new CopyOnWriteArrayList<ISubscriptionEventHandler>();
this.inviteEventHandlers = new CopyOnWriteArrayList<IInviteEventHandler>();
this.configurationService = ServiceManager.getConfigurationService();
this.networkService = ServiceManager.getNetworkService();
this.subPres = new CopyOnWriteArrayList<MySubscriptionSession>();
this.preferences = new SipPrefrences();
}
public boolean start() {
return true;
}
public boolean stop() {
if(this.sipStack != null && this.sipStack.getState() == STACK_STATE.STARTED){
this.sipStack.stop();
}
return true;
}
public boolean isRegistered() {
if (this.regSession != null) {
return this.regSession.isConnected();
}
return false;
}
public MySipStack getStack(){
return this.sipStack;
}
public byte[] getReginfo(){
return this.reginfo;
}
public byte[] getWinfo(){
return this.winfo;
}
public MySubscriptionSession createPresenceSession(String toUri, EVENT_PACKAGE_TYPE eventPackage){
MySubscriptionSession session = new MySubscriptionSession(this.sipStack, toUri, eventPackage);
this.subPres.add(session);
return session;
}
public void clearPresenceSessions(){
for(MySubscriptionSession session : this.subPres){
if(session.isConnected()){
session.unsubscribe();
}
}
//this.subPres.clear();
}
public void removePresenceSession(MySubscriptionSession session){
if(session.isConnected()){
session.unsubscribe();
}
//this.subPres.remove(session);
}
/* ===================== SIP functions ======================== */
public boolean stopStack(){
if(this.sipStack != null){
return this.sipStack.stop();
}
return true;
}
public boolean register() {
this.preferences.realm = this.configurationService.getString(
CONFIGURATION_SECTION.NETWORK, CONFIGURATION_ENTRY.REALM,
Configuration.DEFAULT_REALM);
this.preferences.impi = this.conf
- 1
- 2
- 3
- 4
前往页