Index: pjproject/branches/projects/pjsua2/build.mak.in
===================================================================
--- pjproject/branches/projects/pjsua2/build.mak.in	(revision 4638)
+++ pjproject/branches/projects/pjsua2/build.mak.in	(revision 4639)
@@ -130,5 +130,5 @@
 # variables. it will also require -lstdc++
 #  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x
-export APP_LDLIBS := \ 
+export APP_LDLIBS := \
 	-lpjsua2-$(TARGET_NAME)\
 	-lpjsua-$(TARGET_NAME)\
@@ -154,5 +154,5 @@
 # variables. it will also require -lstdc++
 #  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x
-export APP_LIB_FILES = \ 
+export APP_LIB_FILES = \
 	$(PJ_DIR)/pjsip/lib/libpjsua2-$(LIB_SUFFIX) \
 	$(PJ_DIR)/pjsip/lib/libpjsua-$(LIB_SUFFIX) \
Index: pjproject/branches/projects/pjsua2/pjlib/include/pj/types.h
===================================================================
--- pjproject/branches/projects/pjsua2/pjlib/include/pj/types.h	(revision 4638)
+++ pjproject/branches/projects/pjsua2/pjlib/include/pj/types.h	(revision 4639)
@@ -87,13 +87,16 @@
 #endif
 
-
-/** Status is OK. */
-#define PJ_SUCCESS  0
-
-/** True value. */
-#define PJ_TRUE	    1
-
-/** False value. */
-#define PJ_FALSE    0
+/** Some constants */
+enum pj_constants_
+{
+    /** Status is OK. */
+    PJ_SUCCESS=0,
+
+    /** True value. */
+    PJ_TRUE=1,
+
+    /** False value. */
+    PJ_FALSE=0
+};
 
 /**
Index: pjproject/branches/projects/pjsua2/pjmedia/include/pjmedia-videodev/videodev.h
===================================================================
--- pjproject/branches/projects/pjsua2/pjmedia/include/pjmedia-videodev/videodev.h	(revision 4638)
+++ pjproject/branches/projects/pjsua2/pjmedia/include/pjmedia-videodev/videodev.h	(revision 4639)
@@ -132,5 +132,5 @@
  * Device index constants.
  */
