00001
00002
00003
00004
00005
00006
00007 #pragma once
00008
00009 #include <vector>
00010 #include <boost/shared_ptr.hpp>
00011 #include <boost/optional.hpp>
00012
00013 #include <string>
00014 #include <Swiften/JID/JID.h>
00015 #include <Swiften/Elements/Payload.h>
00016 #include <Swiften/Elements/JingleContentPayload.h>
00017
00018 #include <Swiften/Base/Log.h>
00019
00020 namespace Swift {
00021 class JinglePayload : public Payload {
00022 public:
00023 typedef boost::shared_ptr<JinglePayload> ref;
00024 struct Reason : public Payload {
00025 enum Type {
00026 UnknownType,
00027 AlternativeSession,
00028 Busy,
00029 Cancel,
00030 ConnectivityError,
00031 Decline,
00032 Expired,
00033 FailedApplication,
00034 FailedTransport,
00035 GeneralError,
00036 Gone,
00037 IncompatibleParameters,
00038 MediaError,
00039 SecurityError,
00040 Success,
00041 Timeout,
00042 UnsupportedApplications,
00043 UnsupportedTransports
00044 };
00045 Reason() : type(UnknownType), text("") {}
00046 Reason(Type type, const std::string& text = "") : type(type), text(text) {}
00047 ~Reason() {}
00048 Type type;
00049 std::string text;
00050 };
00051
00052 enum Action {
00053 UnknownAction,
00054 ContentAccept,
00055 ContentAdd,
00056 ContentModify,
00057 ContentReject,
00058 ContentRemove,
00059 DescriptionInfo,
00060 SecurityInfo,
00061 SessionAccept,
00062 SessionInfo,
00063 SessionInitiate,
00064 SessionTerminate,
00065 TransportAccept,
00066 TransportInfo,
00067 TransportReject,
00068 TransportReplace
00069 };
00070 JinglePayload() : action(SessionTerminate), sessionID("") {
00071 }
00072
00073 JinglePayload(Action action, const std::string& sessionID) : action(action), sessionID(sessionID) {
00074
00075 }
00076
00077 void setAction(Action action) {
00078 this->action = action;
00079 }
00080
00081 Action getAction() const {
00082 return action;
00083 }
00084
00085 void setInitiator(const JID& initiator) {
00086 this->initiator = initiator;
00087 }
00088
00089 const JID& getInitiator() const {
00090 return initiator;
00091 }
00092
00093 void setResponder(const JID& responder) {
00094 this->responder = responder;
00095 }
00096
00097 const JID& getResponder() const {
00098 return responder;
00099 }
00100
00101 void setSessionID(const std::string& id) {
00102 sessionID = id;
00103 }
00104
00105 const std::string& getSessionID() const {
00106 return sessionID;
00107 }
00108
00109 void addContent(JingleContentPayload::ref content) {
00110 this->payloads.push_back(content);
00111 }
00112
00113 void addPayload(boost::shared_ptr<Payload> payload) {
00114 this->payloads.push_back(payload);
00115 }
00116
00117 const std::vector<JingleContentPayload::ref> getContents() const {
00118 return getPayloads<JingleContentPayload>();
00119 }
00120
00121 const std::vector<boost::shared_ptr<Payload> > getPayloads() const {
00122 return payloads;
00123 }
00124
00125 template<typename T>
00126 const std::vector<boost::shared_ptr<T> > getPayloads() const {
00127 std::vector<boost::shared_ptr<T> > matched_payloads;
00128 for (std::vector<boost::shared_ptr<Payload> >::const_iterator i = payloads.begin(); i != payloads.end(); ++i) {
00129 boost::shared_ptr<T> result = boost::dynamic_pointer_cast<T>(*i);
00130 if (result) {
00131 matched_payloads.push_back(result);
00132 }
00133 }
00134
00135 return matched_payloads;
00136
00137 }
00138
00139 template<typename T>
00140 const boost::shared_ptr<T> getPayload() const {
00141 boost::shared_ptr<T> result;
00142 for (std::vector<boost::shared_ptr<Payload> >::const_iterator i = payloads.begin(); i != payloads.end(); ++i) {
00143 result = boost::dynamic_pointer_cast<T>(*i);
00144 if (result) {
00145 return result;
00146 }
00147 }
00148
00149 return result;
00150 }
00151
00152 void setReason(const Reason& reason) {
00153 this->reason = reason;
00154 }
00155
00156 const boost::optional<Reason>& getReason() const {
00157 return reason;
00158 }
00159
00160 private:
00161 Action action;
00162 JID initiator;
00163 JID responder;
00164 std::string sessionID;
00165 std::vector<boost::shared_ptr<Payload> > payloads;
00166 boost::optional<Reason> reason;
00167 };
00168 }