Commits

Ivan Vučica committed 8e36929

Added libjingle-test to xcodeproj. Extracted from cricket::Session and cricket::SessionManager the minimum amount of code that seems obvious to be necessary for a working implementation of our own Session and SessionManager. Figured out we need to disable RTTI to be able to subclass BaseSession.

Comments (0)

Files changed (3)

 
 CXXFLAGS+=-DPOSIX=1
 
+CXXFLAGS+=-g3 -O0
+LDFLAGS+=-g3 -O0
+
+CXXFLAGS+=-fno-rtti # libjingle is compiled without rtti, and subclassing a virtual class (such as BaseSession) requires that our code is also rtti-less
+
 #CXXFLAGS+=-I/Users/ivucica/projects/THIRDPARTY # for 0.3.0 sample
 CXXFLAGS+=-I/Users/ivucica/projects/THIRDPARTY/libjingle
 LDFLAGS+=-L/Users/ivucica/projects/THIRDPARTY/libjingle/talk/build/dbg/lib
 LDFLAGS+=-arch i386
 LDFLAGS+=-framework CoreFoundation -framework CoreServices
 LDFLAGS+=-framework Security -framework SystemConfiguration -lssl -lcrypto -framework Carbon # something in p2p pulled these in! TODO check what
+LDFLAGS+=-lexpat # SessionDescription, referenced by BaseSession, pulled this in
 # end Mac OS X
 
-
 all: libjingle-test libjingle-p2ponly
 
 libjingle-test: libjingle-test.o
 	g++ libjingle-test.o -o libjingle-test -ljingle -lsrtp -lexpat $(LDFLAGS)
 
 libjingle-p2ponly: libjingle-p2ponly.o
-	g++ libjingle-p2ponly.o -o libjingle-p2ponly -ljingle $(LDFLAGS)
+	g++ libjingle-p2ponly.o -o libjingle-p2ponly  -ljingle $(LDFLAGS)
 
 clean:
 	-rm -f *.o

libjingle-p2ponly.cpp

 #include <talk/base/network.h> // talk_base::NetworkManager 
 #include <talk/p2p/base/session.h>
 #include <talk/p2p/base/sessionmanager.h>
+#include <talk/base/helpers.h> // talk_base::CreateRandomId
+
 
 cricket::P2PTransportChannel *p2pTransportChannel;
 cricket::HttpPortAllocator *httpPortAllocator;
 cricket::P2PTransport *p2pTransport;
 talk_base::NetworkManager *networkManager;
-cricket::SessionManager *sessionManager;
+//cricket::SessionManager *sessionManager;
+
+class libjinglep2ponlySessionManager;
 
 class libjinglep2ponlySession : public cricket::BaseSession
 {
+	virtual cricket::TransportChannel *CreateChannel(
+                                             const std::string& content_name,
+                                             const std::string& channel_name)
+	{
+		printf("%s: %s %s\n", __PRETTY_FUNCTION__, content_name.c_str(), channel_name.c_str());
+        
+        return NULL;
+	}
+    
+	virtual cricket::TransportChannel *GetChannel(
+                                          const std::string& content_name,
+                                          const std::string& channel_name)
+	{
+		printf("%s: %s %s\n", __PRETTY_FUNCTION__, content_name.c_str(), channel_name.c_str());
+        return NULL;
+	}
+	virtual void DestroyChannel(
+                        const std::string& content_name,
+                        const std::string& channel_name)
+	{
+		printf("%s: %s %s\n", __PRETTY_FUNCTION__, content_name.c_str(), channel_name.c_str());
+	}
+    
+	virtual bool Accept(const cricket::SessionDescription* sdesc)
+	{
+		printf("%s\n", __PRETTY_FUNCTION__);
+        return false;
+	}
+	virtual bool Reject(const std::string& reason)
+	{
+		printf("%s: %s\n", __PRETTY_FUNCTION__, reason.c_str());
+        return false;
+	}
+	virtual bool TerminateWithReason(const std::string& reason)
+	{
+		printf("%s: %s\n", __PRETTY_FUNCTION__, reason.c_str());
+        return false;
+	}
+	virtual talk_base::Thread* worker_thread()
+	{
+		// TODO
+		return NULL;
+	}
+private:
+    libjinglep2ponlySession(libjinglep2ponlySessionManager *session_manager,
+            const std::string& local_name, const std::string& initiator_name,
+            const std::string& sid, const std::string& content_type
+            /*,
+            SessionClient* client
+             */
+            );
+    // implemented below session manager, since we need to use a
+    // method from session manager to pass stuff to constructor
+    friend class libjinglep2ponlySessionManager;
 
+    libjinglep2ponlySessionManager* session_manager_;
+    std::string initiator_name_;
+    std::string content_type_;
+    std::string transport_type_;
+    //cricket::TransportParser *transport_parser_;
+    bool initiator_;
+    std::string current_protocol_;
 };
 
 class libjinglep2ponlySessionManager 
 //
 // plus, our signaling differs!
 //: public cricket::SessionManager