-enum
+enum pjmedia_vid_dev_std_index
 {
     /**
Index: pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/Makefile
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/Makefile	(revision 4638)
+++ pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/Makefile	(revision 4639)
@@ -9,5 +9,9 @@
 export SRCS=$(SRC_DIR)/pjsua2/endpoint.hpp $(SRC_DIR)/pjsua2/types.hpp
 
-all clean dep depend distclean print realclean:
+.PHONY: all clean dep depend distclean print realclean install uninstall
+
+all: symbols.i
+
+all clean dep depend distclean print realclean install uninstall:
 	for dir in $(DIRS); do \
 		if $(MAKE) $(MAKE_FLAGS) -C $$dir $@; then \
@@ -17,2 +21,5 @@
 		fi; \
 	done
+
+symbols.i: symbols.lst
+	python importsym.py
Index: pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/importsym.py
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/importsym.py	(revision 4639)
+++ pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/importsym.py	(revision 4639)
@@ -0,0 +1,191 @@
+# $Id$
+#
+# importsym.py: Import C symbol decls (structs, enums, etc) and write them
+#               to another file 
+#
+# Copyright (C)2013 Teluu Inc. (http://www.teluu.com)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+#
+import pycparser
+from pycparser import c_generator
+import sys
+import os
+
+def which(program):
+	import os
+	def is_exe(fpath):
+		return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+	
+	fpath, fname = os.path.split(program)
+	if fpath:
+		if is_exe(program):
+			return program
+	else:
+		for path in os.environ["PATH"].split(os.pathsep):
+			path = path.strip('"')
+			exe_file = os.path.join(path, program)
+			if is_exe(exe_file):
+				return exe_file
+	return None
+
+#
+PJ_ROOT_PATH = "../../../"
+   
+# CPP is needed by pycparser.
+CPP_PATH = which("cpp")
+if not CPP_PATH:
+	print 'Error: need to have cpp in PATH'
+	sys.exit(1)
+
+# Hardcoded!
+if sys.platform == 'win32':
+	PYCPARSER_DIR="C:/devs/tools/pycparser"
+elif sys.platform == "linux2":
+	PYCPARSER_DIR="/home/bennylp/Desktop/opt/src/pycparser-master"
+else:
+	PYCPARSER_DIR="/Library/Python/2.7/site-packages/pycparser"
+
+if not os.path.exists(PYCPARSER_DIR + '/utils/fake_libc_include'):
+	print "Error: couldn't find pycparser utils in '%s'" % PYPARSER_DIR 
+	sys.exit(1)
+
+# Heading, to be placed before the source files
+C_HEADING_SECTION = """
+#define PJ_AUTOCONF		1
+#define CC_DUMMY
+#define jmp_buf			int
+#define __attribute__(x)
+"""
+
+# CPP (C preprocessor) settings
+CPP_CFLAGS   = [
+	'-I' + PYCPARSER_DIR + '/utils/fake_libc_include',
+	"-I" + PJ_ROOT_PATH + "pjlib/include",
+	"-I" + PJ_ROOT_PATH + "pjlib-util/include",
+	"-I" + PJ_ROOT_PATH + "pjnath/include",
+	"-I" + PJ_ROOT_PATH + "pjmedia/include",
+	"-I" + PJ_ROOT_PATH + "pjsip/include"
+	]
+
+
+class SymbolVisitor(pycparser.c_ast.NodeVisitor):
+	def __init__(self, names):
+		self.nodeDict = {}
+		for name in names:
+			self.nodeDict[name] = None
+		
+	def _add(self, node):
+		if self.nodeDict.has_key(node.name):
+			self.nodeDict[node.name] = node
+		
+	def visit_Struct(self, node):
+		self._add(node)
+		
+	def visit_Enum(self, node):
+		self._add(node)
+
+	def visit_Typename(self, node):
+		self._add(node)
+		
+	def visit_Typedef(self, node):
+		self._add(node)
+
+		
+TEMP_FILE="tmpsrc.h"
+		
+class SymbolImporter:
+	"""
+	Import C selected declarations from C source file and move it
+	to another file.
+	
+	Parameters:
+	 - listfile	Path of file containing list of C source file
+	                and identifier names to be imported. The format
+	                of the listfile is:
+	                
+	                filename        name1  name2  name3
+	                
+	                for example:
+	                
+	                pj/sock_qos.h	pj_qos_type  pj_qos_flag
+	                pj/types.h	pj_status_t  PJ_SUCCESS
+	"""
+	def __init__(self):
+		pass
+	
+	def process(self, listfile, outfile):
+		
+		# Read listfile
+		f = open(listfile)
+		lines = f.readlines()
+		f.close()
+		
+		# Process each line in list file, while generating the
+		# temporary C file to be processed by pycparser
+		f = open(TEMP_FILE, "w")
+		f.write(C_HEADING_SECTION)
+		names = []
+		fcnt = 0
+		for line in lines:
+			spec = line.split()
+			if len(spec) < 2:
+				continue
+			fcnt += 1
+			f.write("#include <%s>\n" % spec[0])
+			names.extend(spec[1:])
+		f.close()
+		print 'Parsing %d symbols from %d files..' % (len(names), fcnt)
+		
+		# Parse the temporary C file
+		ast = pycparser.parse_file(TEMP_FILE, use_cpp=True, cpp_path=CPP_PATH, cpp_args=CPP_CFLAGS)
+		os.remove(TEMP_FILE)
+		
+		# Filter the declarations that we wanted
+		print 'Filtering..'
+		visitor = SymbolVisitor(names)
+		visitor.visit(ast)
+	
+		# Print symbol declarations to outfile
+		print 'Writing declarations..'
+		f = open(outfile, 'w')
+		f.write("// This file is autogenerated by importsym script, do not modify!\n\n")
+		gen = pycparser.c_generator.CGenerator()
+		for name in names:
+			node = visitor.nodeDict[name]
+			if not node:
+				print "  ** Warning: declaration for '%s' is not found **" % k
+			else:
+				print "  writing '%s'.." % name
+				output = gen.visit(node) + ";\n\n"
+				f.write(output)
+		f.close()
+		print "Done."
+
+
+if __name__ == "__main__":
+	print "Importing symbols: 'symbols.lst' --> 'symbols.i'"
+	si = SymbolImporter()
+	si.process("symbols.lst", "symbols.i")
+	try:
+		os.remove("lextab.py")
+	except OSError:
+		pass
+	try:
+		os.remove("yacctab.py")
+	except OSError:
+		pass
+	
+	
Index: pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/Makefile
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/Makefile	(revision 4638)
+++ pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/Makefile	(revision 4639)
@@ -43,5 +43,5 @@
 MY_LDFLAGS	 = $(PJ_LDFLAGS) -lpjsua2-$(TARGET_NAME) $(PJ_LDLIBS) $(MY_JNI_LDFLAGS) -static-libstdc++
 
-.PHONY: all java
+.PHONY: all java install uninstall
 
 all: $(LIBPJSUA2_SO) java
@@ -53,5 +53,5 @@
 	g++ -c $(OUT_DIR)/pjsua2_wrap.cpp -o $(OUT_DIR)/pjsua2_wrap.o $(MY_CFLAGS) $(MY_LDFLAGS)
 
-$(OUT_DIR)/pjsua2_wrap.cpp: ../pjsua2.i $(SRCS)
+$(OUT_DIR)/pjsua2_wrap.cpp: ../pjsua2.i ../symbols.i $(SRCS)
 	swig $(SWIG_FLAGS) -java  -o $(OUT_DIR)/pjsua2_wrap.cpp ../pjsua2.i
 
@@ -71,2 +71,6 @@
 	@# CLASSPATH and java.library.path env settings
 	$(MY_JAVA) -cp $(OUT_DIR) -Djava.library.path="$(OUT_DIR)" test
+
+install:
+uninstall:
+
Index: pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/pjsua2.i
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/pjsua2.i	(revision 4638)
+++ pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/pjsua2.i	(revision 4639)
@@ -15,4 +15,28 @@
 %}
 
+#ifdef SWIGPYTHON
+  %feature("director:except") {
+    if( $error != NULL ) {
+      PyObject *ptype, *pvalue, *ptraceback;
+      PyErr_Fetch( &ptype, &pvalue, &ptraceback );
+      PyErr_Restore( ptype, pvalue, ptraceback );
+      PyErr_Print();
+      //Py_Exit(1);
+    }
+  }
+#endif
+
+// Constants from PJSIP libraries
+%include "symbols.i"
+
+
+//
+// Classes that can be extended in the target language
+//
+%feature("director") LogWriter;
+%feature("director") Endpoint; 
+%feature("director") Account;
+
+
 //
 // STL stuff.
@@ -21,161 +45,10 @@
 %include "std_vector.i"
 
-namespace std
-{
-	%template(StringVector) std::vector<std::string>;
-	%template(IntVector) std::vector<int>;
-	%template(AuthCredInfoVector) std::vector<AuthCredInfo>;
-	%template(SipMultipartPartVector) std::vector<SipMultipartPart>;
-	%template(SipHeaderVector) std::vector<SipHeader>;
-}
+
+%template(StringVector)			std::vector<std::string>;
+%template(IntVector) 			std::vector<int>;
 
 //
-// Classes that can be extended in the target language
-//
-%feature("director") LogWriter; 
-%feature("director") EpCallback;
-
-//
-// And include supporting constants etc. Here we don't want to export
-// the whole file, so we start with ignoring everything and then enable
-// selected symbols  
-//
-#define PJ_BEGIN_DECL
-#define PJ_END_DECL
-#define PJ_DECL(type)		type
-#define PJ_INLINE(type)		type
-#define PJ_DECL_DATA(type)	extern type
-
-//
-// Start with ignoring everything
-//
-%ignore "";
-
-// Process the files. Keep them sorted.
-
-//
-//
-%rename("%s") pj_file_access;				// Unignore this
-%rename("%s", regexmatch$name="PJ_O_.*") "";		// Unignore this
-%include "pj/file_io.h"
-
-//
-//
-%rename("%s") pj_log_decoration;			// Unignore this
-%rename("%s", regexmatch$name="PJ_LOG_HAS_.*") "";	// Unignore this
-%include "pj/log.h"
-
-//
-//
-%rename("%s") pj_qos_type;				// Unignore this
-%rename("%s", regexmatch$name="PJ_QOS_TYPE_.*") "";	// Unignore this
-%rename("%s") pj_qos_flag;				// Unignore this
-%rename("%s", regexmatch$name="PJ_QOS_PARAM_HAS_.*") "";// Unignore this
-%rename("%s") pj_qos_wmm_prio;				// Unignore this
-%rename("%s", regexmatch$name="PJ_QOS_WMM_PRIO_.*") "";	// Unignore this
-// TODO:
-//  Wish there is a better way to unignore a struct than
-//  listing the fields one by one like below. Using regex
-//  doesn't seem to work?
-%rename("%s") pj_qos_params;				// Unignore this
-%rename("%s") pj_qos_params::flags;			// Unignore this
-%rename("%s") pj_qos_params::dscp_val;			// Unignore this
-%rename("%s") pj_qos_params::so_prio;			// Unignore this
-%rename("%s") pj_qos_params::wmm_prio;			// Unignore this
-%include "pj/sock_qos.h"
-
-//
-//
-%rename("%s") pj_ssl_cipher;				// Unignore this
-%rename("%s", regexmatch$name="PJ_O_.*") "";		// Unignore this
-%include "pj/ssl_sock.h"
-
-//
-//
-%rename("%s") pj_status_t;				// Unignore this
-%rename("%s") PJ_SUCCESS;				// Unignore this
-%include "pj/types.h"
-
-//
-//
-%rename("%s") pj_stun_nat_type;				// Unignore this
-%rename("%s", regexmatch$name="PJ_STUN_NAT_TYPE_.*") "";// Unignore this
-%include "pjnath/nat_detect.h"
-
-//
-//
-%rename("%s") pj_turn_tp_type;				// Unignore this
-%rename("%s", regexmatch$name="PJ_TURN_TP_.*") "";	// Unignore this
-%include "pjnath/turn_session.h"
-
-//
-//
-%rename("%s") pjmedia_vid_stream_rc_method;		// Unignore this
-%rename("%s", regexmatch$name="PJMEDIA_VID_STREAM_RC_.*") "";// Unignore this
-%include "pjmedia/vid_stream.h"
-
-//
-//
-%rename("%s") pjmedia_srtp_use;				// Unignore this
-%rename("%s", regexmatch$name="PJMEDIA_SRTP_.*") "";	// Unignore this
-%include "pjmedia/transport_srtp.h"
-
-//
-//
-%rename("%s") pjmedia_vid_dev_index;			// Unignore this
-%rename("%s") PJMEDIA_VID_DEFAULT_CAPTURE_DEV;		// Unignore this
-%rename("%s") PJMEDIA_VID_DEFAULT_RENDER_DEV;		// Unignore this
-%rename("%s") PJMEDIA_VID_INVALID_DEV;			// Unignore this
-%include "pjmedia-videodev/videodev.h"
-
-//
-//
-%rename("%s") pjsip_cred_data_type;			// Unignore this
-%rename("%s", regexmatch$name="PJSIP_CRED_DATA_.*") "";	// Unignore this
-%include "pjsip/sip_auth.h"
-
-//
-//
-%rename("%s") pjsip_status_code;			// Unignore this
-%rename("%s", regexmatch$name="PJSIP_SC_.*") "";	// Unignore this
-%include "pjsip/sip_msg.h"
-
-//
-//
-%rename("%s") pjsip_transport_type_e;			// Unignore this
-%rename("%s") pjsip_transport_flags_e;			// Unignore this
-%rename("%s") pjsip_transport_state;			// Unignore this
-%rename("%s", regexmatch$name="PJSIP_TRANSPORT_.*") "";	// Unignore this
-%rename("%s", regexmatch$name="PJSIP_TP_STATE_.*") "";	// Unignore this
-%include "pjsip/sip_transport.h"
-
-//
-//
-%rename("%s") pjsip_ssl_method;				// Unignore this
-%rename("%s", regexmatch$name="PJSIP_TLS.*_METHOD") "";	// Unignore this
-%rename("%s", regexmatch$name="PJSIP_SSL.*_METHOD") "";	// Unignore this
-%include "pjsip/sip_transport_tls.h"
-
-//
-//
-%rename("%s") PJSUA_INVALID_ID;				// Unignore this
-%rename("%s") pjsua_state;				// Unignore this
-%rename("%s", regexmatch$name="PJSUA_STATE_.*") "";	// Unignore this
-%rename("%s") pjsua_stun_use;				// Unignore this
-%rename("%s", regexmatch$name="PJSUA_STUN_USE_.*") "";	// Unignore this
-%rename("%s") pjsua_call_hold_type;			// Unignore this
-%rename("%s", regexmatch$name="PJSUA_CALL_HOLD_TYPE_.*") "";// Unignore this
-%rename("%s") pjsua_acc_id;				// Unignore this
-%rename("%s") pjsua_destroy_flag;			// Unignore this
-%rename("%s", regexmatch$name="PJSUA_DESTROY_.*") "";	// Unignore this
-%include "pjsua-lib/pjsua.h"
-
-//
-// Back to unignore everything
-//
-%rename("%s") "";
-
-//
-// Ignore stuffs in pjsua2 itself
+// Ignore stuffs in pjsua2
 //
 %ignore fromPj;
@@ -186,5 +59,9 @@
 //
 %include "pjsua2/types.hpp"
+%template(SipHeaderVector)		std::vector<pj::SipHeader>;
+%template(AuthCredInfoVector)		std::vector<pj::AuthCredInfo>;
+%template(SipMultipartPartVector)	std::vector<pj::SipMultipartPart>;
+
 %include "pjsua2/endpoint.hpp"
-#include "pjsua2/account.hpp"
+%include "pjsua2/account.hpp"
 
Index: pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/python/Makefile
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/python/Makefile	(revision 4638)
+++ pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/python/Makefile	(revision 4639)
@@ -1,19 +1,29 @@
 PYTHON_SO=_pjsua2.so
 
-PYTHON_SETUP_FLAGS = --inplace 
+#PYTHON_SETUP_FLAGS = --inplace 
 ifeq ($(OS),Windows_NT)
   PYTHON_SETUP_FLAGS += --compiler=mingw32
 endif
 
-.PHONY: all
+SWIG_FLAGS += -w312
+
+.PHONY: all install uninstall
 
 all: $(PYTHON_SO)
 
 $(PYTHON_SO): pjsua2_wrap.cpp setup.py
-	python setup.py build_ext $(PYTHON_SETUP_FLAGS)
+	python setup.py build $(PYTHON_SETUP_FLAGS)
 
-pjsua2_wrap.cpp: ../pjsua2.i $(SRCS)
+pjsua2_wrap.cpp: ../pjsua2.i ../symbols.i Makefile $(SRCS)
 	swig $(SWIG_FLAGS) -python  -o pjsua2_wrap.cpp ../pjsua2.i
 
 clean distclean realclean:
 	rm -rf $(PYTHON_SO) pjsua2_wrap.cpp pjsua2_wrap.h pjsua2.py build *.pyc
+
+install:
+	python setup.py install --user
+
+uninstall:
+	rm -f $(HOME)/.local/lib/python2.7/site-packages/pjsua2*
+	rm -f $(HOME)/.local/lib/python2.7/site-packages/_pjsua2*
+
Index: pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/symbols.i
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/symbols.i	(revision 4639)
+++ pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/symbols.i	(revision 4639)
@@ -0,0 +1,74 @@
+// This file is autogenerated by importsym script, do not modify!
+
+typedef int pj_status_t;
+
+enum pj_constants_ {PJ_SUCCESS = 0, PJ_TRUE = 1, PJ_FALSE = 0};
+
+typedef unsigned char pj_uint8_t;
+
+typedef int pj_int32_t;
+
+enum pj_file_access {PJ_O_RDONLY = 0x1101, PJ_O_WRONLY = 0x1102, PJ_O_RDWR = 0x1103, PJ_O_APPEND = 0x1108};
+
+enum pj_log_decoration {PJ_LOG_HAS_DAY_NAME = 1, PJ_LOG_HAS_YEAR = 2, PJ_LOG_HAS_MONTH = 4, PJ_LOG_HAS_DAY_OF_MON = 8, PJ_LOG_HAS_TIME = 16, PJ_LOG_HAS_MICRO_SEC = 32, PJ_LOG_HAS_SENDER = 64, PJ_LOG_HAS_NEWLINE = 128, PJ_LOG_HAS_CR = 256, PJ_LOG_HAS_SPACE = 512, PJ_LOG_HAS_COLOR = 1024, PJ_LOG_HAS_LEVEL_TEXT = 2048, PJ_LOG_HAS_THREAD_ID = 4096, PJ_LOG_HAS_THREAD_SWC = 8192, PJ_LOG_HAS_INDENT = 16384};
+
+typedef enum pj_qos_type {PJ_QOS_TYPE_BEST_EFFORT, PJ_QOS_TYPE_BACKGROUND, PJ_QOS_TYPE_VIDEO, PJ_QOS_TYPE_VOICE, PJ_QOS_TYPE_CONTROL} pj_qos_type;
+
+typedef enum pj_qos_flag {PJ_QOS_PARAM_HAS_DSCP = 1, PJ_QOS_PARAM_HAS_SO_PRIO = 2, PJ_QOS_PARAM_HAS_WMM = 4} pj_qos_flag;
+
+typedef enum pj_qos_wmm_prio {PJ_QOS_WMM_PRIO_BULK_EFFORT, PJ_QOS_WMM_PRIO_BULK, PJ_QOS_WMM_PRIO_VIDEO, PJ_QOS_WMM_PRIO_VOICE} pj_qos_wmm_prio;
+
+typedef struct pj_qos_params
+{
+  pj_uint8_t flags;
+  pj_uint8_t dscp_val;
+  pj_uint8_t so_prio;
+  pj_qos_wmm_prio wmm_prio;
+} pj_qos_params;
+
+typedef enum pj_ssl_cipher {PJ_TLS_NULL_WITH_NULL_NULL = 0x00000000, PJ_TLS_RSA_WITH_NULL_MD5 = 0x00000001, PJ_TLS_RSA_WITH_NULL_SHA = 0x00000002, PJ_TLS_RSA_WITH_NULL_SHA256 = 0x0000003B, PJ_TLS_RSA_WITH_RC4_128_MD5 = 0x00000004, PJ_TLS_RSA_WITH_RC4_128_SHA = 0x00000005, PJ_TLS_RSA_WITH_3DES_EDE_CBC_SHA = 0x0000000A, PJ_TLS_RSA_WITH_AES_128_CBC_SHA = 0x0000002F, PJ_TLS_RSA_WITH_AES_256_CBC_SHA = 0x00000035, PJ_TLS_RSA_WITH_AES_128_CBC_SHA256 = 0x0000003C, PJ_TLS_RSA_WITH_AES_256_CBC_SHA256 = 0x0000003D, PJ_TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA = 0x0000000D, PJ_TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA = 0x00000010, PJ_TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA = 0x00000013, PJ_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA = 0x00000016, PJ_TLS_DH_DSS_WITH_AES_128_CBC_SHA = 0x00000030, PJ_TLS_DH_RSA_WITH_AES_128_CBC_SHA = 0x00000031, PJ_TLS_DHE_DSS_WITH_AES_128_CBC_SHA = 0x00000032, PJ_TLS_DHE_RSA_WITH_AES_128_CBC_SHA = 0x00000033, PJ_TLS_DH_DSS_WITH_AES_256_CBC_SHA = 0x00000036, PJ_TLS_DH_RSA_WITH_AES_256_CBC_SHA = 0x00000037, PJ_TLS_DHE_DSS_WITH_AES_256_CBC_SHA = 0x00000038, PJ_TLS_DHE_RSA_WITH_AES_256_CBC_SHA = 0x00000039, PJ_TLS_DH_DSS_WITH_AES_128_CBC_SHA256 = 0x0000003E, PJ_TLS_DH_RSA_WITH_AES_128_CBC_SHA256 = 0x0000003F, PJ_TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 = 0x00000040, PJ_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 = 0x00000067, PJ_TLS_DH_DSS_WITH_AES_256_CBC_SHA256 = 0x00000068, PJ_TLS_DH_RSA_WITH_AES_256_CBC_SHA256 = 0x00000069, PJ_TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 = 0x0000006A, PJ_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 = 0x0000006B, PJ_TLS_DH_anon_WITH_RC4_128_MD5 = 0x00000018, PJ_TLS_DH_anon_WITH_3DES_EDE_CBC_SHA = 0x0000001B, PJ_TLS_DH_anon_WITH_AES_128_CBC_SHA = 0x00000034, PJ_TLS_DH_anon_WITH_AES_256_CBC_SHA = 0x0000003A, PJ_TLS_DH_anon_WITH_AES_128_CBC_SHA256 = 0x0000006C, PJ_TLS_DH_anon_WITH_AES_256_CBC_SHA256 = 0x0000006D, PJ_TLS_RSA_EXPORT_WITH_RC4_40_MD5 = 0x00000003, PJ_TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 = 0x00000006, PJ_TLS_RSA_WITH_IDEA_CBC_SHA = 0x00000007, PJ_TLS_RSA_EXPORT_WITH_DES40_CBC_SHA = 0x00000008, PJ_TLS_RSA_WITH_DES_CBC_SHA = 0x00000009, PJ_TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA = 0x0000000B, PJ_TLS_DH_DSS_WITH_DES_CBC_SHA = 0x0000000C, PJ_TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA = 0x0000000E, PJ_TLS_DH_RSA_WITH_DES_CBC_SHA = 0x0000000F, PJ_TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA = 0x00000011, PJ_TLS_DHE_DSS_WITH_DES_CBC_SHA = 0x00000012, PJ_TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA = 0x00000014, PJ_TLS_DHE_RSA_WITH_DES_CBC_SHA = 0x00000015, PJ_TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 = 0x00000017, PJ_TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA = 0x00000019, PJ_TLS_DH_anon_WITH_DES_CBC_SHA = 0x0000001A, PJ_SSL_FORTEZZA_KEA_WITH_NULL_SHA = 0x0000001C, PJ_SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA = 0x0000001D, PJ_SSL_FORTEZZA_KEA_WITH_RC4_128_SHA = 0x0000001E, PJ_SSL_CK_RC4_128_WITH_MD5 = 0x00010080, PJ_SSL_CK_RC4_128_EXPORT40_WITH_MD5 = 0x00020080, PJ_SSL_CK_RC2_128_CBC_WITH_MD5 = 0x00030080, PJ_SSL_CK_RC2_128_CBC_EXPORT40_WITH_MD5 = 0x00040080, PJ_SSL_CK_IDEA_128_CBC_WITH_MD5 = 0x00050080, PJ_SSL_CK_DES_64_CBC_WITH_MD5 = 0x00060040, PJ_SSL_CK_DES_192_EDE3_CBC_WITH_MD5 = 0x000700C0} pj_ssl_cipher;
+
+typedef enum pj_stun_nat_type {PJ_STUN_NAT_TYPE_UNKNOWN, PJ_STUN_NAT_TYPE_ERR_UNKNOWN, PJ_STUN_NAT_TYPE_OPEN, PJ_STUN_NAT_TYPE_BLOCKED, PJ_STUN_NAT_TYPE_SYMMETRIC_UDP, PJ_STUN_NAT_TYPE_FULL_CONE, PJ_STUN_NAT_TYPE_SYMMETRIC, PJ_STUN_NAT_TYPE_RESTRICTED, PJ_STUN_NAT_TYPE_PORT_RESTRICTED} pj_stun_nat_type;
+
+typedef enum pj_turn_tp_type {PJ_TURN_TP_UDP = 17, PJ_TURN_TP_TCP = 6, PJ_TURN_TP_TLS = 255} pj_turn_tp_type;
+
+typedef enum pjmedia_srtp_use {PJMEDIA_SRTP_DISABLED, PJMEDIA_SRTP_OPTIONAL, PJMEDIA_SRTP_MANDATORY} pjmedia_srtp_use;
+
+typedef enum pjmedia_vid_stream_rc_method {PJMEDIA_VID_STREAM_RC_NONE = 0, PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING = 1} pjmedia_vid_stream_rc_method;
+
+typedef pj_int32_t pjmedia_vid_dev_index;
+
+enum pjmedia_vid_dev_std_index {PJMEDIA_VID_DEFAULT_CAPTURE_DEV = -1, PJMEDIA_VID_DEFAULT_RENDER_DEV = -2, PJMEDIA_VID_INVALID_DEV = -3};
+
+typedef enum pjsip_cred_data_type {PJSIP_CRED_DATA_PLAIN_PASSWD = 0, PJSIP_CRED_DATA_DIGEST = 1, PJSIP_CRED_DATA_EXT_AKA = 16} pjsip_cred_data_type;
+
+typedef enum pjsip_status_code {PJSIP_SC_TRYING = 100, PJSIP_SC_RINGING = 180, PJSIP_SC_CALL_BEING_FORWARDED = 181, PJSIP_SC_QUEUED = 182, PJSIP_SC_PROGRESS = 183, PJSIP_SC_OK = 200, PJSIP_SC_ACCEPTED = 202, PJSIP_SC_MULTIPLE_CHOICES = 300, PJSIP_SC_MOVED_PERMANENTLY = 301, PJSIP_SC_MOVED_TEMPORARILY = 302, PJSIP_SC_USE_PROXY = 305, PJSIP_SC_ALTERNATIVE_SERVICE = 380, PJSIP_SC_BAD_REQUEST = 400, PJSIP_SC_UNAUTHORIZED = 401, PJSIP_SC_PAYMENT_REQUIRED = 402, PJSIP_SC_FORBIDDEN = 403, PJSIP_SC_NOT_FOUND = 404, PJSIP_SC_METHOD_NOT_ALLOWED = 405, PJSIP_SC_NOT_ACCEPTABLE = 406, PJSIP_SC_PROXY_AUTHENTICATION_REQUIRED = 407, PJSIP_SC_REQUEST_TIMEOUT = 408, PJSIP_SC_GONE = 410, PJSIP_SC_REQUEST_ENTITY_TOO_LARGE = 413, PJSIP_SC_REQUEST_URI_TOO_LONG = 414, PJSIP_SC_UNSUPPORTED_MEDIA_TYPE = 415, PJSIP_SC_UNSUPPORTED_URI_SCHEME = 416, PJSIP_SC_BAD_EXTENSION = 420, PJSIP_SC_EXTENSION_REQUIRED = 421, PJSIP_SC_SESSION_TIMER_TOO_SMALL = 422, PJSIP_SC_INTERVAL_TOO_BRIEF = 423, PJSIP_SC_TEMPORARILY_UNAVAILABLE = 480, PJSIP_SC_CALL_TSX_DOES_NOT_EXIST = 481, PJSIP_SC_LOOP_DETECTED = 482, PJSIP_SC_TOO_MANY_HOPS = 483, PJSIP_SC_ADDRESS_INCOMPLETE = 484, PJSIP_AC_AMBIGUOUS = 485, PJSIP_SC_BUSY_HERE = 486, PJSIP_SC_REQUEST_TERMINATED = 487, PJSIP_SC_NOT_ACCEPTABLE_HERE = 488, PJSIP_SC_BAD_EVENT = 489, PJSIP_SC_REQUEST_UPDATED = 490, PJSIP_SC_REQUEST_PENDING = 491, PJSIP_SC_UNDECIPHERABLE = 493, PJSIP_SC_INTERNAL_SERVER_ERROR = 500, PJSIP_SC_NOT_IMPLEMENTED = 501, PJSIP_SC_BAD_GATEWAY = 502, PJSIP_SC_SERVICE_UNAVAILABLE = 503, PJSIP_SC_SERVER_TIMEOUT = 504, PJSIP_SC_VERSION_NOT_SUPPORTED = 505, PJSIP_SC_MESSAGE_TOO_LARGE = 513, PJSIP_SC_PRECONDITION_FAILURE = 580, PJSIP_SC_BUSY_EVERYWHERE = 600, PJSIP_SC_DECLINE = 603, PJSIP_SC_DOES_NOT_EXIST_ANYWHERE = 604, PJSIP_SC_NOT_ACCEPTABLE_ANYWHERE = 606, PJSIP_SC_TSX_TIMEOUT = PJSIP_SC_REQUEST_TIMEOUT, PJSIP_SC_TSX_TRANSPORT_ERROR = PJSIP_SC_SERVICE_UNAVAILABLE, PJSIP_SC__force_32bit = 0x7FFFFFFF} pjsip_status_code;
+
+typedef enum pjsip_transport_type_e {PJSIP_TRANSPORT_UNSPECIFIED, PJSIP_TRANSPORT_UDP, PJSIP_TRANSPORT_TCP, PJSIP_TRANSPORT_TLS, PJSIP_TRANSPORT_SCTP, PJSIP_TRANSPORT_LOOP, PJSIP_TRANSPORT_LOOP_DGRAM, PJSIP_TRANSPORT_START_OTHER, PJSIP_TRANSPORT_IPV6 = 128, PJSIP_TRANSPORT_UDP6 = PJSIP_TRANSPORT_UDP + PJSIP_TRANSPORT_IPV6, PJSIP_TRANSPORT_TCP6 = PJSIP_TRANSPORT_TCP + PJSIP_TRANSPORT_IPV6, PJSIP_TRANSPORT_TLS6 = PJSIP_TRANSPORT_TLS + PJSIP_TRANSPORT_IPV6} pjsip_transport_type_e;
+
+enum pjsip_transport_flags_e {PJSIP_TRANSPORT_RELIABLE = 1, PJSIP_TRANSPORT_SECURE = 2, PJSIP_TRANSPORT_DATAGRAM = 4};
+
+typedef enum pjsip_transport_state {PJSIP_TP_STATE_CONNECTED, PJSIP_TP_STATE_DISCONNECTED} pjsip_transport_state;
+
+typedef enum pjsip_ssl_method {PJSIP_SSL_UNSPECIFIED_METHOD = 0, PJSIP_TLSV1_METHOD = 31, PJSIP_SSLV2_METHOD = 20, PJSIP_SSLV3_METHOD = 30, PJSIP_SSLV23_METHOD = 23} pjsip_ssl_method;
+
+typedef enum pjrpid_activity {PJRPID_ACTIVITY_UNKNOWN, PJRPID_ACTIVITY_AWAY, PJRPID_ACTIVITY_BUSY} pjrpid_activity;
+
+enum pjsua_invalid_id_const_ {PJSUA_INVALID_ID = -1};
+
+typedef enum pjsua_state {PJSUA_STATE_NULL, PJSUA_STATE_CREATED, PJSUA_STATE_INIT, PJSUA_STATE_STARTING, PJSUA_STATE_RUNNING, PJSUA_STATE_CLOSING} pjsua_state;
+
+typedef enum pjsua_stun_use {PJSUA_STUN_USE_DEFAULT, PJSUA_STUN_USE_DISABLED} pjsua_stun_use;
+
+typedef enum pjsua_call_hold_type {PJSUA_CALL_HOLD_TYPE_RFC3264, PJSUA_CALL_HOLD_TYPE_RFC2543} pjsua_call_hold_type;
+
+typedef int pjsua_acc_id;
+
+typedef enum pjsua_destroy_flag {PJSUA_DESTROY_NO_RX_MSG = 1, PJSUA_DESTROY_NO_TX_MSG = 2, PJSUA_DESTROY_NO_NETWORK = PJSUA_DESTROY_NO_RX_MSG | PJSUA_DESTROY_NO_TX_MSG} pjsua_destroy_flag;
+
+typedef enum pjsua_100rel_use {PJSUA_100REL_NOT_USED, PJSUA_100REL_MANDATORY, PJSUA_100REL_OPTIONAL} pjsua_100rel_use;
+
+typedef enum pjsua_sip_timer_use {PJSUA_SIP_TIMER_INACTIVE, PJSUA_SIP_TIMER_OPTIONAL, PJSUA_SIP_TIMER_REQUIRED, PJSUA_SIP_TIMER_ALWAYS} pjsua_sip_timer_use;
+
+typedef enum pjsua_ipv6_use {PJSUA_IPV6_DISABLED, PJSUA_IPV6_ENABLED} pjsua_ipv6_use;
+
Index: pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/symbols.lst
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/symbols.lst	(revision 4639)
+++ pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/symbols.lst	(revision 4639)
@@ -0,0 +1,21 @@
+pj/types.h			pj_status_t pj_constants_ pj_uint8_t pj_int32_t		
+pj/file_io.h			pj_file_access
+pj/log.h			pj_log_decoration
+pj/sock_qos.h			pj_qos_type pj_qos_flag pj_qos_wmm_prio pj_qos_params
+pj/ssl_sock.h			pj_ssl_cipher
+
+pjnath/nat_detect.h		pj_stun_nat_type
+pjnath/turn_session.h		pj_turn_tp_type
+
+pjmedia/transport_srtp.h	pjmedia_srtp_use
+pjmedia/vid_stream.h		pjmedia_vid_stream_rc_method
+pjmedia-videodev/videodev.h	pjmedia_vid_dev_index pjmedia_vid_dev_std_index
+
+pjsip/sip_auth.h		pjsip_cred_data_type
+pjsip/sip_msg.h			pjsip_status_code
+pjsip/sip_transport.h		pjsip_transport_type_e pjsip_transport_flags_e pjsip_transport_state
+pjsip/sip_transport_tls.h	pjsip_ssl_method
+
+pjsip-simple/rpid.h		pjrpid_activity
+
+pjsua-lib/pjsua.h		pjsua_invalid_id_const_ pjsua_state pjsua_stun_use pjsua_call_hold_type pjsua_acc_id pjsua_destroy_flag pjsua_100rel_use pjsua_sip_timer_use pjsua_ipv6_use
Index: pjproject/branches/projects/pjsua2/pjsip/include/pjsua-lib/pjsua.h
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip/include/pjsua-lib/pjsua.h	(revision 4638)
+++ pjproject/branches/projects/pjsua2/pjsip/include/pjsua-lib/pjsua.h	(revision 4639)
@@ -252,5 +252,8 @@
 
 /** Constant to identify invalid ID for all sorts of IDs. */
-#define PJSUA_INVALID_ID	    (-1)
+enum pjsua_invalid_id_const_
+{
+    PJSUA_INVALID_ID = -1
+};
 
 /** Disabled features temporarily for media reorganization */
@@ -1881,4 +1884,24 @@
 
 /**
+ * Register a thread to poll for events. This function should be
+ * called by an external worker thread, and it will block polling
+ * for events until the library is destroyed.
+ *
+ * @return 		PJ_SUCCESS if things are working correctly
+ * 			or an error polling cannot be done for some
+ * 			reason.
+ */
+PJ_DECL(pj_status_t) pjsua_register_worker_thread(const char *name);
+
+
+/**
+ * Signal all worker threads to quit. This will only wait until internal
+ * threads are done. For external threads, application must perform
+ * its own waiting for the external threads to quit from
+ * pjsua_register_worker_thread() function.
+ */
+PJ_DECL(void) pjsua_stop_worker_threads(void);
+
+/**
  * Create memory pool to be used by the application. Once application
  * finished using the pool, it must be released with pj_pool_release().
Index: pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/account.hpp
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/account.hpp	(revision 4638)
+++ pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/account.hpp	(revision 4639)
@@ -42,5 +42,4 @@
 {
 using std::string;
-using std::vector;
 
 /**
@@ -141,4 +140,6 @@
 };
 
+/** Array of SIP credentials */
+typedef std::vector<AuthCredInfo> AuthCredInfoVector;
 
 /**
Index: pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/approach1.hpp
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/approach1.hpp	(revision 4638)
+++ 	(revision )
@@ -1,64 +1,0 @@
-//////////////////////////////// API ////////////////////////////////
-
-class Account
-{
-public: /* Operations */
-    virtual ~Account();
-
-    void create();
-    void setRegistration(bool renew=true);
-
-public: /* Callbacks */
-    virtual void onRegState(RegStateParam &prm)
-    {}
-
-protected:
-    /* App should always subclass this. */
-    Account(Endpoint &ep, const AccountConfig &cfg);
-};
-
-
-class Endpoint
-{
-public: /* Operations */
-    Endpoint(EndpointCallback *cb);
-
-public:	/* Callbacks */
-    virtual void onTransportStateChanged(
-			const TransportStateChangedParam &prm)
-    {}
-};
-
-///////////////////////////// Sample Application /////////////////////////////
-class MyAccount: public Account
-{
-public:
-    MyAccount(Endpoint &ep, const AccountConfig &cfg);
-
-    void doNewThing() {}
-
-    virtual void onRegState(RegStateParam &prm)
-    { /* do stuff */  }
-
-};
-
-class MyEndpoint : public Endpoint
-{
-public:
-    virtual void onTransportStateChanged(
-			const TransportStateChangedParam &prm)
-    {}
-};
-
-
-int main()
-{
-    MyEndpoint ep;
-
-    // Two steps creation: instantiate, and actually create the acc in pjsua
-    // (why??)
-    MyAccount acc(accCfg);
-    acc.create(ep);
-
-    acc.setRegistration(true);
-};
Index: pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/approach2.hpp
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/approach2.hpp	(revision 4638)
+++ 	(revision )
@@ -1,105 +1,0 @@
-//////////////////////////////// API ////////////////////////////////
-
-class AccountCallback
-{
-public:
-    Account *getAccount();
-
-    virtual ~AccountCallback() {}
-
-    virtual void onRegState(RegStateParam &prm);
-
-protected:
-    void setAccount(Account *acc);
-
-private:
-    Account *acc;
-
-};
-
-
-class Account
-{
-public:
-    virtual ~Account();
-
-    void setRegistration(bool renew=true);
-
-protected:
-    friend class EndpointCallback;
-
-    /* Users are not supposed to instantiate this directly. They either need
-     * to subclasss this, or create from endpoint.
-     */
-    Account(const AccountConfig &cfg, AccountCallback &cb);
-};
-
-
-class EndpointCallback
-{
-public:
-    /* By default this creates Account instance, but if the app subclasses
-     * Account, it can implement this callback.
-     */
-    virtual Account *onCreateAccount(const AccountConfig &cfg,
-                                     AccountCallback &cb)
-    {
-	return new Account(cfg, cb);
-    }
-
-    /* Other callbacks: ... */
-    virtual void onTransportStateChanged(
-			const TransportStateChangedParam &prm)
-    {}
-
-};
-
-class Endpoint
-{
-public:
-    Endpoint(EndpointCallback *cb);
-
-    /* This is the only way to create account */
-    Account* createAccount(const AccountConfig &cfg, AccountCallback &cb)
-    {
-	Account *acc = this->endpointCallback->onCreateAccount(cfg, cb);
-	acc->setRegistration();
-	return acc;
-    }
-};
-
-///////////////////////////// Sample Application /////////////////////////////
-class MyAccountCallback : public AccountCallback
-{
-public:
-    virtual void onRegState(RegStateParam &prm)
-    { /* do stuff */  }
-};
-
-class MyAccount: public Account
-{
-public:
-    MyAccount(const AccountConfig &cfg, AccountCallback &cb);
-
-    void doNewThing();
-};
-
-class MyEndpointCallback : public EndpointCallback
-{
-public:
-    virtual Account *onCreateAccount(const AccountConfig &cfg, AccountCallback &cb)
-    {
-	return new MyAccount(cfg, cb);
-    };
-};
-
-
-int main()
-{
-    Endpoint ep(new MyEndpointCallback);
-
-    Account *acc = ep.createAccount(accCfg, new MyAccountCallback);
-    acc->setRegistration(true);
-};
-
-
Index: pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/approach3.hpp
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/approach3.hpp	(revision 4638)
+++ 	(revision )
@@ -1,82 +1,0 @@
-//////////////////////////////// API ////////////////////////////////
-
-class AccountCallback
-{
-public:
-    Account *getAccount();
-
-    virtual ~AccountCallback() {}
-
-    virtual void onRegState(RegStateParam &prm);
-
-protected:
-    void setAccount(Account *acc);
-
-private:
-    Account *acc;
-};
-
-class Account
-{
-public: /* Operations */
-    virtual ~Account();
-
-    void create();
-    void setRegistration(bool renew=true);
-
-protected:
-    /* App should always subclass this. */
-    Account(Endpoint &ep, const AccountConfig &cfg);
-};
-
-
-class EndpointCallback
-{
-public:
-
-    /* Other callbacks: ... */
-    virtual void onTransportStateChanged(
-			const TransportStateChangedParam &prm)
-    {}
-
-};
-
-class Endpoint
-{
-public: /* Operations */
-    Endpoint(EndpointCallback *cb);
-
-public:	/* Callbacks */
-    virtual void onTransportStateChanged(
-			const TransportStateChangedParam &prm)
-    {}
-};
-
-///////////////////////////// Sample Application /////////////////////////////
-class MyAccount: public Account
-{
-public:
-    MyAccount(Endpoint &ep, const AccountConfig &cfg);
-
-    void doNewThing() {}
-
-    virtual void onRegState(RegStateParam &prm)
-    { /* do stuff */  }
-
-};
-
-class MyEndpoint : public Endpoint
-{
-public:
-    virtual void onTransportStateChanged(
-			const TransportStateChangedParam &prm)
-    {}
-};
-
-
-int main()
-{
-    MyEndpoint ep;
-    MyAccount acc(ep, accCfg);
-    acc.setRegistration(true);
-};
Index: pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/endpoint.hpp
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/endpoint.hpp	(revision 4638)
+++ pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/endpoint.hpp	(revision 4639)
@@ -598,4 +598,9 @@
 
     /**
+     * Get library version.
+     */
+    Version libVersion() const;
+
+    /**
      * Instantiate pjsua application. Application must call this function before
      * calling any other functions, to make sure that the underlying libraries
@@ -629,4 +634,33 @@
      */
     void libStart() throw(Error);
