
00001 /* 00002 * Client register - Stores active clients 00003 * 00004 * @Author Michael Matzen <mim@informatik.uni-kiel.de> 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of the GNU General Public License as published by the Free 00008 * Software Foundation; either version 2 of the License, or (at your option) 00009 * any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, but WITHOUT 00012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00014 * more details. 00015 * 00016 * You should have received a copy of the GNU General Public License along with 00017 * this program; if not, write to the Free Software Foundation, Inc., 51 00018 * Franklin St, Fifth Floor, Boston, MA 02110, USA 00019 * 00020 */ 00021 #pragma once 00022 00023 #define _WIN32_WINNT 0x0600 00024 00025 #include <tbb_thread.h> 00026 #include <task_scheduler_init.h> 00027 #include <concurrent_hash_map.h> 00028 #include <concurrent_vector.h> 00029 #include <task.h> 00030 #include <stdio.h> 00031 00032 #include "SraNetworkShared.h" 00033 00034 00035 namespace SraNetwork{ 00036 class ClientRegister 00037 { 00038 //Hash-Map compare function for system addresses. 00039 struct SystemAddressCompare { 00040 //Simple 'hash', we're simply using the binaryaddress, maybe we need somthing better. 00041 static size_t hash( const SystemAddress& a) 00042 { 00043 return a.binaryAddress; 00044 } 00045 //Since the SystemAddress class has a compare function, use this to compare addresses 00046 static bool equal( const SystemAddress& a, const SystemAddress& b) 00047 { 00048 return a == b; 00049 } 00050 }; 00051 00052 private: 00053 ClientRegister(void); 00054 ~ClientRegister(void); 00055 //tbb::concurrent_vector<SraNetwork::SraClientData> clients; 00062 tbb::concurrent_hash_map<SystemAddress, SraClientData, SystemAddressCompare> clientAddressRegister; 00063 // Singleton-instance yea yea singletons are bad and evil but easy to use ;) 00064 static ClientRegister* instance; 00065 00066 00067 //NOTE: Naively removed to ensure it builds in test 00068 //SraData::DbProcedureManager dbManager; 00069 public: 00073 static ClientRegister* getInstance(); 00074 00079 void addClient( SystemAddress address, SraClientData client); 00080 00082 const SraClientData* getClientFromAddress( SystemAddress address); 00083 00085 const SystemAddress* getAddressFromClient( const SraClientData* data); 00086 00088 const SystemAddress* getAddressFromClientID( const int clientID); 00089 00091 void removeClient(const SystemAddress address); 00092 00094 void removeClient( const SraClientData* data); 00095 00104 int loginClient( wchar_t* data, SystemAddress address, int userLen); 00105 private: 00106 int nextID; 00107 }; 00108 }
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.