001/** 002 * 003 * Copyright the original author or authors 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.jingleold; 018 019import java.util.logging.Level; 020import java.util.logging.Logger; 021 022import org.jivesoftware.smack.packet.IQ; 023 024import org.jivesoftware.smackx.jingleold.packet.Jingle; 025 026/** 027 * Jingle. 028 * @author Jeff Williams 029 * @see JingleSessionState 030 */ 031@SuppressWarnings("UnusedVariable") 032public class JingleSessionStatePending extends JingleSessionState { 033 private static final Logger LOGGER = Logger.getLogger(JingleSessionStatePending.class.getName()); 034 035 private static JingleSessionStatePending INSTANCE = null; 036 037 protected JingleSessionStatePending() { 038 // Prevent instantiation of the class. 039 } 040 041 /** 042 * A thread-safe means of getting the one instance of this class. 043 * @return The singleton instance of this class. 044 */ 045 public static synchronized JingleSessionState getInstance() { 046 if (INSTANCE == null) { 047 INSTANCE = new JingleSessionStatePending(); 048 } 049 return INSTANCE; 050 } 051 052 @Override 053 public void enter() { 054 // TODO Auto-generated method stub 055 056 } 057 058 @Override 059 public void exit() { 060 // TODO Auto-generated method stub 061 062 } 063 064 @Override 065 public IQ processJingle(JingleSession session, Jingle jingle, JingleActionEnum action) { 066 IQ response = null; 067 068 switch (action) { 069 070 case CONTENT_ACCEPT: 071 response = receiveContentAcceptAction(jingle); 072 break; 073 074 case CONTENT_MODIFY: 075 break; 076 077 case CONTENT_REMOVE: 078 break; 079 080 case SESSION_ACCEPT: 081 response = receiveSessionAcceptAction(session, jingle); 082 break; 083 084 case SESSION_INFO: 085 break; 086 087 case SESSION_TERMINATE: 088 response = receiveSessionTerminateAction(session, jingle); 089 break; 090 091 case TRANSPORT_INFO: 092 break; 093 094 default: 095 // Anything other action is an error. 096 // response = createJingleError(inJingle, JingleError.OUT_OF_ORDER); 097 break; 098 } 099 100 return response; 101 } 102 103 /** 104 * Receive and process the <session-accept> action. 105 */ 106 private static IQ receiveContentAcceptAction(Jingle inJingle) { 107 108 // According to XEP-167 the only thing we can do is ack. 109 // setSessionState(JingleSessionStateEnum.ACTIVE); 110 // return createAck(inJingle); 111 112 // This is now handled by the media negotiator for the matching <content> segment. 113 return null; 114 } 115 116 /** 117 * Receive and process the <session-accept> action. 118 */ 119 private static IQ receiveSessionAcceptAction(JingleSession session, Jingle inJingle) { 120 121 // According to XEP-166 the only thing we can do is ack. 122 session.setSessionState(JingleSessionStateActive.getInstance()); 123 return session.createAck(inJingle); 124 } 125 126 /** 127 * Receive and process the <session-terminate> action. 128 */ 129 private static IQ receiveSessionTerminateAction(JingleSession session, Jingle jingle) { 130 131 // According to XEP-166 the only thing we can do is ack. 132 IQ response = session.createAck(jingle); 133 134 try { 135 session.terminate("Closed remotely"); 136 } catch (Exception e) { 137 LOGGER.log(Level.WARNING, "exception", e); 138 } 139 140 return response; 141 } 142}