+
+: public sigslot::has_slots<>
+
 {
+public:
+    libjinglep2ponlySessionManager(cricket::PortAllocator *allocator,
+                                   talk_base::Thread *worker_thread = NULL)
+    {
+        // c/p: sessionmanager
+        allocator_ = allocator;
+        signaling_thread_ = talk_base::Thread::Current();
+        if (worker_thread == NULL) {
+            worker_thread_ = talk_base::Thread::Current();
+        } else {
+            worker_thread_ = worker_thread;
+        }
+        timeout_ = 50;
+    }
+    virtual ~libjinglep2ponlySessionManager()
+    {
+        // c/p: sessionmanager
+        // Note: Session::Terminate occurs asynchronously, so it's too late to
+        // delete them now.  They better be all gone.
+        ASSERT(session_map_.empty());
+        // TerminateAll();
+        SignalDestroyed();
+    }
+    
+    cricket::PortAllocator *port_allocator() const { return allocator_; }
+    talk_base::Thread *worker_thread() const { return worker_thread_; }
+    talk_base::Thread *signaling_thread() const { return signaling_thread_; }
+    
+    int session_timeout() const { return timeout_; }
+    void set_session_timeout(int timeout) { timeout_ = timeout; }
+    
+    // Registers support for the given client.  If we receive an initiate
+    // describing a session of the given type, we will automatically create a
+    // Session object and notify this client.  The client may then accept or
+    // reject the session.
+    /*
+     // ivucica (2011-05-13): we shouldn't be needing clients
+     
+     void AddClient(const std::string& content_type, cricket::SessionClient* client);
+     void RemoveClient(const std::string& content_type);
+     cricket::SessionClient* GetClient(const std::string& content_type);
+     */
+    
+    // Creates a new session.  The given name is the JID of the client on whose
+    // behalf we initiate the session.
+    libjinglep2ponlySession *CreateSession(const std::string& local_name,
+                                           const std::string& content_type)
+    {
+        // c/p: sessionmanager
+        return CreateSession(local_name, local_name,
+                             talk_base::ToString(talk_base::CreateRandomId()),
+                             content_type, false);
+    }
+    
+    // Destroys the given session.
+    void DestroySession(libjinglep2ponlySession *session)
+    {
+        // c/p: sessionmanager
+        if (session != NULL) {
+            SessionMap::iterator it = session_map_.find(session->id());
+            if (it != session_map_.end()) {
+                SignalSessionDestroy(session);
+                //session->client()->OnSessionDestroy(session);
+                session_map_.erase(it);
+                delete session;
+            }
+        }
+        
+    }
+    
+    // Returns the session with the given ID or NULL if none exists.
+    libjinglep2ponlySession *GetSession(const std::string& sid)
+    {
+        // c/p: sessionmanager
+        SessionMap::iterator it = session_map_.find(sid);
+        if (it != session_map_.end())
+            return it->second;
+        return NULL;
+    }
+    
+    // Terminates all of the sessions created by this manager.
+    void TerminateAll()
+    {
+        // c/p: sessionmanager:
+        while (session_map_.begin() != session_map_.end()) {
+            libjinglep2ponlySession* session = session_map_.begin()->second;
+            session->Terminate();
+        }
+    }
+    
+    // These are signaled whenever the set of existing sessions changes.
+    sigslot::signal2<libjinglep2ponlySession *, bool> SignalSessionCreate;
+    sigslot::signal1<libjinglep2ponlySession *> SignalSessionDestroy;
+    
+    // Given a sid, initiator, and remote_name, this finds the matching Session
+    libjinglep2ponlySession* FindSession(const std::string& sid,
+                                         const std::string& remote_name)
+    {
+        SessionMap::iterator iter = session_map_.find(sid);
+        if (iter == session_map_.end())
+            return NULL;
+        
+        libjinglep2ponlySession* session = iter->second;
+        if (buzz::Jid(remote_name) != buzz::Jid(session->remote_name()))
+            return NULL;
+        
+        return session;
+        
+    }
+    ///////// TODO some xmpp-specific stuff here
+    
+    
+    // Signaled when this SessionManager is deleted.
+    sigslot::signal0<> SignalDestroyed;
+    
+private:
+    typedef std::map<std::string, libjinglep2ponlySession*> SessionMap;
+    //  typedef std::map<std::string, SessionClient*> ClientMap;
+    
+    cricket::PortAllocator *allocator_;
+    talk_base::Thread *signaling_thread_;
+    talk_base::Thread *worker_thread_;
+    int timeout_;
+    SessionMap session_map_;
+    //ClientMap client_map_;
+    
+    // Helper function for CreateSession.  This is also invoked when we receive
+    // a message attempting to initiate a session with this client.
+    libjinglep2ponlySession *CreateSession(const std::string& local_name,
+                                           const std::string& initiator,
+                                           const std::string& sid,
+                                           const std::string& content_type,
+                                           bool received_initiate)
+    {
+        // c/p: sessionmanager
+        //SessionClient* client = GetClient(content_type);
+        //ASSERT(client != NULL);
+        
+        libjinglep2ponlySession* session = new libjinglep2ponlySession(this, 
+                                                                       local_name,
+                                                                       initiator,
+                                                                       sid, 
+                                                                       content_type/*, 
+                                                                       client
+                                                                        */
+                                                                       );
+        session_map_[session->id()] = session;
+        /*
+        session->SignalRequestSignaling.connect(
+                                                this, &SessionManager::OnRequestSignaling);
+        session->SignalOutgoingMessage.connect(
+                                               this, &SessionManager::OnOutgoingMessage);
+        session->SignalErrorMessage.connect(this, &SessionManager::OnErrorMessage);
+         */
+        SignalSessionCreate(session, received_initiate);
+        /*
+        session->client()->OnSessionCreate(session, received_initiate);
+         */
+        return session;
+
+    }
+    
+    // Attempts to find a registered session type whose description appears as
+    // a child of the session element.  Such a child should be present indicating
+    // the application they hope to initiate.
+    //std::string FindClient(const buzz::XmlElement* session);
+    
+    // Sends a message back to the other client indicating that we found an error
+    // in the stanza they sent.  name identifies the error, type is one of the
+    // standard XMPP types (cancel, continue, modify, auth, wait), and text is a
+    // description for debugging purposes.
+    /*
+     void SendErrorMessage(const buzz::XmlElement* stanza,
+                           const buzz::QName& name,
+                           const std::string& type,
+                           const std::string& text,
+                           const buzz::XmlElement* extra_info);
+     */
+    // Creates and returns an error message from the given components.  The
+    // caller is responsible for deleting this.
+    /*
+     buzz::XmlElement* CreateErrorMessage(
+                                          const buzz::XmlElement* stanza,
+                                          const buzz::QName& name,
+                                          const std::string& type,
+                                          const std::string& text,
+                                          const buzz::XmlElement* extra_info);
+     */
+    // Called each time a session requests signaling.
+    void OnRequestSignaling(libjinglep2ponlySession* session);
+    
+    // Called each time a session has an outgoing message.
+    //  void OnOutgoingMessage(libjinglep2ponlySession* session, const buzz::XmlElement* stanza);
+    
+    // Called each time a session has an error to send.
+    /*  void OnErrorMessage(BaseSession* session,
+                            const buzz::XmlElement* stanza,
+                            const buzz::QName& name,
+                            const std::string& type,
+                            const std::string& text,
+                            const buzz::XmlElement* extra_info);
+     */
 };
 
