From 1e4e2782b5a5d83de8378e7d6bc5768f7da6c8e2 Mon Sep 17 00:00:00 2001
From: Ramin Yaghoubzadeh <ryaghoub@techfak.uni-bielefeld.de>
Date: Thu, 12 Apr 2012 17:23:14 +0200
Subject: [PATCH] Committing before adding the remoteServer code

---
 cpp/src/ipaaca-test-main.cc | 86 +++----------------------------------
 cpp/src/ipaaca.cc           | 51 +++++++++++++++++++---
 cpp/src/ipaaca.h            | 32 ++++++++------
 3 files changed, 70 insertions(+), 99 deletions(-)

diff --git a/cpp/src/ipaaca-test-main.cc b/cpp/src/ipaaca-test-main.cc
index 86c732d..4000a09 100644
--- a/cpp/src/ipaaca-test-main.cc
+++ b/cpp/src/ipaaca-test-main.cc
@@ -5,84 +5,6 @@
 //#include <rsc/logging/LoggerFactory.h>
 // //rsc::logging::LoggerFactory::getInstance().reconfigure(rsc::logging::Logger::LEVEL_ALL);
 
-#if 0
-//boost::mutex mtx;
-using namespace ipaaca;
-
-class Testo {
-	protected:
-		std::string _name;
-	public:
-		inline Testo(const std::string& name="Testo"): _name(name) { }
-		inline void handleIUEvent(EventPtr event)
-		{
-			std::cout << _name << " received a ";
-			std::string type = event->getType();
-			if (type == "ipaaca::IUPayloadUpdate") {
-				std::cout << *boost::static_pointer_cast<IUPayloadUpdate>(event->getData()) << std::endl;
-			} else if (type == "ipaaca::IULinkUpdate") {
-				std::cout << *boost::static_pointer_cast<IULinkUpdate>(event->getData()) << std::endl;
-			} else {
-				std::cout << type << " (Unhandled type!)" << std::endl;
-			}
-		}
-};
-
-int main() {
-	initialize_ipaaca_rsb();
-	
-	ListenerPtr listener = Factory::getInstance().createListener( Scope("/tutorial/converter"));
-	
-	Testo t("TESTO");
-	HandlerPtr event_handler = HandlerPtr(new EventFunctionHandler(boost::bind(&Testo::handleIUEvent, boost::ref(t), _1)));
-	listener->addHandler( event_handler );
-	
-	while(true) {
-		boost::this_thread::sleep(boost::posix_time::milliseconds(100));
-	}
-	return EXIT_SUCCESS;
-}
-//
-//
-//
-//
-
-using namespace ipaaca;
-int main() {
-	initialize_ipaaca_rsb();
-	
-	//Informer<ipaaca::IUPayloadUpdate>::Ptr pinformer = Factory::getInstance().createInformer<ipaaca::IUPayloadUpdate> ( Scope("/tutorial/converter"));
-	//Informer<ipaaca::IULinkUpdate>::Ptr linformer = Factory::getInstance().createInformer<ipaaca::IULinkUpdate> ( Scope("/tutorial/converter"));
-	
-	Informer<AnyType>::Ptr informer = Factory::getInstance().createInformer<AnyType> ( Scope("/tutorial/converter"));
-
-	IUPayloadUpdate* pup = new ipaaca::IUPayloadUpdate();
-	Informer<ipaaca::IUPayloadUpdate>::DataPtr pdata(pup);
-	pup->uid = "2000";
-	pup->revision = 3;
-	pup->writer_name = "Comp1_OB";
-	pup->is_delta = true;
-	pup->new_items["new_key"] = "new_value";
-	pup->new_items["another_key"] = "some_info";
-	pup->keys_to_remove.push_back("old_key");
-	informer->publish(pdata);
-	
-	IULinkUpdate* lup = new ipaaca::IULinkUpdate();
-	Informer<ipaaca::IULinkUpdate>::DataPtr ldata(lup);
-	lup->uid = "2001";
-	lup->revision = 4;
-	lup->writer_name = "Comp2_IB";
-	lup->is_delta = true;
-	lup->new_links["SLL"].insert("2000");
-	lup->new_links["grin"].insert("1002");
-	lup->links_to_remove["grin"].insert("1001");
-	informer->publish(ldata);
-	
-	std::cout << "Done." << std::endl;
-	return EXIT_SUCCESS;
-}
-#endif
-
 //
 //   TESTS
 //