+
+    /**
+     * Register a thread to poll for events. This function should be
+     * called by an external worker thread, and it will block polling
+     * for events until the library is destroyed.
+     */
+    void libRegisterWorkerThread(const string &name) throw(Error);
+
+    /**
+     * Stop all worker threads.
+     */
+    void libStopWorkerThreads();
+
+    /**
+     * Poll pjsua for events, and if necessary block the caller thread for
+     * the specified maximum interval (in miliseconds).
+     *
+     * Application doesn't normally need to call this function if it has
+     * configured worker thread (\a thread_cnt field) in pjsua_config
+     * structure, because polling then will be done by these worker threads
+     * instead.
+     *
+     * @param msec_timeout Maximum time to wait, in miliseconds.
+     *
+     * @return		The number of events that have been handled during the
+     *	    		poll. Negative value indicates error, and application
+     *	    		can retrieve the error as (status = -return_value).
+     */
+    int libHandleEvents(unsigned msec_timeout);
 
     /**
@@ -641,5 +675,5 @@
      * keep track of it's state.
      *
-     * @param prmFlags		Combination of pjsua_destroy_flag enumeration.
+     * @param prmFlags	Combination of pjsua_destroy_flag enumeration.
      */
     void libDestroy(unsigned prmFlags=0) throw(Error);
Index: pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/types.hpp
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/types.hpp	(revision 4638)
+++ pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/types.hpp	(revision 4639)
@@ -71,9 +71,8 @@
 
 /*
- * Forward declaration of Account, AccountConfig, to be used
+ * Forward declaration of Account to be used
  * by Endpoint.
  */
 class Account;
-class AccountConfig;
 
 
@@ -143,5 +142,9 @@
 
 #   define PJSUA2_RAISE_ERROR3(status,op,txt)	\
-	throw Error(status, op, txt, __FILE__, __LINE__)
+	do { \
+	    Error err_ = Error(status, op, txt, __FILE__, __LINE__); \
+	    PJ_LOG(1,(THIS_FILE, "%s", err_.info().c_str())); \
+	    throw err_; \
+	} while (0)
 
 #else
@@ -153,5 +156,9 @@
 
 #   define PJSUA2_RAISE_ERROR3(status,op,txt)	\
-	throw Error(status, op, txt, string(), 0)
+	do { \
+	    Error err_ = Error(status, op, txt, string(), 0); \
+	    PJ_LOG(1,(THIS_FILE, "%s", err_.info().c_str())); \
+	    throw err_; \
+	} while (0)
 
 #endif
@@ -159,6 +166,7 @@
 #define PJSUA2_CHECK_RAISE_ERROR2(status, op)	\
 	do { \
-	    if (status != PJ_SUCCESS) \
+	    if (status != PJ_SUCCESS) { \
 		PJSUA2_RAISE_ERROR2(status, op); \
+	    } \
 	} while (0)
 
@@ -171,4 +179,31 @@
 	    PJSUA2_CHECK_RAISE_ERROR2(the_status, #expr); \
 	} while (0)
+
+//////////////////////////////////////////////////////////////////////////////
+
+struct Version
+{
+    /** Major number */
+    int		major;
+
+    /** Minor number */
+    int		minor;
+
+    /** Additional revision number */
+    int		rev;
+
+    /** Version suffix (e.g. "-svn") */
+    string	suffix;
+
+    /** The full version info (e.g. "2.1.0-svn") */
+    string	full;
+
+    /**
+     * PJLIB version number as three bytes with the following format:
+     * 0xMMIIRR00, where MM: major number, II: minor number, RR: revision
+     * number, 00: always zero for now.
+     */
+    unsigned	numeric;
+};
 
 //////////////////////////////////////////////////////////////////////////////
@@ -232,8 +267,7 @@
                  const int data_type,
                  const string data);
-};
-
-/** Array of SIP credentials */
-typedef std::vector<AuthCredInfo> AuthCredInfoVector;
+
+};
+
 
 //////////////////////////////////////////////////////////////////////////////
Index: pjproject/branches/projects/pjsua2/pjsip/src/pjsua-lib/pjsua_core.c
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip/src/pjsua-lib/pjsua_core.c	(revision 4638)
+++ pjproject/branches/projects/pjsua2/pjsip/src/pjsua-lib/pjsua_core.c	(revision 4639)
@@ -687,4 +687,48 @@
 }
 
+PJ_DEF(pj_status_t) pjsua_register_worker_thread(const char *name)
+{
+    pj_thread_desc desc;
+    pj_thread_t *thread;
+    pj_status_t status;
+
+    if (pjsua_var.thread_quit_flag)
+	return PJ_EGONE;
+
+    status = pj_thread_register(NULL, desc, &thread);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    if (name)
+	PJ_LOG(4,(THIS_FILE, "Worker thread %s started", name));
+
+    worker_thread(NULL);
+
+    if (name)
+	PJ_LOG(4,(THIS_FILE, "Worker thread %s stopped", name));
+
+    return PJ_SUCCESS;
+}
+
+PJ_DEF(void) pjsua_stop_worker_threads(void)
+{
+    unsigned i;
+
+    pjsua_var.thread_quit_flag = 1;
+
+    /* Wait worker threads to quit: */
+    for (i=0; i<(int)pjsua_var.ua_cfg.thread_cnt; ++i) {
+    	if (pjsua_var.thread[i]) {
+    	    pj_status_t status;
+    	    status = pj_thread_join(pjsua_var.thread[i]);
+    	    if (status != PJ_SUCCESS) {
+    		PJ_PERROR(4,(THIS_FILE, status, "Error joining worker thread"));
+    		pj_thread_sleep(1000);
+    	    }
+    	    pj_thread_destroy(pjsua_var.thread[i]);
+    	    pjsua_var.thread[i] = NULL;
+    	}
+    }
+}
 
 /* Init random seed */
