Advertisement

Chicken or the egg with my bind method

Started by March 19, 2015 04:42 AM
1 comment, last by ankhd 9 years, 9 months ago

Hi all.

The design is probably at fault, but humor me. What I have is a class room and a class that holds all the rooms that allows creating or joining a room. That all worked fine until I wanted to remove idle rooms from the Available rooms class using the room it's self by using boost::deadline timer object that when bound with the AvailableRooms call back function, The only way I could get it to work was create a new class cOnIdleRoomHandler that I used in the bind.

Wondering whats the correct way to go about this. But I can't move the AvailableRoom class above Room class and use a forward dec the shared_pointers complain about that.

Here is a cut down version.

.



//----------------------------------------------------------------------------------
//this class is our call back to handle RoomIdleDeadLineTimers
//it marshalls our cAvailableRoomLobbyServer to the room server class
//------------------------------------------------------------------------------------
class cOnIdleRoomHandler
{
public:
	
	//--------------------------------------------------------------------------------------------------------
	//this handles a rooms deadline timer for idle rooms. The rooms id are there names
	//it will find the room and remove it
	//--------------------------------------------------------------------------------------------------------
	virtual void HandleRoomDeadLineTimer(std::string &roomname){}
	

};//end class cOnIdleRoomHandler
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////




class cRoom
{
    cOnIdleRoomHandler *Handler;

  cRoom(cOnIdleRoomHandler *h): Handler(h){}

  void RemoveClient(client &c)
  {
      //do remove then when room empty set the time binding here
      DeadLineIdleRoom.expires_from_now(boost::posix_time::seconds(60));
		
     //set the timer in motion
     DeadLineIdleRoom.async_wait(boost::bind(&cOnIdleRoomHandler::HandleRoomDeadLineTimer, Handler, RoomData.RoomName));

}

};//end cRoom
///////////////////////////////////////////////////////////////////


class cAvailableRooms : public cOnIdleRoomHandler
{

ListOfRooms Rooms;
public:

        //--------------------------------------------------------------------------------------------------------
	//this handles a rooms deadline timer for idle rooms. The rooms id are there names
	//it will find the room and remove it
	//--------------------------------------------------------------------------------------------------------
	virtual void HandleRoomDeadLineTimer(std::string &roomname)
        {
              //remove the room
         }

};//end class







I have no problems compiling your code if I just comment out all symbols from your code that aren't defined. Whatever code you have removed in your post from your actual code is probably hiding the error from us. For example, what shared_pointer are you talking about? There's no such thing in the code you posted. Post actual not-working code.

Advertisement

Hi. Thanks I found the issue it was here

.


void OnDeadLineTimerLoginExpired(const boost::system::error_code& ec, int32_t id)
{
	if(ec)
	 return;//error or cancled called or setting to DeadLine.expires_at(boost::posix_time::pos_infin);


The timer proc gets called it the objects cancled or and that and I had no error checking works fine now.

This was in the cAvailableRoom class the the compiler complained about when I forward declared cRoom

.


class cRoom;

typedef boost::shared_ptr<cRoom> cRoom_Ptr;

cRoom_Ptr newroom = boost::make_shared<cRoom>(ioservice, this);


This topic is closed to new replies.

Advertisement