reSIProcate/DialogUsageManager  9694
ServerPagerMessage.cxx
Go to the documentation of this file.
00001 #include "resip/stack/SipMessage.hxx"
00002 #include "resip/stack/MethodTypes.hxx"
00003 #include "resip/dum/ServerPagerMessage.hxx"
00004 #include "resip/dum/OutOfDialogHandler.hxx"
00005 #include "resip/dum/DialogUsageManager.hxx"
00006 #include "resip/dum/Dialog.hxx"
00007 #include "resip/dum/PagerMessageHandler.hxx"
00008 #include "rutil/Logger.hxx"
00009 #include "rutil/WinLeakCheck.hxx"
00010 
00011 using namespace resip;
00012 
00013 #define RESIPROCATE_SUBSYSTEM Subsystem::DUM
00014 
00015 ServerPagerMessageHandle 
00016 ServerPagerMessage::getHandle()
00017 {
00018    return ServerPagerMessageHandle(mDum, getBaseHandle().getId());
00019 }
00020 
00021 ServerPagerMessage::ServerPagerMessage(DialogUsageManager& dum,
00022                                        DialogSet& dialogSet,
00023                                        const SipMessage& req) : 
00024    NonDialogUsage(dum, dialogSet),
00025    mRequest(req),
00026    mResponse(new SipMessage)
00027 {
00028 }
00029 
00030 ServerPagerMessage::~ServerPagerMessage()
00031 {
00032    mDialogSet.mServerPagerMessage = 0;
00033 }
00034 
00035 
00036 void
00037 ServerPagerMessage::end()
00038 {
00039    delete this;
00040 }
00041 
00042 class ServerPagerMessageEndCommand : public DumCommandAdapter
00043 {
00044 public:
00045    ServerPagerMessageEndCommand(ServerPagerMessage& serverPagerMessage)
00046       : mServerPagerMessage(serverPagerMessage)
00047    {
00048 
00049    }
00050 
00051    virtual void executeCommand()
00052    {
00053       mServerPagerMessage.end();
00054    }
00055 
00056    virtual EncodeStream& encodeBrief(EncodeStream& strm) const
00057    {
00058       return strm << "ServerPagerMessageEndCommand";
00059    }
00060 private:
00061    ServerPagerMessage& mServerPagerMessage;
00062 };
00063 
00064 void ServerPagerMessage::endCommand()
00065 {
00066    mDum.post(new ServerPagerMessageEndCommand(*this));
00067 }
00068 
00069 void 
00070 ServerPagerMessage::dispatch(const SipMessage& msg)
00071 {
00072         assert(msg.isRequest());
00073     ServerPagerMessageHandler* handler = mDum.mServerPagerMessageHandler;
00074     
00075     //?dcm? check in DialogUsageManager
00076     if (!handler)
00077     {
00078        mDum.makeResponse(*mResponse, msg, 405);
00079        mDum.send(mResponse);
00080        delete this;
00081        return;
00082     }
00083     handler->onMessageArrived(getHandle(), msg);
00084 }
00085 
00086 void
00087 ServerPagerMessage::dispatch(const DumTimeout& msg)
00088 {
00089 }
00090 
00091 void 
00092 ServerPagerMessage::send(SharedPtr<SipMessage> response)
00093 {
00094    assert(response->isResponse());
00095    mDum.send(response);
00096    delete this;
00097 }
00098 
00099 SharedPtr<SipMessage>
00100 ServerPagerMessage::accept(int statusCode)
00101 {   
00103    mDum.makeResponse(*mResponse, mRequest, statusCode);
00104    mResponse->remove(h_Contacts);   
00105    return mResponse;
00106 }
00107 
00108 class ServerPagerMessageAcceptCommand : public DumCommandAdapter
00109 {
00110 public:
00111    ServerPagerMessageAcceptCommand(ServerPagerMessage& serverPagerMessage, int statusCode)
00112       : mServerPagerMessage(serverPagerMessage),
00113         mStatusCode(statusCode)
00114    {
00115    }
00116 
00117    virtual void executeCommand()
00118    {
00119       mServerPagerMessage.accept(mStatusCode);
00120    }
00121 
00122    virtual EncodeStream& encodeBrief(EncodeStream& strm) const
00123    {
00124       return strm << "ServerPagerMessageAcceptCommand";
00125    }
00126 private:
00127    ServerPagerMessage& mServerPagerMessage;
00128    int mStatusCode;
00129 };
00130 
00131 void
00132 ServerPagerMessage::acceptCommand(int statusCode)
00133 {   
00134    mDum.post(new ServerPagerMessageAcceptCommand(*this, statusCode));
00135 }
00136 
00137 SharedPtr<SipMessage>
00138 ServerPagerMessage::reject(int statusCode)
00139 {
00141    mDum.makeResponse(*mResponse, mRequest, statusCode);
00142    return mResponse;
00143 }
00144 
00145 class ServerPagerMessageRejectCommand : public DumCommandAdapter
00146 {
00147 public:
00148    ServerPagerMessageRejectCommand(ServerPagerMessage& serverPagerMessage, int statusCode)
00149       : mServerPagerMessage(serverPagerMessage),
00150         mStatusCode(statusCode)
00151    {
00152    }
00153 
00154    virtual void executeCommand()
00155    {
00156       mServerPagerMessage.reject(mStatusCode);
00157    }
00158 
00159    virtual EncodeStream& encodeBrief(EncodeStream& strm) const
00160    {
00161       return strm << "ServerPagerMessageRejectCommand";
00162    }
00163 private:
00164    ServerPagerMessage& mServerPagerMessage;
00165    int mStatusCode;
00166 };
00167 
00168 void
00169 ServerPagerMessage::rejectCommand(int statusCode)
00170 {
00171    mDum.post(new ServerPagerMessageRejectCommand(*this, statusCode));
00172 }
00173 
00174 EncodeStream& 
00175 ServerPagerMessage::dump(EncodeStream& strm) const
00176 {
00177    strm << "ServerPagerMessage ";
00178    mRequest.encodeBrief(strm);
00179    return strm;
00180 }
00181 
00182 
00183 
00184 /* ====================================================================
00185  * The Vovida Software License, Version 1.0 
00186  * 
00187  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00188  * 
00189  * Redistribution and use in source and binary forms, with or without
00190  * modification, are permitted provided that the following conditions
00191  * are met:
00192  * 
00193  * 1. Redistributions of source code must retain the above copyright
00194  *    notice, this list of conditions and the following disclaimer.
00195  * 
00196  * 2. Redistributions in binary form must reproduce the above copyright
00197  *    notice, this list of conditions and the following disclaimer in
00198  *    the documentation and/or other materials provided with the
00199 
00200  *    distribution.
00201  * 
00202  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00203  *    and "Vovida Open Communication Application Library (VOCAL)" must
00204  *    not be used to endorse or promote products derived from this
00205  *    software without prior written permission. For written
00206  *    permission, please contact vocal@vovida.org.
00207  *
00208  * 4. Products derived from this software may not be called "VOCAL", nor
00209  *    may "VOCAL" appear in their name, without prior written
00210  *    permission of Vovida Networks, Inc.
00211  * 
00212  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00213  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00214  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00215  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00216  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00217  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00218  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00219  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00220  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00221  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00222  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00223  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00224  * DAMAGE.
00225  * 
00226  * ====================================================================
00227  * 
00228  * This software consists of voluntary contributions made by Vovida
00229  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00230  * Inc.  For more information on Vovida Networks, Inc., please see
00231  * <http://www.vovida.org/>.
00232  *
00233  */