+libjinglep2ponlySession::libjinglep2ponlySession(libjinglep2ponlySessionManager *session_manager,
+                        const std::string& local_name, const std::string& initiator_name,
+                        const std::string& sid, const std::string& content_type
+                        /*,
+                         SessionClient* client
+                         */
+                        ) : cricket::BaseSession(session_manager->signaling_thread())
+{
+    ASSERT(session_manager->signaling_thread()->IsCurrent());
+    ASSERT(client != NULL);
+    session_manager_ = session_manager;
+    local_name_ = local_name;
+    sid_ = sid;
+    initiator_name_ = initiator_name;
+    content_type_ = content_type;
+    // TODO: Once we support different transport types,
+    // don't hard code this here.
+    transport_type_ = cricket::NS_GINGLE_P2P;
+    //transport_parser_ = new P2PTransportParser();
+    //client_ = client;
+    error_ = ERROR_NONE;
+    state_ = STATE_INIT;
+    initiator_ = false;
+    current_protocol_ = cricket::PROTOCOL_HYBRID;
+
+}
+
+
+
+
+libjinglep2ponlySessionManager *sessionManager = NULL;
+
 int main()
 {
     networkManager = new talk_base::NetworkManager();
     httpPortAllocator = new cricket::HttpPortAllocator(networkManager, USER_AGENT);
-    p2pTransportChannel = new cricket::P2PTransportChannel("Kanal", "sadrzaj", p2pTransport, httpPortAllocator);
-    //sessionManager = new cricket::libjinglep2ponlySessionManager(httpPortAllocator);
+    //p2pTransportChannel = new cricket::P2PTransportChannel("Kanal", "sadrzaj", p2pTransport, httpPortAllocator);
+    sessionManager = new libjinglep2ponlySessionManager(httpPortAllocator);
     
+    sessionManager->CreateSession("Local Session Name", "test-type");
 	return 0;
 }

