/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sip.RequestEvent;
import javax.sip.header.CSeqHeader;
import javax.sip.header.CallIdHeader;
import javax.sip.header.ContactHeader;
import javax.sip.header.FromHeader;
import javax.sip.header.HeaderFactory;
import javax.sip.header.ToHeader;
import javax.sip.header.ViaHeader;
import javax.sip.message.MessageFactory;
import javax.sip.message.Response;
import logger.OhmLogger;
/**
 * Erstellt den Ringing Header, wird als zweites gesendet sobald man einen Anruf bekommt
 * Wiederholen bis User das Telefon abnimmt oder nichtmehr angerufen wird
 * 
 * @author Jan
 */
public class SIP180Ringing
{
  private Response responseRing;
  public static final Logger lgRing = OhmLogger.getLogger();
  //private SubmissionPublisher<Integer> publisherZahl;

  public SIP180Ringing(RequestEvent requestEvent, String myTag, ContactHeader contact, 
                       HeaderFactory headerFactory, MessageFactory messageFactory)
  {
    try
    {
      responseRing = messageFactory.createResponse(180, requestEvent.getRequest());
      responseRing.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via"));
      responseRing.addHeader((FromHeader) requestEvent.getRequest().getHeader("From"));
      //persönlichen Tag muss beim To-Header ergänzt werden
      ToHeader tempTo = ((ToHeader) requestEvent.getRequest().getHeader("To")); 
      tempTo.setTag(myTag);
      responseRing.addHeader(tempTo);
      responseRing.addHeader((CallIdHeader) requestEvent.getRequest().getHeader("Call-ID"));
      responseRing.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq"));
      responseRing.addHeader(contact);
      responseRing.addHeader(headerFactory.createSupportedHeader("replace,path,timer"));
      responseRing.addHeader(headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE"));
      responseRing.addHeader(headerFactory.createAllowEventsHeader("talk,hold,refer")); //für was wird er gebraucht
      lgRing.info("180-Ringing Header erstellt");
    }
    catch (Exception ex)
    {
      lgRing.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
  /**
   * @return the responseRing
   */
  public Response getResponseRing()
  {
    return responseRing;
  }
}
