[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Aug 20 15:38:28 CDT 2010


branch "master" has been updated
       via  fbc6f99656df255bb4f497e7697abffb1b406af3 (commit)
      from  a21c5d84e24269377087dd322a0a9bdca90780a8 (commit)

Summary of changes:
 src/PJSipManager.cpp |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/PJSipManager.h   |   51 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 118 insertions(+), 0 deletions(-)
 create mode 100644 src/PJSipManager.cpp
 create mode 100644 src/PJSipManager.h


- Log -----------------------------------------------------------------
commit fbc6f99656df255bb4f497e7697abffb1b406af3
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Aug 20 15:36:37 2010 -0500

    Add PJSipManager initial stuff.
    
    The PJSipManager is created when the SIP application starts
    up. Its main responsibility is in initializing PJSIP, creating
    the pjsip_endpoint that will be used for SIP communication, and
    providing a way for pjsip_modules to access the pjsip_endpoint
    as needed.
    
    It also creates the thread that will be used to service the
    pjsip_endpoint's timer. pjsip_module callbacks will be called
    from this thread.

diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
new file mode 100644
index 0000000..1eb86b5
--- /dev/null
+++ b/src/PJSipManager.cpp
@@ -0,0 +1,67 @@
+#include "PJSipManager.h"
+
+PJSipManager *PJSipManager::mInstance = NULL;
+
+static void *monitorThread(pjsip_uint32_t ignore)
+{
+	//Fill this in later
+}
+
+PJSipManager *PJSipManager::getInstance()
+{
+	if (mInstance == NULL)
+	{
+		mInstance = new PJSipManager;
+	}
+	return mInstance;
+}
+
+PJSipManager::PJSipManager()
+{
+	pj_status_t status = pj_init();
+	if (status != PJ_SUCCESS)
+	{
+		std::cerr << "[ERROR] Failed to Initialize PJSIP" << std::endl;
+	}
+	// The third parameter is just copied from
+	// example code from PJLIB. This can be adjusted
+	// if necessary.
+	pj_caching_pool_init(&mCachingPool, NULL, 1024 * 1024);
+	pjsip_endpt_create(&mCachingPool.factory, "SIP", &mEndpoint);
+	mMemoryPool = pj_pool_create(&mCachingPool.factory, "SIP", 1024, 1024, NULL);
+	if (!mMemoryPool)
+	{
+		std::cerr << "Oh crap again!\n" << std::endl;
+	}
+	status = pj_thread_create(mMemoryPool, "SIP", (pj_thread_proc *) &monitorThread,
+			NULL, PJ_THREAD_DEFAULT_STACK_SIZE, 0, &mPjThread);
+	if (status != PJ_SUCCESS)
+	{
+		std::cerr << "And again, oh crap!" << std::endl;
+	}
+}
+
+pjsip_endpt *PJSipManager::getEndpoint()
+{
+	return mEndpoint;
+}
+
+bool PJSipManager::registerModule(pjsip_module *module)
+{
+	pj_status_t status = pjsip_endpt_register_module(mEndpoint, module);
+	if (status != PJ_SUCCESS)
+	{
+		return false;
+	}
+	return true;
+}
+
+bool PJSipManager::unregisterModule(pjsip_module *module)
+{
+	pj_status_t status = pjsip_endpt_unregister_module(mEndpoint, module);
+	if (status != PJ_SUCCESS)
+	{
+		return false;
+	}
+	return true;
+}
diff --git a/src/PJSipManager.h b/src/PJSipManager.h
new file mode 100644
index 0000000..558164e
--- /dev/null
+++ b/src/PJSipManager.h
@@ -0,0 +1,51 @@
+#pragma once
+
+#include <pjlib.h>
+#include <pjsip.h>
+
+#include <boost/shared_ptr.hpp>
+
+/**
+ * This class is responsible for providing
+ * access to the pjsip_endpt for the Asterisk
+ * SCF SIP component.
+ *
+ * In addition, it provides some common functions
+ * that many SIP services will use.
+ */
+class PJSipManager
+{
+public:
+	/**
+	 * Get the singleton PJSipManager instance
+	 */
+	static PJSipManager *getInstance();
+	/**
+	 * Get a handle to the PJSipEndpoint for operations
+	 * that may require it
+	 */
+	pjsip_endpt *getEndpoint();
+	/**
+	 * Register a module with PJsip
+	 * This will result in the module's load and
+	 * start callbacks being called.
+	 * @module The module to register
+	 */
+	bool registerModule(pjsip_module *module);
+	/**
+	 * Unregister a PJSIP module.
+	 * This will result in the module's unload and
+	 * stop callbacks being called.
+	 * @module The module to unregister
+	 */
+	bool unregisterModule(pjsip_module *module);
+protected:
+	PJSipManager();
+private:
+	static Boost::shared_ptr<PJSipManager> mInstance;
+	pjsip_endpoint *mEndpoint;
+	std::vector<pjsip_module *> mModules;
+	pj_thread_t *mPjThread;
+	pj_caching_pool mCachingPool;
+	pj_pool_t *mMemoryPool;
+};

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list