libjingle-test.xcodeproj/project.pbxproj

 
 /* Begin PBXBuildFile section */
 		7F2D80A41378759400DDF742 /* libjingle-p2ponly.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7F2D80A31378759400DDF742 /* libjingle-p2ponly.cpp */; };
+		7FDBF613137FFF05002A9AF9 /* libjingle-test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7FDBF612137FFF05002A9AF9 /* libjingle-test.cpp */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXCopyFilesBuildPhase section */
 			);
 			runOnlyForDeploymentPostprocessing = 1;
 		};
+		7FDBF60B137FFEB2002A9AF9 /* CopyFiles */ = {
+			isa = PBXCopyFilesBuildPhase;
+			buildActionMask = 2147483647;
+			dstPath = /usr/share/man/man1/;
+			dstSubfolderSpec = 0;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 1;
+		};
 /* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
 		7F2D808E1378752500DDF742 /* libjingle-p2ponly */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "libjingle-p2ponly"; sourceTree = BUILT_PRODUCTS_DIR; };
 		7F2D80A31378759400DDF742 /* libjingle-p2ponly.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "libjingle-p2ponly.cpp"; sourceTree = "<group>"; };
+		7FDBF60F137FFEB2002A9AF9 /* libjingle-test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "libjingle-test"; sourceTree = BUILT_PRODUCTS_DIR; };
+		7FDBF612137FFF05002A9AF9 /* libjingle-test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "libjingle-test.cpp"; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
+		7FDBF60A137FFEB2002A9AF9 /* Frameworks */ = {
+			isa = PBXFrameworksBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 /* End PBXFrameworksBuildPhase section */
 
 /* Begin PBXGroup section */
 		7F2D80831378752500DDF742 = {
 			isa = PBXGroup;
 			children = (
+				7FDBF612137FFF05002A9AF9 /* libjingle-test.cpp */,
 				7F2D80A31378759400DDF742 /* libjingle-p2ponly.cpp */,
 				7F2D808F1378752500DDF742 /* Products */,
 			);
 			isa = PBXGroup;
 			children = (
 				7F2D808E1378752500DDF742 /* libjingle-p2ponly */,
+				7FDBF60F137FFEB2002A9AF9 /* libjingle-test */,
 			);
 			name = Products;
 			sourceTree = "<group>";
 			productReference = 7F2D808E1378752500DDF742 /* libjingle-p2ponly */;
 			productType = "com.apple.product-type.tool";
 		};
+		7FDBF607137FFEB2002A9AF9 /* libjingle-test */ = {
+			isa = PBXNativeTarget;
+			buildConfigurationList = 7FDBF60C137FFEB2002A9AF9 /* Build configuration list for PBXNativeTarget "libjingle-test" */;
+			buildPhases = (
+				7FDBF608137FFEB2002A9AF9 /* Sources */,
+				7FDBF60A137FFEB2002A9AF9 /* Frameworks */,
+				7FDBF60B137FFEB2002A9AF9 /* CopyFiles */,
+			);
+			buildRules = (
+			);
+			dependencies = (
+			);
+			name = "libjingle-test";
+			productName = "libjingle-p2ponly";
+			productReference = 7FDBF60F137FFEB2002A9AF9 /* libjingle-test */;
+			productType = "com.apple.product-type.tool";
+		};
 /* End PBXNativeTarget section */
 
 /* Begin PBXProject section */
 			projectRoot = "";
 			targets = (
 				7F2D808D1378752500DDF742 /* libjingle-p2ponly */,
+				7FDBF607137FFEB2002A9AF9 /* libjingle-test */,
 			);
 		};
 /* End PBXProject section */
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
+		7FDBF608137FFEB2002A9AF9 /* Sources */ = {
+			isa = PBXSourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				7FDBF613137FFF05002A9AF9 /* libjingle-test.cpp in Sources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 /* End PBXSourcesBuildPhase section */
 
 /* Begin XCBuildConfiguration section */
 				ALWAYS_SEARCH_USER_PATHS = NO;
 				COPY_PHASE_STRIP = NO;
 				GCC_DYNAMIC_NO_PIC = NO;
+				GCC_ENABLE_CPP_RTTI = NO;
 				GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+				OTHER_LDFLAGS = (
+					"$(inherited)",
+					"-lexpat",
+				);
 				PRODUCT_NAME = "$(TARGET_NAME)";
 			};
 			name = Debug;
 				ALWAYS_SEARCH_USER_PATHS = NO;
 				COPY_PHASE_STRIP = YES;
 				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+				GCC_ENABLE_CPP_RTTI = NO;
 				GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+				OTHER_LDFLAGS = (
+					"$(inherited)",
+					"-lexpat",
+				);
 				PRODUCT_NAME = "$(TARGET_NAME)";
 			};
 			name = Release;
 		};
+		7FDBF60D137FFEB2002A9AF9 /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				COPY_PHASE_STRIP = NO;
+				GCC_DYNAMIC_NO_PIC = NO;
+				GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+				OTHER_LDFLAGS = (
+					"$(inherited)",
+					"-lexpat",
+				);
+				PRODUCT_NAME = "libjingle-test";
+			};
+			name = Debug;
+		};
+		7FDBF60E137FFEB2002A9AF9 /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				COPY_PHASE_STRIP = YES;
+				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+				GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+				OTHER_LDFLAGS = (
+					"$(inherited)",
+					"-lexpat",
+				);
+				PRODUCT_NAME = "libjingle-test";
+			};
+			name = Release;
+		};
 /* End XCBuildConfiguration section */
 
 /* Begin XCConfigurationList section */
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;
 		};
+		7FDBF60C137FFEB2002A9AF9 /* Build configuration list for PBXNativeTarget "libjingle-test" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				7FDBF60D137FFEB2002A9AF9 /* Debug */,
+				7FDBF60E137FFEB2002A9AF9 /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
 /* End XCConfigurationList section */
 	};
 	rootObject = 7F2D80851378752500DDF742 /* Project object */;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.