Commits

Kirill Morarenko  committed d90fc06

do not use boost::slots

  • Participants
  • Parent commits 6533fcf

Comments (0)

Files changed (8)

File CMakeLists.txt

 add_subdirectory(tests)
 
 ENABLE_TESTING()
-ADD_TEST(testCleanup tests/testCleanup tests/testApeReconnect)
+ADD_TEST(testCleanup tests/testCleanup)
+ADD_TEST(testApeReconnect tests/testApeReconnect)
+ 

File include/avatar.h

 #include "datalink.h"
 
 #include <boost/noncopyable.hpp>
-#include <boost/signals2/signal.hpp>
+#include <boost/function.hpp>
 
 #include <string>
 
         ~Avatar();
 
 	const std::string& name() const {return name_;}
-
-	void auth();
 	Datalink& dlink() {return dlink_;}
 	AvatarData* data() {return data_;}
 
-	//TODO remove boost::signals2, since we do not concentrate all logic here
-        //slots
-        boost::signals2::signal<void (Avatar&, const std::string&)> onAuth;
+	typedef boost::function<void (Avatar&, const std::string&)> OnAuthCallback;
+	void auth(const OnAuthCallback& cb);
     private:
         Datalink dlink_;
         std::string name_;

File include/avatar_data.h

 
 #include <fwd.h>
 #include <ape.h>
+#include <avatar.h>
 #include <channel.h>
 #include <json/json.h>
 
-#include <boost/signals2/signal.hpp>
-
 #include <string>
 
 namespace chatru{
     class AvatarData{
     public:
-        AvatarData(Avatar& avatar) {}
-	void onAuthCb(const std::string& error, const Json::Value& json);
+        AvatarData(Avatar& avatar) : avatar_(avatar) {}
+	void onAuthCb(const Avatar::OnAuthCallback& cb, const std::string& error, const Json::Value& json);
 
-        boost::signals2::signal<void (const std::string&)> onAuth;
         std::string uticket;
 	ChannelList channels;
 	Ape ape;
+	Avatar& avatar_;
     };    
 }
 #endif

File src/avatar.cpp

 #include <iostream>
 
 namespace chatru{
-    namespace{
-	void onAuth2(Avatar* av, const std::string& error){
-	}
-        void onAuthImpl(Avatar* av, AvatarData* data, const std::string& error){/*
-	    if (error.empty())
-		data->ape.connect(boost::bind(&onAuth2, av, _1));
-		else*/
-		av->onAuth(*av, error);
-        }
-    }
-
     Avatar::Avatar(const std::string& name, const std::string& passwd)
         : dlink_("http://chat4.chat.ru")
         , name_(name)
         , data_(NULL){
 
     }
-    void Avatar::auth(){
+    void Avatar::auth(const OnAuthCallback& cb){
 	if (data_){
 	    delete data_;
 	}
 	data_ = new AvatarData(*this);
-        data_->onAuth.connect(boost::bind(&onAuthImpl, this, data_, _1));
-        jsonGet(*this, std::string("/auth"), FormValue("username", name_)("passwd", passwd_), boost::bind(&AvatarData::onAuthCb, data_, _1, _3));
+        jsonGet(*this, std::string("/auth"), FormValue("username", name_)("passwd", passwd_), boost::bind(&AvatarData::onAuthCb, data_, cb, _1, _3));
     }
 
     Avatar::~Avatar(){

File src/avatar_data.cpp

 //-*- mode: c++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
 #include <avatar_data.h>
 namespace chatru{
-    void AvatarData::onAuthCb(const std::string& error, const Json::Value& json){
+    void AvatarData::onAuthCb(const Avatar::OnAuthCallback& cb, const std::string& error, const Json::Value& json){
 	if (error.empty()){
 	    uticket = json.get("uticket", "").asString();
 	}
-	onAuth(error);
+	cb(boost::ref(avatar_), boost::cref(error));
     }
 }

File tests/apereconnect.cpp

     //timeout, needed to disconnect APE
     chatru::DatalinkManager::set_timeout(wait_time);
     std::cout << "start" << std::endl;
-    g_avatar->auth();
-    g_avatar->onAuth.connect(onAuth);
+    g_avatar->auth(&onAuth);
 
     chatru::DatalinkManager::mainloop(&onIdle);
     

File tests/cleanup.cpp

 int main(){
     chatru::DatalinkManager::set_verbose(false);
     std::cout << "start" << std::endl;
-    g_avatar->auth();
-    g_avatar->onAuth.connect(onAuth);
+    g_avatar->auth(&onAuth);
 
     chatru::DatalinkManager::mainloop(&onIdle);
     

File tests/ctest.cpp

         std::cout << "start" << std::endl;
 	chatru::DatalinkManager::set_verbose(false);
         chatru::Avatar avatar("moriarty_test", "testtesttest");
-	avatar.auth();
-        avatar.onAuth.connect(onAuth);
+	avatar.auth(&onAuth);
 
         chatru::DatalinkManager::mainloop();
         std::cout << "mainlooped" << std::endl;