@@ -94,7 +16,7 @@ int main() {
 	try{
 		initialize_ipaaca_rsb();
 		
-		InputBuffer ib("TestIB", "testcategory");
+		InputBuffer ib("Tester", "testcategory");
 		
 		
 		while (true) {
@@ -112,7 +34,7 @@ int main() {
 		initialize_ipaaca_rsb();
 		
 		
-		OutputBuffer ob("TestOB");
+		OutputBuffer ob("Tester");
 		std::cout << "Buffer: " << ob.unique_name() << std::endl;
 		
 		IU::ref iu = IU::create("testcategory");
@@ -125,7 +47,9 @@ int main() {
 		
 		std::string s = "The string \"" + iu->_payload["TEST"].to_str() + "\" is the new value.";
 		std::cout << "Concatenation test: " << s << std::endl;
-	
+		
+		iu->add_link("grin", "DUMMY_IU_UID");
+		
 		std::cout << "Interpreted as  long  value: " << iu->_payload["TEST"].to_int() << std::endl;
 		std::cout << "Interpreted as double value: " << iu->_payload["TEST"].to_float() << std::endl;
 		iu->commit();
diff --git a/cpp/src/ipaaca.cc b/cpp/src/ipaaca.cc
index 00df2d0..10c6cfc 100644
--- a/cpp/src/ipaaca.cc
+++ b/cpp/src/ipaaca.cc
@@ -47,6 +47,24 @@ void init_inprocess_too() {
 */
 //}}}
 
+std::ostream& operator<<(std::ostream& os, const SmartLinkMap& obj)//{{{
+{
+	os << "{";
+	bool first = true;
+	for (LinkMap::const_iterator it=obj._links.begin(); it!=obj._links.end(); ++it) {
+		if (first) { first=false; } else { os << ", "; }
+		os << "'" << it->first << "': [";
+		bool firstinner = true;
+		for (LinkSet::const_iterator it2=it->second.begin(); it2!=it->second.end(); ++it2) {
+			if (firstinner) { firstinner=false; } else { os << ", "; }
+			os << "'" << *it2 << "'";
+		}
+		os << "]";
+	}
+	os << "}";
+	return os;
+}
+//}}}
 std::ostream& operator<<(std::ostream& os, const Payload& obj)//{{{
 {
 	os << "{";
@@ -61,11 +79,15 @@ std::ostream& operator<<(std::ostream& os, const Payload& obj)//{{{
 //}}}
 std::ostream& operator<<(std::ostream& os, const IUInterface& obj)//{{{
 {
-	os << "IUInterface(uid=" << obj.uid() << ", revision=" << obj.revision();
-	os << ", owner_name=" << obj.owner_name();
-	os << ", payload = ";
-	bool first = true;
+	os << "IUInterface(uid='" << obj.uid() << "'";
+	os << ", category='" << obj.category() << "'";
+	os << ", revision=" << obj.revision();
+	os << ", committed=" << (obj.committed()?"True":"False");
+	os << ", owner_name='" << obj.owner_name() << "'";
+	os << ", payload=";
 	os << obj.const_payload();
+	os << ", links=";
+	os << obj._links;
 	os << ")";
 	return os;
 }
@@ -520,6 +542,25 @@ void IUInterface::_associate_with_buffer(Buffer* buffer) { //boost::shared_ptr<B
 	payload()._set_owner_name(buffer->unique_name());
 }
 
+/// C++-specific convenience function to add one single link
+void IUInterface::add_link(const std::string& type, const std::string& target, const std::string& writer_name)
+{
+	LinkMap none;
+	LinkMap add;
+	add[type].insert(target);
+	_modify_links(true, add, none, writer_name);
+	_add_and_remove_links(add, none);
+}
+/// C++-specific convenience function to remove one single link
+void IUInterface::remove_link(const std::string& type, const std::string& target, const std::string& writer_name)
+{
+	LinkMap none;
+	LinkMap remove;
+	remove[type].insert(target);
+	_modify_links(true, none, remove, writer_name);
+	_add_and_remove_links(none, remove);
+}
+
 void IUInterface::add_links(const std::string& type, const LinkSet& targets, const std::string& writer_name)
 {
 	LinkMap none;
@@ -674,7 +715,7 @@ void RemotePushIU::_apply_update(IUPayloadUpdate::ptr update)
 }
 void RemotePushIU::_apply_commission()
 {
-	IPAACA_IMPLEMENT_ME
+	_committed = true;
 }
 void Payload::_remotely_enforced_wipe()
 {
diff --git a/cpp/src/ipaaca.h b/cpp/src/ipaaca.h
index ca4a4f0..29dffbe 100644
--- a/cpp/src/ipaaca.h
+++ b/cpp/src/ipaaca.h
@@ -131,6 +131,7 @@ class Lock
 typedef std::set<std::string> LinkSet;
 typedef std::map<std::string, LinkSet> LinkMap;
 class SmartLinkMap {
+	friend std::ostream& operator<<(std::ostream& os, const SmartLinkMap& obj);
 	friend class IUInterface;
 	friend class IU;
 	friend class IUConverter;
@@ -147,7 +148,7 @@ class SmartLinkMap {
 const LinkSet EMPTY_LINK_SET;
 //const std::set<std::string> EMPTY_LINK_SET;
 
-class Buffer { //: public boost::enable_shared_from_this<Buffer> {
+class Buffer { //: public boost::enable_shared_from_this<Buffer> {//{{{
 	friend class IU;
 	friend class RemotePushIU;
 	protected:
@@ -168,8 +169,9 @@ class Buffer { //: public boost::enable_shared_from_this<Buffer> {
 		inline const std::string& unique_name() { return _unique_name; }
 		//_IPAACA_ABSTRACT_ virtual void add(boost::shared_ptr<IUInterface> iu) = 0;
 };
+//}}}
 
-class OutputBuffer: public Buffer { //, public boost::enable_shared_from_this<OutputBuffer>  {
+class OutputBuffer: public Buffer { //, public boost::enable_shared_from_this<OutputBuffer>  {//{{{
 	friend class IU;
 	friend class RemotePushIU;
 	protected:
@@ -198,8 +200,9 @@ class OutputBuffer: public Buffer { //, public boost::enable_shared_from_this<Ou
 		boost::shared_ptr<IU> remove(const std::string& iu_uid);
 		boost::shared_ptr<IU> remove(boost::shared_ptr<IU> iu);
 };
+//}}}
 
-class InputBuffer: public Buffer { //, public boost::enable_shared_from_this<InputBuffer>  {
+class InputBuffer: public Buffer { //, public boost::enable_shared_from_this<InputBuffer>  {//{{{
 	friend class IU;
 	friend class RemotePushIU;
 	protected:
@@ -237,16 +240,7 @@ class InputBuffer: public Buffer { //, public boost::enable_shared_from_this<Inp
 		//	IPAACA_IMPLEMENT_ME
 		//}
 };
-
-/*
-class IUEventFunctionHandler: public rsb::EventFunctionHandler {
-	protected:
-		Buffer* _buffer;
-	public:
-		inline IUEventFunctionHandler(Buffer* buffer, const EventFunction& function, const std::string& method="")
-			: EventFunctionHandler(function, method), _buffer(buffer) { }
-};
-*/
+//}}}
 
 class IUConverter: public rsb::converter::Converter<std::string> {//{{{
 	public:
@@ -514,6 +508,18 @@ class NotImplementedError: public Exception//{{{
 		}
 };//}}}
 
+// (snippets) //{{{
+/*
+class IUEventFunctionHandler: public rsb::EventFunctionHandler {
+	protected:
+		Buffer* _buffer;
+	public:
+		inline IUEventFunctionHandler(Buffer* buffer, const EventFunction& function, const std::string& method="")
+			: EventFunctionHandler(function, method), _buffer(buffer) { }
+};
+*/
+//}}}
+
 } // of namespace ipaaca
 
 #endif
-- 
GitLab