SmartFoxServer 2X C++ API
SFSUserManager.h
1 // ===================================================================
2 //
3 // Description
4 // Contains the definition of SFSUserManager
5 //
6 // Revision history
7 // Date Description
8 // 30-Nov-2012 First version
9 //
10 // ===================================================================
11 #ifndef __SFSUserManager__
12 #define __SFSUserManager__
13 
14 #include "IUserManager.h"
15 #include "../User.h"
16 #include "../../SmartFox.h"
17 #include "../Room.h"
18 
19 #include <boost/shared_ptr.hpp> // Boost Asio shared pointer
20 
21 #if defined(_MSC_VER)
22 #pragma warning(disable:4786) // STL library: disable warning 4786; this warning is generated due to a Microsoft bug
23 #endif
24 #include <map> // STL library: map object
25 #include <vector> // STL library: vector object
26 #include <string> // STL library: string object
27 using namespace std; // STL library: declare the STL namespace
28 
29 using namespace Sfs2X;
30 using namespace Sfs2X::Entities;
31 using namespace Sfs2X::Logging;
32 
33 namespace Sfs2X {
34 namespace Entities {
35 namespace Managers {
36 
43  class DLLImportExport SFSUserManager : public IUserManager
44  {
45  public:
46 
47  // -------------------------------------------------------------------
48  // Public methods
49  // -------------------------------------------------------------------
50 
51  SFSUserManager(boost::shared_ptr<SmartFox> sfs);
52  SFSUserManager(boost::shared_ptr<Room> room);
53  void Dispose();
54  virtual ~SFSUserManager();
55  bool ContainsUserName(string userName);
56  bool ContainsUserId(long int userId);
57  bool ContainsUser(boost::shared_ptr<User> user);
58  boost::shared_ptr<User> GetUserByName(string userName);
59  boost::shared_ptr<User> GetUserById(long int userId);
60  virtual void AddUser(boost::shared_ptr<User> user);
61  virtual void RemoveUser(boost::shared_ptr<User> user);
62  void RemoveUserById(long int id);
63  long int UserCount();
64  boost::shared_ptr<SmartFox> SmartFoxClient();
65  boost::shared_ptr<vector<boost::shared_ptr<User> > > GetUserList();
66  void ClearAll();
67 
68  // -------------------------------------------------------------------
69  // Public members
70  // -------------------------------------------------------------------
71 
72  protected:
73 
74  // -------------------------------------------------------------------
75  // Protected methods
76  // -------------------------------------------------------------------
77 
78  void LogWarn(boost::shared_ptr<string> msg);
79  void AddUserInternal(boost::shared_ptr<User> user);
80 
81  // -------------------------------------------------------------------
82  // Protected members
83  // -------------------------------------------------------------------
84 
85  boost::shared_ptr<Room> room;
86  boost::shared_ptr<SmartFox> sfs;
87 
88  private:
89 
90  // -------------------------------------------------------------------
91  // Private methods
92  // -------------------------------------------------------------------
93 
94  // -------------------------------------------------------------------
95  // Private members
96  // -------------------------------------------------------------------
97 
98  boost::shared_ptr<map<string, boost::shared_ptr<User> > > usersByName;
99  boost::shared_ptr<map<long int, boost::shared_ptr<User> > > usersById;
100 
101  boost::recursive_mutex lockUsersById;
102  boost::recursive_mutex lockUsersByName;
103  };
104 
105 } // namespace Managers
106 } // namespace Entities
107 } // namespace Sfs2X
108 
109 #endif
Definition: Logger.cpp:14
STL namespace.
Manages the local Users.
Definition: SFSUserManager.h:43
The User Manager interface
Definition: IUserManager.h:45
Definition: Buddy.h:30
Definition: SmartFox.cpp:24