Gnash  0.8.10
NetConnection_as.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00003 //   Free Software Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef GNASH_NETCONNECTION_H
00020 #define GNASH_NETCONNECTION_H
00021 
00022 
00023 #include <vector>
00024 #include <string>
00025 #include <list>
00026 #include <memory>
00027 #include <boost/shared_ptr.hpp>
00028 
00029 #include "Relay.h"
00030 
00031 // Forward declarations
00032 namespace gnash {
00033     class Connection;
00034     class as_object;
00035     class as_value;
00036     class IOChannel;
00037     struct ObjectURI;
00038 }
00039 
00040 namespace gnash {
00041 
00043 //
00046 class NetConnection_as : public ActiveRelay
00047 {
00048 public:
00049 
00050     enum StatusCode
00051     {
00052         CONNECT_FAILED,
00053         CONNECT_SUCCESS,
00054         CONNECT_CLOSED,
00055         CONNECT_REJECTED,
00056         CONNECT_APPSHUTDOWN,
00057         CALL_FAILED,
00058         CALL_BADVERSION
00059     };
00060 
00061     NetConnection_as(as_object* owner);
00062 
00063     virtual ~NetConnection_as();
00064 
00066     virtual void update();
00067 
00069         std::string validateURL() const;
00070 
00071     void call(as_object* asCallback, const std::string& methodName,
00072             const std::vector<as_value>& args);
00073 
00075     void close();
00076 
00078     //
00081     bool connect(const std::string& uri);
00082 
00084     //
00087     void connect();
00088 
00089     void setConnected() {
00090         _isConnected = true;
00091     }
00092 
00093     bool isConnected() const {
00094         return _isConnected;
00095     }
00096 
00097     void setURI(const std::string& uri);
00098 
00099     const std::string& getURI() const {
00100         return _uri;
00101     }
00102 
00104     void notifyStatus(StatusCode code);
00105 
00107     std::auto_ptr<IOChannel> getStream(const std::string& name);
00108 
00110     void markReachableResources() const;
00111 
00112 private:
00113 
00115     void addToURL(const std::string& url);
00116 
00117     typedef std::list<boost::shared_ptr<Connection> > Connections;
00118 
00120     //
00125     Connections _oldConnections;
00126 
00128     std::auto_ptr<Connection> _currentConnection; 
00129 
00131     std::string _uri;
00132 
00133     bool _isConnected;
00134 
00135     void startAdvanceTimer();
00136 
00137     void stopAdvanceTimer();
00138 };
00139 
00140 void netconnection_class_init(as_object& global, const ObjectURI& uri);
00141 
00142 } // end of gnash namespace
00143 
00144 #endif
00145 
00146 // local Variables:
00147 // mode: C++
00148 // indent-tabs-mode: nil
00149 // End: