Allow explicit object registration.

This also allows explicit object *un*registration, which means that the object
lifecycle (as exposed to the bus) is now divorced from the object lifecycle as a
C++ object. This allows things like e.g. unregistering an object now but running
its cleanup "later".

BUG=chromium-os:9628
TEST=Adhoc
Built, ran, connected to 3G.

Change-Id: Icfdb96ff47bb6a0d5e86a0774981906f20304c88
Signed-off-by: Elly Jones <ellyjones@chromium.org>
Signed-off-by: Jason Glasgow <jglasgow@chromium.org>

Review URL: http://codereview.chromium.org/6250197
diff --git a/include/dbus-c++/object.h b/include/dbus-c++/object.h
index 962bf77..4e8ea6d 100644
--- a/include/dbus-c++/object.h
+++ b/include/dbus-c++/object.h
@@ -52,11 +52,14 @@
 	
  	inline Connection &conn();
 
+protected:
+	virtual void register_obj() = 0;
+	virtual void unregister_obj() = 0;
+	virtual bool is_registered() = 0;
+
 private:
 
 	DXXAPILOCAL virtual bool handle_message(const Message &) = 0;
-	DXXAPILOCAL virtual void register_obj() = 0;
-	DXXAPILOCAL virtual void unregister_obj() = 0;
 
 private:
 
@@ -151,15 +154,16 @@
 
 	Continuation *find_continuation(const Tag *tag);
 
+	virtual void register_obj();
+	virtual void unregister_obj();
+	virtual bool is_registered();
+
 private:
 
 	void _emit_signal(SignalMessage &);
 
 	bool handle_message(const Message &);
 
-	void register_obj();
-	void unregister_obj();
-
 	typedef std::map<const Tag *, Continuation *> ContinuationMap;
 	ContinuationMap _continuations;
 
@@ -206,8 +210,10 @@
 
 	bool handle_message(const Message &);
 
-	void register_obj();
-	void unregister_obj();
+protected:
+	virtual void register_obj();
+	virtual void unregister_obj();
+	virtual bool is_registered();
 
 private:
 
diff --git a/src/object.cpp b/src/object.cpp
index f7d0916..5bb538d 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -173,6 +173,9 @@
 
 void ObjectAdaptor::unregister_obj()
 {
+	if (!is_registered())
+		return;
+
 	_adaptor_table.erase(path());
 
 	debug_log("unregistering local object %s", path().c_str());
@@ -180,6 +183,11 @@
 	dbus_connection_unregister_object_path(conn()._pvt->conn, path().c_str());
 }
 
+bool ObjectAdaptor::is_registered()
+{
+	return _adaptor_table.find(path()) != _adaptor_table.end();
+}
+
 void ObjectAdaptor::_emit_signal(SignalMessage &sig)
 {
 	sig.path(path().c_str());
@@ -321,6 +329,11 @@
 	conn().remove_filter(_filtered);
 }
 
+bool ObjectProxy::is_registered()
+{
+	return true;
+}
+
 Message ObjectProxy::_invoke_method(CallMessage &call)
 {
 	if (call.path() == NULL)