@@ -1466,19 +1510,5 @@
 
     /* Signal threads to quit: */
-    pjsua_var.thread_quit_flag = 1;
-
-    /* Wait worker threads to quit: */
-    for (i=0; i<(int)pjsua_var.ua_cfg.thread_cnt; ++i) {
-	if (pjsua_var.thread[i]) {
-	    pj_status_t status;
-	    status = pj_thread_join(pjsua_var.thread[i]);
-	    if (status != PJ_SUCCESS) {
-		PJ_PERROR(4,(THIS_FILE, status, "Error joining worker thread"));
-		pj_thread_sleep(1000);
-	    }
-	    pj_thread_destroy(pjsua_var.thread[i]);
-	    pjsua_var.thread[i] = NULL;
-	}
-    }
+    pjsua_stop_worker_threads();
     
     if (pjsua_var.endpt) {
Index: pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/account.cpp
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/account.cpp	(revision 4638)
+++ pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/account.cpp	(revision 4639)
@@ -333,4 +333,11 @@
 ///////////////////////////////////////////////////////////////////////////////
 
+AccountPresenceStatus::AccountPresenceStatus()
+: isOnline(false), activity(PJRPID_ACTIVITY_UNKNOWN)
+{
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
 void AccountInfo::fromPj(const pjsua_acc_info &pai)
 {
@@ -379,5 +386,5 @@
 {
     pjsua_acc_config pj_acc_cfg = acc_cfg.toPj();
-
+    pj_acc_cfg.user_data = (void*)this;
     PJSUA2_CHECK_EXPR( pjsua_acc_modify(id, &pj_acc_cfg) );
 }
Index: pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/endpoint.cpp
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/endpoint.cpp	(revision 4638)
+++ pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/endpoint.cpp	(revision 4639)
@@ -545,4 +545,16 @@
  * Endpoint library operations
  */
+Version Endpoint::libVersion() const
+{
+    Version ver;
+    ver.major = PJ_VERSION_NUM_MAJOR;
+    ver.minor = PJ_VERSION_NUM_MINOR;
+    ver.rev = PJ_VERSION_NUM_REV;
+    ver.suffix = PJ_VERSION_NUM_EXTRA;
+    ver.full = pj_get_version();
+    ver.numeric = PJ_VERSION_NUM;
+    return ver;
+}
+
 void Endpoint::libCreate() throw(Error)
 {
@@ -594,4 +606,19 @@
 }
 
+void Endpoint::libRegisterWorkerThread(const string &name) throw(Error)
+{
+    PJSUA2_CHECK_EXPR(pjsua_register_worker_thread(name.c_str()));
+}
+
+void Endpoint::libStopWorkerThreads()
+{
+    pjsua_stop_worker_threads();
+}
+
+int Endpoint::libHandleEvents(unsigned msec_timeout)
+{
+    return pjsua_handle_events(msec_timeout);
+}
+
 void Endpoint::libDestroy(unsigned flags) throw(Error)
 {
Index: pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/types.cpp
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/types.cpp	(revision 4638)
+++ pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/types.cpp	(revision 4639)
@@ -23,4 +23,6 @@
 using namespace std;
 
+#define THIS_FILE	"types.cpp"
+
 ///////////////////////////////////////////////////////////////////////////////
 
