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