├── .gitattributes ├── .gitignore ├── README.md └── zertco5 ├── .cproject ├── .project ├── .settings ├── org.eclipse.core.resources.prefs └── org.eclipse.core.runtime.prefs ├── GenCPP.py ├── SConstruct ├── concurrent ├── Concurrent.cpp ├── Concurrent.h ├── ConcurrentState.cpp ├── ConcurrentState.h ├── config.h ├── coroutine │ ├── Coroutine.cpp │ ├── Coroutine.h │ └── config.h ├── rpc │ ├── RPC.h │ ├── RPCClient.h │ ├── RPCClientConnection.cpp │ ├── RPCConnection.h │ ├── RPCHandlers.cpp │ ├── RPCHelper.hpp │ ├── RPCManager.cpp │ ├── RPCManager.h │ ├── RPCRouter.cpp │ ├── RPCRouter.h │ ├── RPCRouterClient.cpp │ ├── RPCRouterClient.h │ ├── RPCRouterManager.h │ ├── RPCServer.h │ ├── RPCServerConnection.cpp │ ├── RPCSpec.cpp │ ├── RPCSpec.h │ ├── config.h │ ├── details │ │ ├── RPCDataProvider.h │ │ ├── RPCFetcher.cpp │ │ ├── RPCFetcher.h │ │ └── RPCHelper.hpp │ ├── sys_cmd.cpp │ └── sys_cmd.h └── update │ ├── UpdateClient.cpp │ ├── UpdateClient.h │ ├── UpdateServer.cpp │ ├── UpdateServer.h │ └── config.h ├── config ├── Config.cpp └── Config.h ├── core ├── Runtime.cpp ├── Runtime.h ├── RuntimeContext.cpp └── RuntimeContext.h ├── db ├── Database.h ├── DatabaseInterface.h ├── DatabaseInterfaceManager.h ├── Query.h ├── details │ └── DatabaseInterfaceImpl.hpp ├── io │ ├── DataProvider.h │ └── DataProviderManager.h └── mongodb │ ├── MongoDBAdapter.cpp │ ├── MongoDBAdapter.h │ ├── MongoDBCursor.cpp │ ├── MongoDBCursor.h │ ├── MongoDBQuery.h │ ├── config.h │ ├── details │ └── MongoDBDataProvider.h │ └── serialize │ ├── BSONStream.cpp │ └── BSONStream.h ├── details.h ├── game_configbase_sample.json ├── gch.py ├── log ├── Log.cpp └── Log.h ├── main ├── GameBase.h ├── SConscript ├── details │ └── GameBaseImpl.hpp └── router_main.cpp ├── net ├── client │ ├── ClientBase.h │ ├── config.h │ └── details │ │ └── ClientBaseDetails.hpp ├── config.h ├── details │ ├── ConnectionBaseDetails.hpp │ ├── IOServiceDetails.hpp │ ├── PersistConnectionDetails.hpp │ └── SSLConnectionBaseDetails.hpp ├── server_config.h ├── tcp │ ├── ConnectionBase.h │ ├── IOService.h │ ├── PersistConnection.h │ ├── client │ │ ├── ClientBase.h │ │ ├── config.h │ │ └── details │ │ │ └── ClientBaseDetails.hpp │ ├── config.h │ ├── details │ │ ├── ConnectionBaseDetails.hpp │ │ ├── IOServiceDetails.hpp │ │ ├── PersistConnectionDetails.hpp │ │ └── SSLConnectionBaseDetails.hpp │ └── server │ │ ├── ServerBase.h │ │ ├── config.h │ │ └── details │ │ └── ServerBaseDetails.hpp └── udp │ ├── ConnectionBase.h │ ├── PackageConnection.h │ ├── ServerBase.h │ ├── config.h │ └── details │ ├── ConnectionBaseDetails.hpp │ ├── PackageConnectionDetails.hpp │ └── ServerBaseDetails.hpp ├── object ├── ActiveObject.h ├── ActiveObjectManager.h ├── ActiveObjectTraits.h ├── ObjectBase.h ├── ObjectTraits.h ├── PoolObject.h ├── SConscript ├── WorldObject.h ├── WorldObjectManager.h └── details │ ├── ActiveObjectImpl.hpp │ ├── ActiveObjectManagerImpl.hpp │ ├── PoolObjectDetails.hpp │ └── WorldObjectManagerImpl.hpp ├── pch.h ├── serialize ├── Archiver.h ├── SConscript ├── Serializer.h ├── Serializer_fwd.h ├── Unserializer.h ├── Unserializer_fwd.h ├── config.h └── details │ ├── SerializerSTLDetails.hpp │ └── UnserializerSTLDetails.hpp ├── suit ├── buff │ ├── Buff.cpp │ ├── Buff.h │ └── BuffCeptor.cpp ├── event │ ├── Event.h │ ├── EventBus.h │ ├── EventHandler.h │ └── details │ │ ├── EventBusImpl.hpp │ │ └── EventHandlerImpl.hpp ├── location │ └── geometric.h ├── period32 │ ├── period.h │ └── period32.cpp ├── session │ ├── Session.h │ └── details │ │ ├── CommandImpl.hpp │ │ ├── SessionImpl.hpp │ │ └── SessionManagerImpl.hpp ├── skill │ └── Skill.h └── utils │ ├── RateValue.cpp │ └── RateValue.h ├── test ├── buffer │ ├── mem_test1.cpp │ └── test1.cpp ├── circular_buffer_test1.cpp ├── concurrent │ ├── context.cpp │ ├── context2.cpp │ ├── context3.cpp │ ├── rpc_test1.cpp │ ├── test1.cpp │ └── test_perf1.cpp ├── database │ └── test1.cpp ├── encrypt │ └── test1.cpp ├── event │ └── e1.cpp ├── http │ ├── server.cpp │ ├── test1.cpp │ └── test2.cpp ├── log │ └── test1.cpp ├── msgpack-test1.cpp ├── msgpack-test2.cpp ├── net │ ├── client │ │ ├── cli.cpp │ │ └── client.cpp │ ├── enet │ │ └── test1.cpp │ ├── server │ │ ├── backgate_server.cpp │ │ ├── gate_server.cpp │ │ └── http_test1.cpp │ └── udp │ │ ├── cli.cpp │ │ ├── client1.cpp │ │ ├── client_bench.cpp │ │ └── test1.cpp ├── object │ ├── test1.cpp │ └── test2.cpp ├── practice │ ├── plot1.cpp │ ├── spin_test1.cpp │ ├── test1.cpp │ ├── test2.cpp │ ├── test3.cpp │ ├── test4.cpp │ ├── test5.cpp │ ├── test6.cpp │ ├── test7.cpp │ └── test8.cpp ├── rpc │ ├── cond_test1.cpp │ ├── test1.cpp │ ├── test2.cpp │ ├── test3.cpp │ └── update1.cpp ├── serialize │ ├── bsonstream_test1.cpp │ ├── bsonstream_test2.cpp │ ├── msgpack_test1.cpp │ ├── serialize_object_test1.cpp │ ├── simple-bson-input.cpp │ ├── simple-bson-output.cpp │ ├── test1.cpp │ └── test2.cpp └── utils │ └── tags_map_test1.cpp ├── third_parties ├── enet │ ├── callbacks.h │ ├── enet.h │ ├── list.h │ ├── protocol.h │ ├── time.h │ ├── types.h │ ├── unix.h │ ├── utility.h │ └── win32.h ├── msgpack.h ├── msgpack.hpp ├── msgpack │ ├── adaptor │ │ ├── bool.hpp │ │ ├── bool_fwd.hpp │ │ ├── char_ptr.hpp │ │ ├── char_ptr_fwd.hpp │ │ ├── cpp11 │ │ │ ├── array.hpp │ │ │ ├── array_char.hpp │ │ │ ├── array_char_fwd.hpp │ │ │ ├── array_fwd.hpp │ │ │ ├── forward_list.hpp │ │ │ ├── forward_list_fwd.hpp │ │ │ ├── tuple.hpp │ │ │ ├── tuple_fwd.hpp │ │ │ ├── unordered_map.hpp │ │ │ ├── unordered_map_fwd.hpp │ │ │ ├── unordered_set.hpp │ │ │ └── unordered_set_fwd.hpp │ │ ├── define.hpp │ │ ├── deque.hpp │ │ ├── deque_fwd.hpp │ │ ├── detail │ │ │ ├── cpp03_define.hpp │ │ │ ├── cpp03_msgpack_tuple.hpp │ │ │ ├── cpp03_msgpack_tuple_fwd.hpp │ │ │ ├── cpp11_define.hpp │ │ │ ├── cpp11_msgpack_tuple.hpp │ │ │ └── cpp11_msgpack_tuple_fwd.hpp │ │ ├── fixint.hpp │ │ ├── fixint_fwd.hpp │ │ ├── float.hpp │ │ ├── float_fwd.hpp │ │ ├── int.hpp │ │ ├── int_fwd.hpp │ │ ├── list.hpp │ │ ├── list_fwd.hpp │ │ ├── map.hpp │ │ ├── map_fwd.hpp │ │ ├── msgpack_tuple.hpp │ │ ├── msgpack_tuple_fwd.hpp │ │ ├── nil.hpp │ │ ├── nil_fwd.hpp │ │ ├── pair.hpp │ │ ├── pair_fwd.hpp │ │ ├── raw.hpp │ │ ├── raw_fwd.hpp │ │ ├── set.hpp │ │ ├── set_fwd.hpp │ │ ├── string.hpp │ │ ├── string_fwd.hpp │ │ ├── tr1 │ │ │ ├── unordered_map.hpp │ │ │ ├── unordered_map_fwd.hpp │ │ │ ├── unordered_set.hpp │ │ │ └── unordered_set_fwd.hpp │ │ ├── vector.hpp │ │ ├── vector_char.hpp │ │ ├── vector_char_fwd.hpp │ │ └── vector_fwd.hpp │ ├── cpp_config.hpp │ ├── detail │ │ ├── cpp03_zone.hpp │ │ └── cpp11_zone.hpp │ ├── fbuffer.h │ ├── fbuffer.hpp │ ├── gcc_atomic.h │ ├── object.h │ ├── object.hpp │ ├── object_fwd.hpp │ ├── pack.h │ ├── pack.hpp │ ├── pack_define.h │ ├── pack_template.h │ ├── sbuffer.h │ ├── sbuffer.hpp │ ├── sysdep.h │ ├── type.hpp │ ├── unpack.h │ ├── unpack.hpp │ ├── unpack_define.h │ ├── unpack_template.h │ ├── util.h │ ├── version.h │ ├── version.hpp │ ├── version_master.h │ ├── versioning.hpp │ ├── vrefbuffer.h │ ├── vrefbuffer.hpp │ ├── zbuffer.h │ ├── zbuffer.hpp │ ├── zone.h │ └── zone.hpp ├── msgpack_fwd.hpp └── rapidjson │ ├── allocators.h │ ├── document.h │ ├── encodedstream.h │ ├── encodings.h │ ├── error │ ├── en.h │ └── error.h │ ├── filereadstream.h │ ├── filewritestream.h │ ├── internal │ ├── biginteger.h │ ├── diyfp.h │ ├── dtoa.h │ ├── ieee754.h │ ├── itoa.h │ ├── meta.h │ ├── pow10.h │ ├── stack.h │ ├── strfunc.h │ └── strtod.h │ ├── memorybuffer.h │ ├── memorystream.h │ ├── msinttypes │ ├── inttypes.h │ └── stdint.h │ ├── pointer.h │ ├── prettywriter.h │ ├── rapidjson.h │ ├── reader.h │ ├── stringbuffer.h │ └── writer.h ├── thread ├── SConscript ├── Thread.cpp ├── Thread.h ├── ThreadHandler.h ├── ThreadHandlerSet.h ├── ThreadLocal.h ├── ThreadPool.cpp ├── ThreadPool.h ├── ThreadSingleton.h ├── config.h └── details │ ├── RWLock.hpp │ ├── ThreadHandlerDetails.hpp │ ├── ThreadHandlerSetDetails.hpp │ ├── ThreadSingletonDetails.hpp │ └── ThreadSingletonImpl.hpp ├── todo.txt ├── utils ├── ExpiredObjectMap.h ├── Params.h ├── SConscript ├── Singleton.h ├── buffer │ ├── MemoryPool.h │ ├── SharedBuffer.cpp │ ├── SharedBuffer.h │ └── details │ │ ├── MemoryAllocator.h │ │ └── SharedBufferSerialization.hpp ├── collision │ ├── DoubleTiles.h │ └── QuadTree.h ├── condition │ ├── BasicValue.h │ ├── Condition.h │ ├── KeysHolder.h │ └── details │ │ └── ConditionDetails.hpp ├── crypto │ ├── Crypto.cpp │ └── Crypto.h ├── details │ ├── errors.hpp │ ├── null.hpp │ └── types.hpp ├── file │ ├── FileManager.cpp │ └── FileManager.h ├── group │ └── Group.h ├── http │ ├── HttpClient.cpp │ ├── HttpClient.h │ ├── HttpClientConnection.cpp │ ├── HttpConnection.h │ ├── HttpRequest.cpp │ ├── HttpRequest.h │ ├── HttpResponse.cpp │ ├── HttpResponse.h │ ├── HttpServer.cpp │ ├── HttpServer.h │ ├── HttpServerConnection.cpp │ └── readme.txt ├── msgpack │ ├── MsgPackStream.cpp │ ├── MsgPackStream.h │ ├── msgpack_stream_intend.cpp │ └── msgpack_stream_intend.h ├── perf │ ├── Performance.cpp │ └── Performance.h ├── random │ ├── Random.cpp │ └── Random.h ├── rapidjson │ ├── RapidJsonStream.cppt │ └── RapidJsonStream.h ├── serializable │ ├── SerializableObject.h │ └── SerializeValues.hpp ├── simplehttp │ ├── CookieParser.cpp │ ├── HttpParser.cpp │ ├── HttpParser.h │ ├── HttpResponse.cpp │ ├── HttpResponse.h │ ├── HttpServer.cpp │ ├── HttpServer.h │ ├── QueryParser.cpp │ ├── ServerConnection.cpp │ ├── ServerConnection.h │ ├── utils.cpp │ └── utils.h ├── spinlock │ └── SpinLock.h ├── string │ ├── KeyString.cpp │ └── KeyString.h ├── sys │ └── System.h ├── tags │ ├── TagsValue.h │ └── details │ │ └── Tags.h ├── time │ ├── CPUTime.cpp │ ├── CPUTime.h │ ├── Tick.cpp │ ├── Tick.h │ ├── TimeType.cpp │ ├── TimeType.h │ ├── Timer.cpp │ ├── Timer.h │ ├── TimerManager.cpp │ ├── TimerManager.h │ └── details │ │ ├── TickTypeSerialization.hpp │ │ └── TimeTypeSerialization.hpp ├── tools │ ├── SameThreadChecker.cpp │ └── SameThreadChecker.h ├── types.cpp ├── types.h ├── updatelist │ ├── DynamicList.h │ └── UpdateList.h └── uuid │ ├── UUIDGenerator.cpp │ └── UUIDGenerator.h └── zertcore.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # ========================= 18 | # Operating System Files 19 | # ========================= 20 | 21 | # OSX 22 | # ========================= 23 | 24 | .DS_Store 25 | .AppleDouble 26 | .LSOverride 27 | 28 | # Icon must end with two \r 29 | Icon 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | 45 | #eclipse files 46 | .settings/ 47 | .cproject 48 | .project 49 | 50 | -------------------------------------------------------------------------------- /zertco5/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | zertco5 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /zertco5/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /zertco5/.settings/org.eclipse.core.runtime.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | line.separator=\n 3 | -------------------------------------------------------------------------------- /zertco5/concurrent/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ConcurrentConfig.h 3 | * 4 | * Created on: 2014��11��22�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_CONCURRENT_CONFIG_H_ 9 | #define ZERTCORE_CONCURRENT_CONFIG_H_ 10 | 11 | #include 12 | #include 13 | 14 | // #define ZC_ENABLE_THREADHANDLER_MULTICAST 15 | 16 | namespace zertcore { namespace concurrent { 17 | 18 | /** 19 | * ConcurrentConfig 20 | */ 21 | struct ConcurrentConfig 22 | { 23 | u32 thread_nums{0}; 24 | }; 25 | 26 | #ifdef ZC_ENABLE_THREADHANDLER_MULTICAST 27 | typedef dynamic_bitset<> thread_ids_flag_type; 28 | #else 29 | typedef tid_type thread_ids_flag_type; 30 | #endif 31 | 32 | namespace details { 33 | /** 34 | typedef ::boost::thread::id thread_id_type; 35 | 36 | 37 | * ThreadIndex 38 | 39 | struct ThreadIndex 40 | { 41 | thread_id_type index; 42 | 43 | explicit ThreadIndex() { 44 | index = this_thread::get_id(); 45 | } 46 | explicit ThreadIndex(const thread_id_type& i) : index(i) {} 47 | explicit ThreadIndex(const ThreadIndex& ti) : index(ti.index) {} 48 | 49 | ThreadIndex& operator= (thread_id_type i) { 50 | index = i; 51 | return *this; 52 | } 53 | }; 54 | */ 55 | } 56 | 57 | }} 58 | 59 | /** 60 | namespace zertcore { namespace concurrent{ 61 | typedef details::ThreadIndex thread_index_type; 62 | }} 63 | */ 64 | 65 | namespace zertcore { namespace concurrent { 66 | }} 67 | 68 | #endif /* CONCURRENTCONFIG_H_ */ 69 | -------------------------------------------------------------------------------- /zertco5/concurrent/coroutine/Coroutine.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Coroutine.cpp 3 | * 4 | * Created on: 2015年7月31日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "Coroutine.h" 9 | 10 | namespace zertcore { namespace concurrent { namespace co { 11 | 12 | FCell::ptr FCell:: 13 | create() { 14 | return new FCell; 15 | } 16 | 17 | void FCell:: 18 | release() { 19 | delete this; 20 | } 21 | 22 | }}} 23 | 24 | namespace zertcore { namespace concurrent { 25 | 26 | bool Coroutine:: 27 | make(co::FCell::ptr cell, void (*f)(co::FCell::ptr, void *), co::FCell::ptr fc, void * params) { 28 | if (!cell) return false; 29 | 30 | ZC_ASSERT(-1 != getcontext(&cell->context)); 31 | cell->context.uc_stack.ss_sp = cell->buffer; 32 | cell->context.uc_stack.ss_size = ZC_COROUTINE_BUFFER; 33 | cell->context.uc_link = ¤t_ctx_; 34 | 35 | makecontext(&cell->context, (void (*)())f, 2, fc, params); 36 | return true; 37 | } 38 | 39 | bool Coroutine:: 40 | make(co::FCell::ptr cell) { 41 | if (!cell) return false; 42 | 43 | ZC_ASSERT(-1 != getcontext(&cell->context)); 44 | cell->context.uc_stack.ss_sp = cell->buffer; 45 | cell->context.uc_stack.ss_size = ZC_COROUTINE_BUFFER; 46 | cell->context.uc_link = ¤t_ctx_; 47 | 48 | return true; 49 | } 50 | 51 | void Coroutine:: 52 | jumpTo(co::FCell::ptr current) { 53 | ZC_ASSERT(-1 != swapcontext(¤t_ctx_, ¤t->context)); 54 | } 55 | 56 | void Coroutine:: 57 | jumpBack(co::FCell::ptr current) { 58 | current->flag = true; 59 | ZC_ASSERT(-1 != swapcontext(¤t->context, ¤t_ctx_)); 60 | } 61 | 62 | }} 63 | 64 | -------------------------------------------------------------------------------- /zertco5/concurrent/coroutine/Coroutine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Coroutine.h 3 | * 4 | * Created on: 2015年7月31日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_CONCURRENT_COROUTINE_COROUTINE_H_ 9 | #define ZERTCORE_CONCURRENT_COROUTINE_COROUTINE_H_ 10 | 11 | #include 12 | #include "config.h" 13 | 14 | namespace zertcore { namespace concurrent { 15 | using namespace zertcore::object; 16 | }} 17 | 18 | namespace zertcore { namespace concurrent { 19 | 20 | /** 21 | * Coroutine 22 | */ 23 | class Coroutine : 24 | public ThreadSingleton 25 | { 26 | public: 27 | bool make(co::FCell::ptr cell, void (*)(co::FCell::ptr, void *), co::FCell::ptr, void * params); 28 | bool make(co::FCell::ptr cell); 29 | 30 | public: 31 | void jumpTo(co::FCell::ptr current); 32 | void jumpBack(co::FCell::ptr current); 33 | 34 | public: 35 | co::FCell::ptr getLastFCell() {return last_fc_;} 36 | void setLastFCell(co::FCell::ptr fc) {last_fc_ = fc;} 37 | 38 | private: 39 | co::context_type current_ctx_; 40 | co::FCell::ptr last_fc_; 41 | }; 42 | 43 | }} 44 | 45 | 46 | #endif /* CONCURRENT_COROUTINE_COROUTINE_H_ */ 47 | -------------------------------------------------------------------------------- /zertco5/concurrent/coroutine/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | * Created on: 2015年7月31日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_CONCURRENT_COROUTINE_CONFIG_H_ 9 | #define ZERTCORE_CONCURRENT_COROUTINE_CONFIG_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #ifndef ZC_COROUTINE_BUFFER 16 | # define ZC_COROUTINE_BUFFER 81920 17 | #endif 18 | 19 | namespace zertcore { namespace concurrent { namespace co { 20 | using namespace zertcore::object; 21 | 22 | typedef ucontext_t context_type; 23 | 24 | struct FCell 25 | { 26 | typedef FCell* ptr; 27 | 28 | static ptr create(); 29 | void release(); 30 | 31 | context_type context; 32 | byte buffer[ZC_COROUTINE_BUFFER]; 33 | 34 | bool flag{false}; 35 | bool finished{false}; 36 | 37 | operator bool () const { return flag; } 38 | }; 39 | struct Cell 40 | { 41 | context_type context; 42 | bool flag{false}; 43 | 44 | operator bool () const { return flag; } 45 | }; 46 | 47 | }}} 48 | 49 | namespace zertcore { 50 | 51 | typedef concurrent::co::Cell cocell_type; 52 | typedef concurrent::co::FCell cofcell_type; 53 | 54 | } 55 | 56 | 57 | #endif /* CONCURRENT_COROUTINE_CONFIG_H_ */ 58 | -------------------------------------------------------------------------------- /zertco5/concurrent/rpc/RPCClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | * RPCClient.h 3 | * 4 | * Created on: 2015年1月27日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_RPCCLIENT_H_ 9 | #define ZERTCORE_RPCCLIENT_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "config.h" 16 | #include "RPCConnection.h" 17 | 18 | namespace zertcore { namespace concurrent { namespace rpc { 19 | using namespace zertcore::net::tcp::client; 20 | using namespace zertcore::utils; 21 | }}} 22 | 23 | namespace zertcore { namespace concurrent { namespace rpc { 24 | 25 | /** 26 | * RPCClient 27 | */ 28 | class RPCClient : 29 | public ClientBase, 30 | public Singleton 31 | { 32 | public: 33 | RPCClient() : ClientBase() {} 34 | virtual ~RPCClient() {} 35 | }; 36 | 37 | }}} 38 | 39 | 40 | #endif /* RPCCLIENT_H_ */ 41 | -------------------------------------------------------------------------------- /zertco5/concurrent/rpc/RPCClientConnection.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * RPCClientConnection.cpp 3 | * 4 | * Created on: 2015年2月4日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "RPCConnection.h" 9 | #include "RPCClient.h" 10 | #include "RPCSpec.h" 11 | 12 | #include 13 | 14 | namespace zertcore { namespace concurrent { namespace rpc { 15 | 16 | RPCClientConnection::RPCClientConnection(RPCClient& service) : 17 | PersistConnection(service) { 18 | ; 19 | } 20 | 21 | }}} 22 | -------------------------------------------------------------------------------- /zertco5/concurrent/rpc/RPCHelper.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * RPCHelper.hpp 3 | * 4 | * Created on: 2015年2月1日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_RPCHELPER_HPP_ 9 | #define ZERTCORE_RPCHELPER_HPP_ 10 | 11 | #include "config.h" 12 | 13 | namespace zertcore { namespace concurrent { namespace rpc { 14 | 15 | /** 16 | * DataSync Template 17 | */ 18 | template , T>, T>::type> 19 | struct DataSync 20 | { 21 | T& data; 22 | 23 | explicit DataSync(T& target) : data(target) {} 24 | void operator () (const key_type& key, const oachiver_type& params) { 25 | data.unserialize(params); 26 | } 27 | }; 28 | 29 | }}} 30 | 31 | 32 | #endif /* RPCHELPER_HPP_ */ 33 | -------------------------------------------------------------------------------- /zertco5/concurrent/rpc/RPCRouter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * RPCRouter.h 3 | * 4 | * Created on: 2015年1月27日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_RPCROUTER_H_ 9 | #define ZERTCORE_RPCROUTER_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include "config.h" 15 | #include "RPCServer.h" 16 | #include "RPCClient.h" 17 | 18 | namespace zertcore { namespace concurrent { namespace rpc { 19 | 20 | /** 21 | * RPCRouter 22 | * Mid layer for RPC framework 23 | * Distribute the server & client info 24 | * check the healthy of each client 25 | */ 26 | class RPCRouter 27 | { 28 | public: 29 | typedef unordered_map 30 | conn_map_type; 31 | 32 | enum { 33 | TIMEOUT = 100, 34 | }; 35 | 36 | public: 37 | RPCRouter(); 38 | 39 | public: 40 | bool globalInit(); 41 | 42 | private: 43 | void SyncServer(key_type, oarchiver_type params, iarchiver_type& ret_data); 44 | void SyncClient(key_type, oarchiver_type params, iarchiver_type& ret_data); 45 | 46 | private: 47 | void SyncData(); 48 | 49 | private: 50 | void onConnectionClose(RPCClientConnection::ptr conn); 51 | 52 | private: 53 | RPCServer server_; 54 | 55 | private: 56 | unordered_map 57 | svr_info_map_; 58 | unordered_map 59 | cli_info_map_; 60 | 61 | private: 62 | conn_map_type conn_map_; 63 | 64 | private: 65 | uuid_t id_counter_; 66 | }; 67 | 68 | }}} 69 | 70 | #endif /* RPCROUTER_H_ */ 71 | -------------------------------------------------------------------------------- /zertco5/concurrent/rpc/RPCServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * RPCServer.h 3 | * 4 | * Created on: 2015��1��22�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_RPCSERVER_H_ 9 | #define ZERTCORE_RPCSERVER_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include "config.h" 15 | #include "RPCConnection.h" 16 | 17 | namespace zertcore { namespace concurrent { namespace rpc { 18 | using namespace zertcore::net::tcp::server; 19 | }}} 20 | 21 | namespace zertcore { namespace concurrent { namespace rpc { 22 | 23 | /** 24 | * RPCServer 25 | */ 26 | class RPCServer : 27 | public ServerBase 28 | { 29 | public: 30 | enum { 31 | TYPE_NONE = 0, 32 | TYPE_SERVER = 1, 33 | TYPE_DATASYNC = 2, 34 | }; 35 | 36 | public: 37 | RPCServer() : ServerBase(), type_(TYPE_NONE) {} 38 | 39 | public: 40 | void setType(const u32& type) { 41 | type_ = type; 42 | } 43 | 44 | bool isServer() const {return type_ == TYPE_SERVER;} 45 | bool isDataSync() const {return type_ == TYPE_DATASYNC;} 46 | 47 | private: 48 | u32 type_; 49 | }; 50 | 51 | /** 52 | * RPC.registerHandler("echo", [](const key_type&, const oachiver_type& params, iachiver_type& ret_data) -> void { 53 | * string text; 54 | * params["text"] & text; 55 | * ret_data["text"] & text; 56 | * 57 | * return; 58 | * }); 59 | */ 60 | 61 | }}} 62 | 63 | 64 | #endif /* RPCSERVER_H_ */ 65 | -------------------------------------------------------------------------------- /zertco5/concurrent/rpc/RPCServerConnection.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * RPCConnection.cpp 3 | * 4 | * Created on: 2015年1月31日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "RPCConnection.h" 9 | #include "RPCServer.h" 10 | #include "RPCSpec.h" 11 | 12 | #include 13 | 14 | namespace zertcore { namespace concurrent { namespace rpc { 15 | 16 | RPCServerConnection::RPCServerConnection(RPCServer& server) : 17 | PersistConnection(server) { 18 | // TODO Auto-generated constructor stub 19 | 20 | } 21 | 22 | RPCServerConnection::~RPCServerConnection() { 23 | ::printf("~RPCServerConnection()\n"); 24 | } 25 | 26 | void RPCServerConnection:: 27 | onPackage(const SharedBuffer& buffer) { 28 | 29 | } 30 | 31 | } /* namespace rpc */ } /* namespace concurrent */ } /* namespace zertcore */ 32 | -------------------------------------------------------------------------------- /zertco5/concurrent/rpc/details/RPCHelper.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * RPCHelper.hpp 3 | * 4 | * Created on: 2015年2月1日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_RPCHELPER_HPP_ 9 | #define ZERTCORE_RPCHELPER_HPP_ 10 | 11 | #include "../config.h" 12 | #include "../RPC.h" 13 | 14 | namespace zertcore { namespace concurrent { namespace rpc { 15 | 16 | /** 17 | * DataSync Template 18 | */ 19 | template , T>::value, T, void>::type> 20 | struct DataSync 21 | { 22 | T& data; 23 | 24 | explicit DataSync(T& target) : data(target) {;} 25 | void operator () (key_type key, oarchiver_type params) { 26 | data.unserialize(params); 27 | } 28 | }; 29 | 30 | template 31 | inline bool static registerDataSync(const key_type& key, T& target) { 32 | DataSync handler(target); 33 | return RPC.registerDataSyncHandler(key, bind(handler, _1, _2)); 34 | } 35 | 36 | }}} 37 | 38 | 39 | #endif /* RPCHELPER_HPP_ */ 40 | -------------------------------------------------------------------------------- /zertco5/concurrent/rpc/sys_cmd.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * sys_cmd.cpp 3 | * 4 | * Created on: 2015年3月11日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "sys_cmd.h" 9 | 10 | namespace zertcore { namespace concurrent { namespace rpc { namespace cmd { 11 | 12 | const char* REG_RPC_SYNC = "*syn"; 13 | const char* REG_RPC_SYNC_SERVER = "*synsvr"; 14 | const char* REG_RPC_SYNC_CLIENT = "*syncli"; 15 | 16 | const char* UPDATE = "*update"; 17 | const char* CONFIG = "*config"; 18 | }}}} 19 | 20 | -------------------------------------------------------------------------------- /zertco5/concurrent/rpc/sys_cmd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sys_cmd.h 3 | * 4 | * Created on: 2015年3月3日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_CONCURRENT_RPC_SYS_CMD_H_ 9 | #define ZERTCORE_CONCURRENT_RPC_SYS_CMD_H_ 10 | 11 | namespace zertcore { namespace concurrent { namespace rpc { namespace cmd { 12 | 13 | extern const char* REG_RPC_SYNC; 14 | extern const char* REG_RPC_SYNC_SERVER; 15 | extern const char* REG_RPC_SYNC_CLIENT; 16 | 17 | extern const char* UPDATE; 18 | extern const char* CONFIG; 19 | 20 | }}}} 21 | 22 | 23 | #endif /* CONCURRENT_RPC_SYS_CMD_H_ */ 24 | -------------------------------------------------------------------------------- /zertco5/concurrent/update/UpdateClient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * UpdateClient.cpp 3 | * 4 | * Created on: 2015年5月7日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "UpdateClient.h" 9 | #include "../rpc/RPCManager.h" 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { namespace concurrent { namespace update { 15 | using namespace zertcore::concurrent::rpc; 16 | }}} 17 | 18 | namespace zertcore { namespace concurrent { namespace update { 19 | 20 | bool UpdateClient:: 21 | globalInit() { 22 | RT.initHandler([this] () { 23 | enabled_ = true; 24 | 25 | if(!RPCManager::Instance().registerRPCHandler(cmd::UPDATE, 26 | bind(&UpdateClient::cbUpdateOnce, this, _1, _2, _3))) 27 | ZCLOG(FATAL) << "Register Updater Client failed" << End; 28 | }); 29 | 30 | return true; 31 | } 32 | 33 | void UpdateClient:: 34 | cbUpdateOnce(rpc::key_type key, rpc::oarchiver_type params, 35 | rpc::iarchiver_type& ret_data) { 36 | u32 count; 37 | ZC_ASSERT( params["count"] & count ); 38 | 39 | for_each(updater_list_.begin(), updater_list_.end(), [&] (updater_type& handler) { 40 | handler.setParams(count); 41 | ZC_ASSERT( Concurrent::Instance().add(handler, concurrentState()) ); 42 | }); 43 | } 44 | 45 | UpdateClient::updater_key_type UpdateClient:: 46 | registerHandler(const updater_type& handler) { 47 | if (!enabled_) { 48 | ZCLOG(FATAL) << "Update Client was not enabled." << End; 49 | } 50 | return updater_list_.insert(updater_list_.end(), handler); 51 | } 52 | 53 | void UpdateClient:: 54 | unregisterHandler(updater_key_type key) { 55 | updater_list_.erase(key); 56 | } 57 | 58 | }}} 59 | 60 | -------------------------------------------------------------------------------- /zertco5/concurrent/update/UpdateClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TickerClient.h 3 | * 4 | * Created on: 2015年5月7日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_CONCURRENT_UPDATE_UPDATECLIENT_H_ 9 | #define ZERTCORE_CONCURRENT_UPDATE_UPDATECLIENT_H_ 10 | 11 | #include "config.h" 12 | 13 | #include 14 | 15 | namespace zertcore { namespace concurrent { namespace update { 16 | using namespace zertcore::utils; 17 | }}} 18 | 19 | namespace zertcore { namespace concurrent { namespace update { 20 | 21 | /** 22 | * UpdateClient 23 | */ 24 | class UpdateClient : 25 | public Singleton 26 | { 27 | public: 28 | typedef list updater_list_type; 29 | typedef updater_list_type::iterator updater_key_type; 30 | 31 | public: 32 | bool globalInit(); 33 | bool isEnabled() const {return enabled_;} 34 | 35 | public: 36 | updater_key_type registerHandler(const updater_type& handler); 37 | void unregisterHandler(updater_key_type key); 38 | 39 | private: 40 | void cbUpdateOnce(rpc::key_type key, rpc::oarchiver_type params, 41 | rpc::iarchiver_type& ret_data); 42 | 43 | private: 44 | list updater_list_; 45 | bool enabled_{false}; 46 | }; 47 | 48 | }}} 49 | 50 | 51 | #endif /* CONCURRENT_TICK_TICKERCLIENT_H_ */ 52 | -------------------------------------------------------------------------------- /zertco5/concurrent/update/UpdateServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ticker.h 3 | * 4 | * Created on: 2015年4月30日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_CONCURRENT_TICK_TICKER_H_ 9 | #define ZERTCORE_CONCURRENT_TICK_TICKER_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "config.h" 17 | #include "../Concurrent.h" 18 | 19 | namespace zertcore { namespace concurrent { namespace update { 20 | using namespace zertcore::utils; 21 | }}} 22 | 23 | namespace zertcore { namespace concurrent { namespace update { 24 | 25 | /** 26 | * UpdateManager 27 | */ 28 | class UpdateServer : 29 | public Singleton 30 | { 31 | public: 32 | UpdateServer(); 33 | 34 | public: 35 | bool globalInit(const UpdateConfig& uc); 36 | 37 | public: 38 | bool start(); 39 | bool tickOnce(); 40 | 41 | public: 42 | void setInterval(const tick_type& interval) { 43 | interval_ = interval; 44 | } 45 | tick_type getInterval() const { 46 | return interval_; 47 | } 48 | 49 | public: 50 | void printStatus(); 51 | 52 | private: 53 | void cbTimer(const tick_type& tick); 54 | void cbTick(RuntimeContext::ptr); 55 | 56 | private: 57 | ConcurrentState::ptr state_; 58 | u32 counter_; 59 | 60 | private: 61 | tick_type interval_; 62 | timer_type timer_; 63 | }; 64 | 65 | }}} 66 | 67 | 68 | #endif /* CONCURRENT_TICK_TICKER_H_ */ 69 | -------------------------------------------------------------------------------- /zertco5/concurrent/update/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | * Created on: 2015年4月25日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_CONCURRENT_TICK_CONFIG_H_ 9 | #define ZERTCORE_CONCURRENT_TICK_CONFIG_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include "../Concurrent.h" 17 | 18 | /** 19 | * Main goal of tick was concurrent 20 | */ 21 | 22 | namespace zertcore { namespace concurrent { namespace update { 23 | 24 | typedef ThreadHandler updater_type; 25 | 26 | /** 27 | * UpdateConfig 28 | */ 29 | struct UpdateConfig : 30 | Unserializable, Serializable 31 | { 32 | tick_type interval; 33 | RemoteConfig rc; 34 | 35 | template 36 | void serialize(Archiver& archiver) const { 37 | archiver["interval"] & interval; 38 | archiver & rc; 39 | } 40 | 41 | template 42 | bool unserialize(Archiver& archiver) { 43 | return 44 | (archiver["interval"] & interval) && 45 | (archiver & rc); 46 | } 47 | }; 48 | 49 | }}} 50 | 51 | 52 | #endif /* CONCURRENT_TICK_CONFIG_H_ */ 53 | -------------------------------------------------------------------------------- /zertco5/config/Config.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/config/Config.cpp -------------------------------------------------------------------------------- /zertco5/config/Config.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/config/Config.h -------------------------------------------------------------------------------- /zertco5/core/RuntimeContext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * RuntimeContext.cpp 3 | * 4 | * Created on: 2015年4月7日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "RuntimeContext.h" 9 | 10 | namespace zertcore{ 11 | 12 | RuntimeContext& RuntimeContext:: 13 | operator= (const RuntimeContext& rc) { 14 | if (!error) 15 | error = rc.error; 16 | return *this; 17 | } 18 | 19 | RuntimeContext:: 20 | operator bool() const { 21 | return error; 22 | } 23 | 24 | void RuntimeContext:: 25 | clear() { 26 | error.clear(); 27 | } 28 | 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /zertco5/core/RuntimeContext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * RuntimeContext.h 3 | * 4 | * Created on: 2015年4月7日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_CORE_RUNTIMECONTEXT_H_ 9 | #define ZERTCORE_CORE_RUNTIMECONTEXT_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace zertcore{ 16 | 17 | /** 18 | * RuntimeContext 19 | */ 20 | struct RuntimeContext : public object::PoolObject 21 | { 22 | Error error; 23 | 24 | RuntimeContext& operator= (const RuntimeContext& rc); 25 | operator bool() const; 26 | 27 | void clear(); 28 | 29 | ZC_TO_STRING("error_code" << error.code << "error_msg" << error.message); 30 | }; 31 | 32 | } 33 | 34 | 35 | #endif /* CORE_RUNTIMECONTEXT_H_ */ 36 | -------------------------------------------------------------------------------- /zertco5/db/Database.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/db/Database.h -------------------------------------------------------------------------------- /zertco5/db/DatabaseInterface.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/db/DatabaseInterface.h -------------------------------------------------------------------------------- /zertco5/db/DatabaseInterfaceManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DatabaseManager.h 3 | * 4 | * Created on: 2014��11��24�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_DATABASEMANAGER_H_ 9 | #define ZERTCORE_DATABASEMANAGER_H_ 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace zertcore { namespace db { 17 | using namespace zertcore::utils; 18 | }} 19 | 20 | namespace zertcore { namespace db { 21 | 22 | /** 23 | * DatabaseInterfaceManager 24 | */ 25 | template 26 | class DatabaseInterfaceManager : 27 | public Singleton > 28 | { 29 | public: 30 | typedef DatabaseInterface 31 | database_type; 32 | typedef typename database_type::ptr database_ptr; 33 | 34 | public: 35 | typedef vector database_slot_type; 36 | 37 | public: 38 | template 39 | database_ptr fetchById(const T& id) { 40 | if (database_slot_.empty()) 41 | return nullptr; 42 | 43 | hash hasher; 44 | return database_slot_[hasher(id) % database_slot_.size()]; 45 | } 46 | 47 | public: 48 | bool add(typename database_type::adapter_config_type& config) { 49 | database_ptr db = new database_type; 50 | if (!db->init(config)) 51 | return false; 52 | 53 | database_slot_.push_back(db); 54 | return true; 55 | } 56 | 57 | private: 58 | database_slot_type database_slot_; 59 | }; 60 | 61 | }} 62 | 63 | 64 | #endif /* DATABASEMANAGER_H_ */ 65 | -------------------------------------------------------------------------------- /zertco5/db/io/DataProvider.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DataIO.h 3 | * 4 | * Created on: 2014-10-5 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_DATAIO_H_ 9 | #define ZERTCORE_DATAIO_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | namespace zertcore { namespace db { namespace io { 18 | using namespace zertcore::object; 19 | using namespace zertcore::concurrent; 20 | }}} 21 | 22 | namespace zertcore { namespace db { namespace io { 23 | 24 | /** 25 | * DataProvider 26 | */ 27 | template 28 | class DataProvider : 29 | public ObjectBase >, 30 | public ThreadHandlerSet > 31 | { 32 | public: 33 | typedef Object* ptr; 34 | 35 | public: 36 | typedef typename ActiveObjectTraits::ptr 37 | object_ptr; 38 | typedef typename ActiveObjectTraits::id_type 39 | id_type; 40 | 41 | public: 42 | virtual ~DataProvider() {} 43 | 44 | public: 45 | virtual bool serialize(object_ptr object, const id_type& id) 46 | = 0; 47 | virtual bool unserialize(object_ptr object, const id_type& id) 48 | = 0; 49 | }; 50 | 51 | }}} 52 | 53 | #endif /* DATAIO_H_ */ 54 | -------------------------------------------------------------------------------- /zertco5/db/io/DataProviderManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DataProviderManager.h 3 | * 4 | * Created on: 2014��11��25�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_DATAPROVIDERMANAGER_H_ 9 | #define ZERTCORE_DATAPROVIDERMANAGER_H_ 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #include "DataProvider.h" 17 | 18 | namespace zertcore{ namespace db{ namespace io{ 19 | using namespace zertcore::utils; 20 | 21 | #ifndef ZT_DATAPROVIDER_KEY_TYPE 22 | typedef u32 key_type; 23 | #else 24 | typedef ZT_DATAPROVIDER_KEY_TYPE key_type; 25 | #endif 26 | 27 | }}} 28 | 29 | namespace zertcore{ namespace db{ namespace io{ 30 | 31 | /** 32 | * DataProviderManager 33 | */ 34 | template 35 | class DataProviderManager : 36 | public Singleton > 37 | { 38 | public: 39 | typedef Object object_type; 40 | typedef DataProvider data_provider_type; 41 | typedef data_provider_type* data_provider_ptr; 42 | public: 43 | typedef unordered_map 44 | data_provider_map_type; 45 | 46 | public: 47 | void reg(const key_type& key, data_provider_ptr dp) { 48 | data_provider_map_[key] = dp; 49 | } 50 | void unreg(const key_type& key) { 51 | data_provider_map_.erase(key); 52 | } 53 | 54 | public: 55 | data_provider_ptr get(const key_type& key) { 56 | typename data_provider_map_type::iterator it = data_provider_map_.find(key); 57 | if (it == data_provider_map_.end()) 58 | return null; 59 | 60 | return it->second; 61 | } 62 | 63 | private: 64 | data_provider_map_type data_provider_map_; 65 | }; 66 | 67 | }}} 68 | 69 | 70 | #endif /* DATAPROVIDERMANAGER_H_ */ 71 | -------------------------------------------------------------------------------- /zertco5/db/mongodb/MongoDBAdapter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/db/mongodb/MongoDBAdapter.h -------------------------------------------------------------------------------- /zertco5/db/mongodb/MongoDBCursor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * MongoDBCursor.cpp 3 | * 4 | * Created on: 2014��11��17�� 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #include "MongoDBCursor.h" 12 | 13 | namespace zertcore{ namespace db{ namespace mongodb{ 14 | 15 | MongoDBCursor::MongoDBCursor() { 16 | // TODO Auto-generated constructor stub 17 | } 18 | 19 | MongoDBCursor::~MongoDBCursor() { 20 | // TODO Auto-generated destructor stub 21 | } 22 | 23 | bool MongoDBCursor::moveNext(Unserializer& data) { 24 | if (cursor_->more()) { 25 | data.stream().data(cursor_->next()); 26 | return true; 27 | } 28 | return false; 29 | } 30 | 31 | 32 | }}} 33 | -------------------------------------------------------------------------------- /zertco5/db/mongodb/MongoDBCursor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MongoDBCursor.h 3 | * 4 | * Created on: 2014��11��17�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_MONGODBCURSOR_H_ 9 | #define ZERTCORE_MONGODBCURSOR_H_ 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #include "config.h" 17 | #include "serialize/BSONStream.h" 18 | 19 | namespace zertcore{ namespace db{ namespace mongodb{ 20 | using namespace zertcore::object; 21 | using namespace zertcore::db::mongodb::serialization; 22 | }}} 23 | 24 | namespace zertcore{ namespace db{ namespace mongodb{ 25 | 26 | /** 27 | * MongoDBCursor 28 | */ 29 | class MongoDBCursor : 30 | public PoolObject 31 | { 32 | public: 33 | typedef SMART_PTR(MongoDBCursor) ptr; 34 | 35 | ZC_TO_STRING("MongoDBCursor"); 36 | public: 37 | MongoDBCursor(); 38 | virtual ~MongoDBCursor(); 39 | 40 | public: 41 | /** 42 | * return true if got data and moved to next one 43 | */ 44 | bool moveNext(Unserializer& data); 45 | 46 | public: 47 | void setCursor(auto_ptr cursor) { 48 | cursor_ = cursor; 49 | } 50 | 51 | private: 52 | auto_ptr cursor_; 53 | }; 54 | 55 | }}} 56 | 57 | #endif /* MONGODBCURSOR_H_ */ 58 | -------------------------------------------------------------------------------- /zertco5/db/mongodb/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MongoDBConfig.h 3 | * 4 | * Created on: 2014��11��19�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_MONGODBCONFIG_H_ 9 | #define ZERTCORE_MONGODBCONFIG_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | namespace zertcore { namespace db { namespace mongodb { 18 | using namespace mongo; 19 | using namespace zertcore::object; 20 | }}} 21 | 22 | 23 | namespace zertcore { namespace db { namespace mongodb { 24 | 25 | namespace details { 26 | 27 | enum { 28 | RUNNING_THREAD_ID = 4, 29 | }; 30 | 31 | } 32 | 33 | /** 34 | * MongoDBAdapterConfig 35 | */ 36 | struct MongoDBAdapterConfig : 37 | Serializable, Unserializable 38 | { 39 | string host{"127.0.0.1"}; 40 | u32 port{27017}; 41 | 42 | string db; 43 | 44 | template 45 | void serialize(Archiver& archiver) const { 46 | archiver["host"] & host; 47 | archiver["port"] & port; 48 | archiver["db"] & db; 49 | } 50 | template 51 | bool unserialize(Archiver& archiver) { 52 | return (archiver["host"] & host) && 53 | (archiver["port"] & port) && 54 | (archiver["db"] & db); 55 | } 56 | }; 57 | 58 | typedef vector mongodb_config_list_type; 59 | 60 | }}} 61 | 62 | #endif /* MONGODBCONFIG_H_ */ 63 | -------------------------------------------------------------------------------- /zertco5/details.h: -------------------------------------------------------------------------------- 1 | /* 2 | * details.h 3 | * 4 | * Created on: 2015年3月31日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_DETAILS_H_ 9 | #define ZERTCORE_DETAILS_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include
25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #endif /* DETAILS_H_ */ 34 | -------------------------------------------------------------------------------- /zertco5/game_configbase_sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "db_config":[], 3 | "rpc_server":{"host":"0.0.0.0","port":10000}, 4 | "rpc_datasync":{"host":"0.0.0.0","port":10001}, 5 | "enable_sync_tick":0, 6 | "router_config":{"host":"127.0.0.1","port":8080}, 7 | "server_config":{"host":"0.0.0.0","port":80}, 8 | "thread_amount":3 9 | } -------------------------------------------------------------------------------- /zertco5/main/SConscript: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /zertco5/main/router_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * rpc_router_main.cpp 3 | * 4 | * Created on: 2015年3月5日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | using namespace zertcore; 14 | using namespace zertcore::concurrent::rpc; 15 | using namespace zertcore::concurrent::update; 16 | 17 | int main() { 18 | UpdateConfig update_config; 19 | RPCRouterConfig router_config; 20 | 21 | RPCRouter router; 22 | 23 | update_config.interval = 1000; 24 | router_config.host = "127.0.0.1"; 25 | router_config.port = 8080; 26 | 27 | config.concurrent.thread_nums = 1; 28 | 29 | ZC_ASSERT(RPCManager::setup( 30 | RemoteConfig("0.0.0.0", router_config.port), 31 | RemoteConfig("0.0.0.0", router_config.port + 10) 32 | )); 33 | 34 | RT.setupRouter(router_config); 35 | RT.globalInit([&]() { 36 | router.globalInit(); 37 | ZC_ASSERT( UpdateServer::Instance().globalInit(update_config) ); 38 | 39 | /** 40 | * RPC Ready 41 | */ 42 | RPCManager::Instance().setRPCReadyHandler([] () { 43 | ZC_ASSERT( UpdateServer::Instance().start() ); 44 | }); 45 | 46 | }); 47 | RT.run(); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /zertco5/net/client/ClientBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ClientBase.h 3 | * 4 | * Created on: 2015��1��13�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_CLIENTBASE_H_ 9 | #define ZERTCORE_CLIENTBASE_H_ 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include "../IOService.h" 16 | #include "config.h" 17 | 18 | namespace zertcore { namespace net { 19 | using namespace zertcore::utils; 20 | }} 21 | 22 | namespace zertcore { namespace net { namespace client { 23 | 24 | template 25 | class ClientBase : 26 | public IOService 27 | { 28 | typedef ClientBase self; 29 | public: 30 | typedef Final final_type; 31 | 32 | typedef Connection connection_type; 33 | typedef typename Connection::ptr connection_ptr; 34 | 35 | public: 36 | ClientBase() : resolver_(this->template io_service_) {} 37 | 38 | public: 39 | bool init(const ClientConfig& config); 40 | /** 41 | * Block version, 42 | * Doesn't provide the sync version, i think its useless (@2015.2.9) 43 | */ 44 | connection_ptr connect(const string& host, const u32& port); 45 | connection_ptr connect(const RemoteConfig& rc) { 46 | return connect(rc.host, rc.port); 47 | } 48 | 49 | private: 50 | /** 51 | void handleResolve(const system::error_code& err, 52 | asio::ip::tcp::resolver::iterator ep, connection_ptr conn); 53 | */ 54 | 55 | private: 56 | asio::ip::tcp::resolver resolver_; 57 | }; 58 | 59 | }}} 60 | 61 | #include "details/ClientBaseDetails.hpp" 62 | 63 | #endif /* CLIENTBASE_H_ */ 64 | -------------------------------------------------------------------------------- /zertco5/net/client/config.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/net/client/config.h -------------------------------------------------------------------------------- /zertco5/net/client/details/ClientBaseDetails.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ClientBaseDetails.hpp 3 | * 4 | * Created on: 2015��1��13�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_CLIENTBASEDETAILS_HPP_ 9 | #define ZERTCORE_CLIENTBASEDETAILS_HPP_ 10 | 11 | #include 12 | 13 | namespace zertcore { namespace net { namespace client { 14 | 15 | template 16 | bool ClientBase:: 17 | init(const ClientConfig& config) { 18 | if (!IOService::init(config)) 19 | return false; 20 | 21 | return true; 22 | } 23 | 24 | template 25 | typename ClientBase::connection_ptr ClientBase:: 26 | connect(const string& host, const u32& port) { 27 | connection_ptr conn = connection_type::template create(*static_cast(this)); 28 | if (!conn) return null; 29 | 30 | system::error_code error_code; 31 | asio::ip::tcp::resolver::query query(host, lexical_cast(port)); 32 | asio::ip::tcp::resolver::iterator ep = resolver_.resolve(query, error_code); 33 | 34 | if (!error_code) { 35 | conn->template connect(ep); 36 | return conn; 37 | } 38 | /** 39 | resolver_.async_resolve(query, 40 | bind(&self::handleResolve, this, asio::placeholders::error, 41 | asio::placeholders::iterator, conn)); 42 | */ 43 | 44 | return null; 45 | } 46 | 47 | /** 48 | template 49 | void ClientBase:: 50 | handleResolve(const system::error_code& err, 51 | asio::ip::tcp::resolver::iterator ep, connection_ptr conn) { 52 | conn->template connect(ep); 53 | } 54 | */ 55 | 56 | }}} 57 | 58 | #endif /* CLIENTBASEDETAILS_HPP_ */ 59 | -------------------------------------------------------------------------------- /zertco5/net/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | * Created on: 2015年6月14日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_NET_CONFIG_H_ 9 | #define ZERTCORE_NET_CONFIG_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { 15 | 16 | /** 17 | * RemoteConfig 18 | */ 19 | struct RemoteConfig : 20 | Serializable, 21 | Unserializable 22 | { 23 | string host; 24 | u32 port; 25 | 26 | RemoteConfig() : port(0) {} 27 | RemoteConfig(const string& h, const u32& p): 28 | host(h), port(p) {} 29 | 30 | operator bool() const { 31 | return !host.empty() && port; 32 | } 33 | 34 | bool operator== (const RemoteConfig& rc) const { 35 | return port == rc.port && host == rc.host; 36 | } 37 | bool operator!= (const RemoteConfig& rc) const { 38 | return !(*this==(rc)); 39 | } 40 | 41 | string toString() const { 42 | return host + ":" + lexical_cast(port); 43 | } 44 | 45 | template 46 | void serialize(Archiver& archiver) const { 47 | archiver["host"] & host; 48 | archiver["port"] & port; 49 | } 50 | 51 | template 52 | bool unserialize(Archiver& archiver) { 53 | return 54 | (archiver["host"] & host) && 55 | (archiver["port"] & port); 56 | } 57 | }; 58 | 59 | } 60 | 61 | 62 | 63 | #endif /* NET_CONFIG_H_ */ 64 | -------------------------------------------------------------------------------- /zertco5/net/details/IOServiceDetails.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IOServiceDetails.hpp 3 | * 4 | * Created on: 2015��1��13�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_IOSERVICEDETAILS_HPP_ 9 | #define ZERTCORE_IOSERVICEDETAILS_HPP_ 10 | 11 | #include 12 | 13 | namespace zertcore{ namespace net{ 14 | 15 | template 16 | bool IOService:: 17 | init(const ServiceConfig& config) { 18 | /** 19 | enable_ssl_ = config.enable_ssl; 20 | if (enable_ssl_) { 21 | ssl_password_ = config.ssl_config.password; 22 | ssl_context_.set_options( 23 | asio::ssl::context::default_workarounds 24 | | asio::ssl::context::no_sslv2 25 | | asio::ssl::context::single_dh_use); 26 | ssl_context_.set_password_callback(bind(&self::getSSLPassword, this)); 27 | ssl_context_.use_certificate_chain_file(config.ssl_config.certificate_chain_file); 28 | ssl_context_.use_private_key_file(config.ssl_config.private_key_file, 29 | asio::ssl::context::pem); 30 | ssl_context_.use_tmp_dh_file(config.ssl_config.dh_file); 31 | } 32 | */ 33 | for (u32 i = 0; i < config.thread_nums; ++i) { 34 | if (!ThreadPool::Instance().registerExclusiveHandler( 35 | bind(&self::mainThread, this), true)) 36 | return false; 37 | } 38 | 39 | return true; 40 | } 41 | 42 | }} 43 | 44 | 45 | #endif /* IOSERVICEDETAILS_HPP_ */ 46 | -------------------------------------------------------------------------------- /zertco5/net/details/SSLConnectionBaseDetails.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/net/details/SSLConnectionBaseDetails.hpp -------------------------------------------------------------------------------- /zertco5/net/tcp/client/ClientBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ClientBase.h 3 | * 4 | * Created on: 2015��1��13�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_NET_TCP_CLIENTBASE_H_ 9 | #define ZERTCORE_NET_TCP_CLIENTBASE_H_ 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include "../IOService.h" 16 | #include "config.h" 17 | 18 | namespace zertcore { namespace net { namespace tcp { 19 | using namespace zertcore::utils; 20 | }}} 21 | 22 | namespace zertcore { namespace net { namespace tcp { namespace client { 23 | 24 | template 25 | class ClientBase : 26 | public IOService 27 | { 28 | typedef ClientBase self; 29 | public: 30 | typedef Final final_type; 31 | 32 | typedef Connection connection_type; 33 | typedef typename Connection::ptr connection_ptr; 34 | 35 | public: 36 | ClientBase() : IOService(), resolver_(this->template io_service_) {} 37 | virtual ~ClientBase() {} 38 | 39 | public: 40 | bool setupClient(const ClientConfig& config); 41 | /** 42 | * Block version, 43 | * Doesn't provide the sync version, i think its useless (@2015.2.9) 44 | */ 45 | connection_ptr connect(const string& host, const u32& port); 46 | connection_ptr connect(const RemoteConfig& rc) { 47 | return connect(rc.host, rc.port); 48 | } 49 | 50 | /** 51 | void handleResolve(const system::error_code& err, 52 | asio::ip::tcp::resolver::iterator ep, connection_ptr conn); 53 | */ 54 | 55 | private: 56 | asio::ip::tcp::resolver resolver_; 57 | }; 58 | 59 | }}}} 60 | 61 | #include "details/ClientBaseDetails.hpp" 62 | 63 | #endif /* CLIENTBASE_H_ */ 64 | -------------------------------------------------------------------------------- /zertco5/net/tcp/client/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | * Created on: 2015��1��13�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_NET_CLIENT_CONFIG_H_ 9 | #define ZERTCORE_NET_CLIENT_CONFIG_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include "../config.h" 15 | 16 | namespace zertcore { namespace net { namespace tcp { 17 | 18 | struct ClientConfig : public ServiceConfig 19 | { 20 | }; 21 | 22 | }}} 23 | 24 | 25 | #endif /* CONFIG_H_ */ 26 | -------------------------------------------------------------------------------- /zertco5/net/tcp/client/details/ClientBaseDetails.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ClientBaseDetails.hpp 3 | * 4 | * Created on: 2015��1��13�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_CLIENTBASEDETAILS_HPP_ 9 | #define ZERTCORE_CLIENTBASEDETAILS_HPP_ 10 | 11 | #include 12 | 13 | namespace zertcore { namespace net { namespace tcp { namespace client { 14 | 15 | template 16 | bool ClientBase:: 17 | setupClient(const ClientConfig& config) { 18 | if (!IOService::setup(config)) 19 | return false; 20 | 21 | return true; 22 | } 23 | 24 | template 25 | typename ClientBase::connection_ptr ClientBase:: 26 | connect(const string& host, const u32& port) { 27 | connection_ptr conn = connection_type::template create(*static_cast(this)); 28 | if (!conn) return null; 29 | 30 | system::error_code error_code; 31 | asio::ip::tcp::resolver::query query(host, lexical_cast(port)); 32 | asio::ip::tcp::resolver::iterator ep = resolver_.resolve(query, error_code); 33 | 34 | if (!error_code && conn->template connect(ep) ) { 35 | return conn; 36 | } 37 | /** 38 | resolver_.async_resolve(query, 39 | bind(&self::handleResolve, this, asio::placeholders::error, 40 | asio::placeholders::iterator, conn)); 41 | */ 42 | 43 | return null; 44 | } 45 | 46 | /** 47 | template 48 | void ClientBase:: 49 | handleResolve(const system::error_code& err, 50 | asio::ip::tcp::resolver::iterator ep, connection_ptr conn) { 51 | conn->template connect(ep); 52 | } 53 | */ 54 | 55 | }}}} 56 | 57 | #endif /* CLIENTBASEDETAILS_HPP_ */ 58 | -------------------------------------------------------------------------------- /zertco5/net/tcp/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | * Created on: 2015��1��13�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_NET_TCP_CONFIG_H_ 9 | #define ZERTCORE_NET_TCP_CONFIG_H_ 10 | 11 | #include "../config.h" 12 | 13 | namespace zertcore { namespace net{ namespace tcp { 14 | 15 | /** 16 | * SSLConfig 17 | * 18 | openssl genrsa -des3 -out [private_key_file] 1024 19 | openssl req -new -key [private_key_file] -out server_tmp.csr 20 | openssl x509 -req -days 3650 -in server_tmp.csr -signkey [private_key_file] -out [certificate_chain_file] 21 | openssl dhparam -out dh_file 512 22 | 23 | for client: 24 | ctx.load_verify_file(certificate_chain_file); 25 | 26 | struct SSLConfig 27 | { 28 | string certificate_chain_file; 29 | string private_key_file; 30 | string dh_file; 31 | 32 | string password; 33 | }; 34 | */ 35 | /** 36 | struct ServiceConfig 37 | { 38 | u32 thread_nums{1}; 39 | 40 | // bool enable_ssl{false}; 41 | // SSLConfig ssl_config; 42 | }; 43 | */ 44 | 45 | }}} 46 | 47 | 48 | #endif /* CONFIG_H_ */ 49 | -------------------------------------------------------------------------------- /zertco5/net/tcp/details/SSLConnectionBaseDetails.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SSLConnectionBaseDetails.hpp 3 | * 4 | * Created on: 2015��1��10�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_SSLCONNECTIONBASEDETAILS_HPP_ 9 | #define ZERTCORE_SSLCONNECTIONBASEDETAILS_HPP_ 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace zertcore { namespace net { namespace tcp { 16 | 17 | template 18 | SSLConnectionBase:: 19 | SSLConnectionBase(server_type& server, asio::ssl::context& context) : 20 | server_(server), strand_(server.IOService()), socket_(server.IOService(), context), 21 | buffer_index_(0), long_term_(false) { 22 | buffer_.reserve(ZC_CONNECTION_BUFFER_SIZE); 23 | } 24 | 25 | template 26 | void SSLConnectionBase:: 27 | start() { 28 | socket_.async_handshake(asio::ssl::stream_base::server, 29 | strand_.wrap(bind(&SSLConnectionBase::handleHandshake, thisPtr(), 30 | asio::placeholders::error))); 31 | } 32 | 33 | template 34 | void SSLConnectionBase:: 35 | handleHandshake(const system::error_code& error) { 36 | if (!error) { 37 | ConnectionBase::start(); 38 | } 39 | } 40 | 41 | }}} 42 | 43 | #endif /* SSLCONNECTIONBASEDETAILS_HPP_ */ 44 | -------------------------------------------------------------------------------- /zertco5/net/tcp/server/ServerBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ServerBase.h 3 | * 4 | * Created on: 2015��1��7�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_NET_TCP_SERVER_BASE_H_ 9 | #define ZERTCORE_NET_TCP_SERVER_BASE_H_ 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #include "../IOService.h" 17 | #include "config.h" 18 | 19 | namespace zertcore { namespace net { namespace tcp { 20 | using namespace zertcore::utils; 21 | using namespace zertcore::object; 22 | }}} 23 | 24 | namespace zertcore { namespace net { namespace tcp { namespace server { 25 | /** 26 | * Server, implement 27 | */ 28 | template 29 | class ServerBase : 30 | public IOService 31 | { 32 | typedef ServerBase self; 33 | 34 | public: 35 | typedef Final final_type; 36 | 37 | typedef Connection connection_type; 38 | typedef typename ObjectTraits::ptr 39 | connection_ptr; 40 | 41 | public: 42 | ServerBase() : is_running_(false), 43 | acceptor_(this->template io_service_) {} 44 | virtual ~ServerBase() {} 45 | 46 | public: 47 | bool setup(const ServerConfig& config); 48 | 49 | protected: 50 | virtual void onStart(); 51 | 52 | private: 53 | void startAccept(); 54 | void continueAccept(); 55 | 56 | private: 57 | void handleAccept(const system::error_code& e, connection_ptr conn); 58 | 59 | private: 60 | bool is_running_; 61 | ServerConfig config_; 62 | 63 | private: 64 | asio::ip::tcp::acceptor acceptor_; 65 | }; 66 | 67 | }}}} 68 | 69 | #include "details/ServerBaseDetails.hpp" 70 | 71 | #endif /* SERVER_H_ */ 72 | -------------------------------------------------------------------------------- /zertco5/net/tcp/server/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | * Created on: 2015��1��7�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_NET_SERVER_CONFIG_H_ 9 | #define ZERTCORE_NET_SERVER_CONFIG_H_ 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include "../config.h" 16 | #include "../../server_config.h" 17 | 18 | namespace zertcore { namespace net { namespace tcp { 19 | 20 | }}} 21 | 22 | 23 | #endif /* CONFIG_H_ */ 24 | -------------------------------------------------------------------------------- /zertco5/net/udp/PackageConnection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PackageConnection.h 3 | * 4 | * Created on: 2015年6月14日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_NET_UDP_PACKAGECONNECTION_H_ 9 | #define ZERTCORE_NET_UDP_PACKAGECONNECTION_H_ 10 | 11 | #include "config.h" 12 | #include "ConnectionBase.h" 13 | 14 | #include 15 | #include 16 | 17 | namespace zertcore { namespace net { namespace udp { 18 | using namespace zertcore::utils; 19 | using namespace zertcore::concurrent; 20 | }}} 21 | 22 | namespace zertcore { namespace net { namespace udp { 23 | 24 | /** 25 | * PackageConnection 26 | */ 27 | template 28 | class PackageConnection: 29 | public ConnectionBase 30 | { 31 | typedef ConnectionBase self; 32 | public: 33 | typedef ThreadHandler 34 | package_handler_type; 35 | public: 36 | explicit PackageConnection(Server& server, peer_ptr peer) : 37 | ConnectionBase(server, peer) {} 38 | virtual ~PackageConnection() {} 39 | 40 | public: 41 | virtual void onPackage(const SharedBuffer& buffer) {;} 42 | /** 43 | * the buffer size must less than 0xfffc 44 | */ 45 | bool sendPackage(const SharedBuffer& buffer); 46 | 47 | public: 48 | virtual size_t onRead(const SharedBuffer& buffer) final; 49 | 50 | public: 51 | static void setPackageHandler(const package_handler_type& handler) { 52 | package_handler_ = handler; 53 | } 54 | 55 | private: 56 | static package_handler_type package_handler_; 57 | }; 58 | 59 | template 60 | typename PackageConnection::package_handler_type 61 | PackageConnection::package_handler_; 62 | 63 | }}} 64 | 65 | 66 | #endif /* NET_UDP_PACKAGECONNECTION_H_ */ 67 | -------------------------------------------------------------------------------- /zertco5/net/udp/ServerBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ServerBase.h 3 | * 4 | * Created on: 2015年6月13日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_NET_UDP_SERVERBASE_H_ 9 | #define ZERTCORE_NET_UDP_SERVERBASE_H_ 10 | 11 | #include "config.h" 12 | #include "../server_config.h" 13 | 14 | namespace zertcore { namespace net { namespace udp { 15 | 16 | /** 17 | * ServerBase 18 | */ 19 | template 20 | class ServerBase 21 | { 22 | private: 23 | typedef ServerBase self; 24 | 25 | public: 26 | typedef Final final_type; 27 | typedef Connection connection_type; 28 | typedef typename connection_type::ptr connection_ptr; 29 | typedef typename connection_type::pure_ptr 30 | connection_pure_ptr; 31 | public: 32 | typedef host_type* host_ptr; 33 | 34 | public: 35 | typedef unordered_map 36 | connection_map_type; 37 | public: 38 | virtual ~ServerBase(); 39 | 40 | public: 41 | bool setup(const ServerConfig& rc); 42 | 43 | public: 44 | bool flush(); 45 | 46 | public: 47 | void startRun(); 48 | size_t mainThread(); 49 | 50 | public: 51 | spinlock_type& getLock() {return lock_;} 52 | 53 | private: 54 | spinlock_type lock_; 55 | host_ptr host_{nullptr}; 56 | 57 | private: 58 | connection_map_type connection_map_; 59 | }; 60 | 61 | }}} 62 | 63 | 64 | #endif /* NET_UDP_SERVERBASE_H_ */ 65 | -------------------------------------------------------------------------------- /zertco5/net/udp/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | * Created on: 2015年6月13日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_NET_UDP_CONFIG_H_ 9 | #define ZERTCORE_NET_UDP_CONFIG_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include "../config.h" 17 | 18 | /** 19 | * for UDP way to transfer data better not bigger than the MTU payload 20 | */ 21 | 22 | namespace zertcore { namespace net { namespace udp { 23 | 24 | typedef ENetHost host_type; 25 | typedef ENetAddress address_type; 26 | typedef ENetPeer peer_type; 27 | typedef peer_type* peer_ptr; 28 | 29 | 30 | }}} 31 | 32 | 33 | #endif /* NET_UDP_CONFIG_H_ */ 34 | -------------------------------------------------------------------------------- /zertco5/net/udp/details/PackageConnectionDetails.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * PackageConnectionDetails.hpp 3 | * 4 | * Created on: 2015年6月14日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef NET_UDP_DETAILS_PACKAGECONNECTIONDETAILS_HPP_ 9 | #define NET_UDP_DETAILS_PACKAGECONNECTIONDETAILS_HPP_ 10 | 11 | #include "../PackageConnection.h" 12 | 13 | namespace zertcore { namespace net { namespace udp { 14 | 15 | template 16 | size_t PackageConnection:: 17 | onRead(const SharedBuffer& buffer) { 18 | if (buffer.size() < sizeof(u16)) { 19 | ZCLOG(ERROR) << "Buffer was too small, size=" << buffer.size() << End; 20 | return 0; 21 | } 22 | 23 | u16 length = *((const u16 *)buffer.data()); 24 | if (length > SharedBuffer::MAX_SIZE) { 25 | ZCLOG(ERROR) >> this->template error() << "Length was too large:" << length << End; 26 | buffer.print(); 27 | return 0; 28 | } 29 | 30 | if (length > buffer.size()) { 31 | ZCLOG(NOTE) << "length=" << length << ",size=" << buffer.size() << End; 32 | return 0; 33 | } 34 | 35 | SharedBuffer pkg = buffer.slice((u32)sizeof(u16), length - sizeof(u16)); 36 | onPackage(pkg); 37 | 38 | if (package_handler_) { 39 | package_handler_.setParams(this->template thisPtr(), pkg); 40 | package_handler_.push(); 41 | } 42 | 43 | return length; 44 | } 45 | 46 | template 47 | bool PackageConnection:: 48 | sendPackage(const SharedBuffer& buffer) { 49 | if (buffer.size() >= max_u16 - sizeof(u16)) 50 | return false; 51 | 52 | u16 head_size = buffer.size() + sizeof(u16); 53 | 54 | SharedBuffer send_buf(buffer.size() + sizeof(u16)); 55 | ZC_ASSERT(send_buf.add((const u8 *)&head_size, sizeof(u16))); 56 | ZC_ASSERT(send_buf.add(buffer)); 57 | 58 | return this->template write(send_buf); 59 | } 60 | 61 | }}} 62 | 63 | 64 | #endif /* NET_UDP_DETAILS_PACKAGECONNECTIONDETAILS_HPP_ */ 65 | -------------------------------------------------------------------------------- /zertco5/object/ActiveObjectTraits.h: -------------------------------------------------------------------------------- 1 | /* 2 | * WorldObjectTraits.h 3 | * 4 | * Created on: 2015年6月6日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_OBJECT_WORLDOBJECTTRAITS_H_ 9 | #define ZERTCORE_OBJECT_WORLDOBJECTTRAITS_H_ 10 | 11 | #include 12 | #include "ObjectTraits.h" 13 | 14 | #include 15 | 16 | namespace zertcore { 17 | 18 | /** 19 | * play role 20 | */ 21 | enum { 22 | ROLE_NONE = 0, 23 | ROLE_SLAVE = 1 << 0, 24 | ROLE_MASTER = 1 << 1, 25 | }; 26 | 27 | typedef u32 role_type; 28 | 29 | } 30 | 31 | namespace zertcore { namespace object { 32 | 33 | template 34 | struct ActiveObjectTraits : public ObjectTraits 35 | { 36 | typedef uuid_t id_type; 37 | 38 | static const char* TABLE_NAME; 39 | static const char* RPC_NAME; 40 | static const char* SYNC_NAME; 41 | 42 | static const tick_type DefaultExpiredTick; // default 10 second 43 | }; 44 | 45 | template 46 | const char* ActiveObjectTraits::TABLE_NAME = NULL; 47 | 48 | template 49 | const char* ActiveObjectTraits::RPC_NAME = NULL; 50 | 51 | template 52 | const char* ActiveObjectTraits::SYNC_NAME = NULL; 53 | 54 | template 55 | const tick_type ActiveObjectTraits::DefaultExpiredTick = 10000; 56 | 57 | }} 58 | 59 | 60 | #endif /* OBJECT_WORLDOBJECTTRAITS_H_ */ 61 | -------------------------------------------------------------------------------- /zertco5/object/ObjectTraits.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ObjectTraits.h 3 | * 4 | * Created on: 2014��11��30�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_OBJECTTRAITS_H_ 9 | #define ZERTCORE_OBJECTTRAITS_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { namespace object { 15 | 16 | template 17 | struct ObjectTraits : public _Traits 18 | { 19 | typedef SMART_PTR(Object) ptr; 20 | enum { 21 | POOL_SIZE = 32, 22 | }; 23 | }; 24 | 25 | }} 26 | 27 | 28 | #endif /* OBJECTTRAITS_H_ */ 29 | -------------------------------------------------------------------------------- /zertco5/object/SConscript: -------------------------------------------------------------------------------- 1 | import GenCPP 2 | 3 | GenCPP.generate_callwrapper_ipp('details/PoolObjectCreateDeclare.ipp', """ 4 | template<{template}> 5 | static typename _Traits::ptr create({params}); 6 | """, 3) 7 | 8 | GenCPP.generate_callwrapper_ipp('details/PoolObjectCreateImpl.ipp', """ 9 | template 10 | template<{template}> 11 | typename _Traits::ptr PoolObject::create({params}) { 12 | Final* raw_ptr = new Final({call});//PoolObject::pobject_pool_.construct({call});// 13 | typename _Traits::ptr ptr(raw_ptr); 14 | #ifndef ZC_RELEASE 15 | ptr->raw_ptr_ = raw_ptr; 16 | #endif 17 | return ptr; 18 | } 19 | """, 3) 20 | -------------------------------------------------------------------------------- /zertco5/object/WorldObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SerializeObject.h 3 | * 4 | * Created on: 2015年6月16日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_OBJECT_WORLDOBJECT_H_ 9 | #define ZERTCORE_OBJECT_WORLDOBJECT_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include "utils/serializable/SerializableObject.h" 15 | 16 | namespace zertcore { namespace object { 17 | using namespace zertcore::utils; 18 | }} 19 | 20 | namespace zertcore { namespace object { 21 | 22 | /** 23 | * WorldObject 24 | */ 25 | template 26 | struct WorldObject : 27 | public ActiveObject, 28 | public SerializableObject 29 | { 30 | }; 31 | 32 | 33 | }} 34 | 35 | namespace zertcore { namespace object { 36 | 37 | /** 38 | * WorldObjectManager 39 | */ 40 | template 41 | class WorldObjectManager : 42 | public ActiveObjectManager 43 | { 44 | public: 45 | virtual ~WorldObjectManager() {} 46 | 47 | public: 48 | virtual void init() { 49 | ActiveObjectManager::init(); 50 | ActiveObjectManager::dp_manager::Instance(). 51 | reg(PROVIDER_MONGODB, new io::MongoDBDataProvider); 52 | } 53 | }; 54 | 55 | }} 56 | 57 | #endif /* OBJECT_WORLDOBJECT_H_ */ 58 | -------------------------------------------------------------------------------- /zertco5/object/WorldObjectManager.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/object/WorldObjectManager.h -------------------------------------------------------------------------------- /zertco5/object/details/ActiveObjectImpl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ActiveObjectImpl.hpp 3 | * 4 | * Created on: 2015年7月22日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_OBJECT_DETAILS_ACTIVEOBJECTIMPL_HPP_ 9 | #define ZERTCORE_OBJECT_DETAILS_ACTIVEOBJECTIMPL_HPP_ 10 | 11 | #include "../ActiveObject.h" 12 | #include 13 | 14 | namespace zertcore { namespace object { 15 | 16 | template 17 | bool ActiveObject:: 18 | setMaster() { 19 | if (!ActiveObjectTraits::SYNC_NAME) { 20 | ZCLOG(ERROR) << "ActiveTraits SYNC_NAME is NULL" << End; 21 | return false; 22 | } 23 | 24 | role_ |= ROLE_MASTER; 25 | return true; 26 | } 27 | 28 | template 29 | bool ActiveObject:: 30 | setSlave() { 31 | if (!id_) return false; 32 | 33 | role_ |= ROLE_SLAVE; 34 | getManager().setupSlave(id_, this->template thisPtr()); 35 | 36 | return true; 37 | } 38 | 39 | template 40 | bool ActiveObject:: 41 | sync() { 42 | if ( !(role_ & ROLE_MASTER) && !setMaster() ) { 43 | ZCLOG(NOTE) << "try to sync others not in master role" << End; 44 | return false; 45 | } 46 | 47 | return RPC.notify(ActiveObjectTraits::SYNC_NAME, *this); 48 | } 49 | 50 | }} 51 | 52 | 53 | #endif /* OBJECT_DETAILS_ACTIVEOBJECTIMPL_HPP_ */ 54 | -------------------------------------------------------------------------------- /zertco5/object/details/PoolObjectDetails.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * PoolObjectDetails.hpp 3 | * 4 | * Created on: 2015年10月18日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_OBJECT_DETAILS_POOLOBJECTDETAILS_HPP_ 9 | #define ZERTCORE_OBJECT_DETAILS_POOLOBJECTDETAILS_HPP_ 10 | 11 | #include "../PoolObject.h" 12 | 13 | namespace zertcore{ namespace object { 14 | 15 | template 16 | void PoolObject:: 17 | operator delete(void *ptr) { 18 | #ifndef ZC_RELEASE 19 | ZC_DEBUG_ASSERT(ptr == ((Final *)ptr)->raw_ptr_); 20 | ((Final *)ptr)->raw_ptr_ = nullptr; 21 | #endif 22 | /** 23 | spinlock_guard_type guard(lock_); 24 | 25 | if (pobject_pool_.is_from((Final *)ptr)) { 26 | pobject_pool_.destroy((Final *)ptr); 27 | } 28 | else 29 | */ 30 | ::operator delete(ptr); 31 | } 32 | 33 | template 34 | typename _Traits::ptr PoolObject:: 35 | create() { 36 | Final* raw_ptr = new Final();//PoolObject::pobject_pool_.construct();// 37 | typename _Traits::ptr ptr(raw_ptr); 38 | #ifndef ZC_RELEASE 39 | ptr->raw_ptr_ = raw_ptr; 40 | #endif 41 | return ptr; 42 | } 43 | 44 | #ifdef ZC_COMPILE 45 | # include "PoolObjectCreateImpl.ipp" 46 | #endif 47 | 48 | }} 49 | 50 | 51 | #endif /* OBJECT_DETAILS_POOLOBJECTDETAILS_HPP_ */ 52 | -------------------------------------------------------------------------------- /zertco5/object/details/WorldObjectManagerImpl.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/object/details/WorldObjectManagerImpl.hpp -------------------------------------------------------------------------------- /zertco5/serialize/SConscript: -------------------------------------------------------------------------------- 1 | import GenCPP 2 | 3 | GenCPP.generate_types_ipp('details/SerializerSetValueDetails.ipp', """ 4 | void setValue(const {type}& v) { 5 | stream_.setValue(key_, v, op_code_); 6 | op_code_ = OP_NONE; 7 | } 8 | """, ['i8','i16','i32','i64','u8','u16','u32','u64','f32','f64','bool']) 9 | 10 | GenCPP.generate_types_ipp('details/SerializerSimpleTypeOperatorDetails.ipp', """ 11 | template 12 | Serializer& operator << (Serializer& s, const {type}& v) { 13 | if (s.getIgnoreNull() && v == 0) 14 | return s; 15 | s.setValue(v); 16 | return s; 17 | } 18 | """, ['i8','i16','i32','i64','u8','u16','u32','u64','f32','f64','bool']) 19 | 20 | ################# 21 | 22 | GenCPP.generate_types_ipp('details/UnserializerGetValueDetails.ipp', """ 23 | bool getValue({type}& v) { 24 | return stream_.getValue(key_, v); 25 | } 26 | """, ['i8','i16','i32','i64','u8','u16','u32','u64','f32','f64','bool']) 27 | 28 | GenCPP.generate_types_ipp('details/UnserializerSimpleTypeOperatorDetails.ipp', """ 29 | template 30 | bool operator >> (const Unserializer& s, {type}& v) { 31 | return s.getValue(v); 32 | } 33 | """, ['i8','i16','i32','i64','u8','u16','u32','u64','f32','f64','bool']) 34 | -------------------------------------------------------------------------------- /zertco5/serialize/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | * Created on: 2014-4-29 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_SERIALIZE_CONFIG_H_ 9 | #define ZERTCORE_SERIALIZE_CONFIG_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace zertcore { 17 | 18 | enum { 19 | TYPE_NONE = 0, 20 | 21 | TYPE_U32 = 1, 22 | TYPE_I32 = 2, 23 | TYPE_U64 = 3, 24 | TYPE_I64 = 4, 25 | TYPE_DOUBLE = 5, 26 | TYPE_STRING = 6, 27 | 28 | TYPE_ARRAY = 7, 29 | TYPE_OBJECT = 8, 30 | 31 | TYPE_KEY = 10, 32 | }; 33 | 34 | typedef u32 value_type; 35 | } 36 | 37 | namespace zertcore { namespace serialization { 38 | using namespace zertcore::utils; 39 | 40 | #ifndef ZC_SERIALIZE_KEY_TYPE 41 | /** 42 | * Recommand the key length less than 7 (with '\0' its 8 64bits) 43 | */ 44 | typedef string key_type; 45 | #else 46 | typedef ZC_SERIALIZE_KEY_TYPE key_type; 47 | #endif 48 | 49 | typedef vector key_list_type; 50 | 51 | /** 52 | * a compromise to query sentence 53 | */ 54 | enum op_code_type 55 | { 56 | OP_NONE = 0, 57 | OP_EQU = 1, 58 | OP_NE = 2, 59 | OP_GT = 3, 60 | OP_GTE = 4, 61 | OP_LT = 5, 62 | OP_LTE = 6, 63 | OP_IN = 7, 64 | OP_NIN = 8, 65 | OP_AND = 9, 66 | OP_OR = 10, 67 | }; 68 | 69 | }} 70 | 71 | 72 | #endif /* CONFIG_H_ */ 73 | -------------------------------------------------------------------------------- /zertco5/suit/buff/Buff.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Buff.cpp 3 | * 4 | * Created on: 2015年6月20日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "Buff.h" 9 | #include 10 | 11 | namespace zertcore { namespace suit { 12 | 13 | Buff::Buff() : host_(0), via_(0), tick_(0) {;} 14 | Buff::Buff(const double& r, const double& v, const ulong& tick) : host_(0), via_(0), tick_(tick) { 15 | rv_.rate = r; 16 | rv_.value = v; 17 | } 18 | 19 | Buff::~Buff() { 20 | unlinkAll(); 21 | } 22 | 23 | void Buff:: 24 | unlinkAll() const { 25 | for (auto it = buffceptor_ptr_list_.begin(); 26 | it != buffceptor_ptr_list_.end(); ) { 27 | auto hit = it++; 28 | *(*hit) -= *this; 29 | } 30 | buffceptor_ptr_list_.clear(); 31 | } 32 | 33 | }} 34 | 35 | -------------------------------------------------------------------------------- /zertco5/suit/buff/BuffCeptor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BuffCeptor.cpp 3 | * 4 | * Created on: 2015年6月20日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "Buff.h" 9 | #include 10 | 11 | namespace zertcore { namespace suit { 12 | 13 | BuffCeptor::BuffCeptor() { 14 | ; 15 | } 16 | 17 | void BuffCeptor:: 18 | add(const Buff& buff) { 19 | buff_ptr_map_.insert(buff_ptr_map_type::value_type(&buff, buff.getTick())); 20 | refresh(); 21 | 22 | buff.link(*this); 23 | } 24 | 25 | void BuffCeptor:: 26 | erase(const Buff& buff) { 27 | buff_ptr_map_.erase(&buff); 28 | refresh(); 29 | 30 | buff.unlink(*this); 31 | } 32 | 33 | void BuffCeptor:: 34 | refresh() { 35 | rv_.value = 0; 36 | rv_.rate = 0; 37 | 38 | for (auto it = buff_ptr_map_.begin(); it != buff_ptr_map_.end(); ++it) { 39 | rv_.value += it->first->getValue(); 40 | rv_.rate += it->first->getRate(); 41 | } 42 | } 43 | 44 | void BuffCeptor:: 45 | updateTick(const ulong& tick) { 46 | bool change_flag = false; 47 | 48 | for (auto it = buff_ptr_map_.begin(); it != buff_ptr_map_.end(); ) { 49 | auto hit = it++; 50 | 51 | if (hit->second <= tick) { 52 | change_flag = true; 53 | erase(*hit->first); 54 | } 55 | else { 56 | hit->second -= tick; 57 | } 58 | } 59 | 60 | if (change_flag) 61 | refresh(); 62 | } 63 | 64 | double BuffCeptor:: 65 | calc(const double& v) const { 66 | return v * rv_; 67 | } 68 | 69 | }} 70 | 71 | 72 | -------------------------------------------------------------------------------- /zertco5/suit/event/Event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Event.h 3 | * 4 | * Created on: 2015年7月3日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_SUIT_EVENT_EVENT_H_ 9 | #define ZERTCORE_SUIT_EVENT_EVENT_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { namespace suit { 15 | 16 | /** 17 | * inspired by danquist's EventBus. 18 | * @https://github.com/danquist/EventBus 19 | */ 20 | 21 | /** 22 | * the event was not support multithread, if so, remember to add lock for 23 | * the safety of public resource. 24 | */ 25 | 26 | /** 27 | * Event 28 | */ 29 | class Event 30 | { 31 | public: 32 | enum { 33 | NONE = 0, 34 | SENDING = 1, 35 | STOPPED = 2, 36 | FINISH = 3, 37 | ERROR = 10, 38 | }; 39 | typedef u32 status_type; 40 | 41 | private: 42 | status_type status_{NONE}; 43 | }; 44 | 45 | }} 46 | 47 | 48 | #endif /* SUIT_EVENT_EVENT_H_ */ 49 | -------------------------------------------------------------------------------- /zertco5/suit/event/EventBus.h: -------------------------------------------------------------------------------- 1 | /* 2 | * EventBus.h 3 | * 4 | * Created on: 2015年8月18日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_SUIT_EVENT_EVENTBUS_H_ 9 | #define ZERTCORE_SUIT_EVENT_EVENTBUS_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include "EventHandler.h" 17 | 18 | namespace zertcore { namespace suit { 19 | using namespace zertcore::utils; 20 | }} 21 | 22 | namespace zertcore { namespace suit { 23 | 24 | /** 25 | * EventBus 26 | */ 27 | template 28 | class EventBus : 29 | public Singleton, NoneChecker> 30 | { 31 | public: 32 | typedef EventDerived event_type; 33 | 34 | public: 35 | typedef unordered_set::ptr> 36 | handler_set_type; 37 | 38 | public: 39 | /** 40 | * dispatch actions 41 | */ 42 | void dispatch(event_type& e); 43 | 44 | /** 45 | * add & remove Handler 46 | */ 47 | void addHandler(typename EventHandler::ptr handler); 48 | void removeHandler(typename EventHandler::ptr handler); 49 | 50 | private: 51 | handler_set_type event_set_; 52 | }; 53 | 54 | }} 55 | 56 | 57 | namespace zertcore { 58 | 59 | /** 60 | * Helper functions 61 | */ 62 | template 63 | inline static void dispatchEvent(Event& e) { 64 | suit::EventBus::Instance().dispatch(e); 65 | } 66 | 67 | } 68 | 69 | #endif /* SUIT_EVENT_EVENTBUS_H_ */ 70 | -------------------------------------------------------------------------------- /zertco5/suit/event/EventHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * EventHandler.h 3 | * 4 | * Created on: 2015年8月18日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_SUIT_EVENT_EVENTHANDLER_H_ 9 | #define ZERTCORE_SUIT_EVENT_EVENTHANDLER_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { namespace suit { 15 | 16 | /** 17 | * EventHandler 18 | */ 19 | template 20 | class EventHandler 21 | { 22 | public: 23 | typedef EventHandler* ptr; 24 | 25 | public: 26 | EventHandler(); 27 | virtual ~EventHandler(); 28 | 29 | public: 30 | void addListener(); 31 | void removeListener(); 32 | 33 | public: 34 | virtual void onEvent(EventDerived& event) 35 | = 0; 36 | }; 37 | 38 | }} 39 | 40 | 41 | 42 | #endif /* SUIT_EVENT_EVENTHANDLER_H_ */ 43 | -------------------------------------------------------------------------------- /zertco5/suit/event/details/EventBusImpl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * EventBusImpl.hpp 3 | * 4 | * Created on: 2015年8月18日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_SUIT_EVENT_DETAILS_EVENTBUSIMPL_HPP_ 9 | #define ZERTCORE_SUIT_EVENT_DETAILS_EVENTBUSIMPL_HPP_ 10 | 11 | #include "../EventBus.h" 12 | 13 | namespace zertcore { namespace suit { 14 | 15 | template 16 | void EventBus:: 17 | dispatch(event_type& e) { 18 | for (auto it = event_set_.begin(); it != event_set_.end(); ++it) { 19 | (*it)->onEvent(e); 20 | 21 | // check for the event's status 22 | } 23 | } 24 | 25 | 26 | template 27 | void EventBus:: 28 | addHandler(typename EventHandler::ptr handler) { 29 | event_set_.insert(handler); 30 | } 31 | 32 | 33 | template 34 | void EventBus:: 35 | removeHandler(typename EventHandler::ptr handler) { 36 | event_set_.erase(handler); 37 | } 38 | 39 | }} 40 | 41 | 42 | #endif /* SUIT_EVENT_DETAILS_EVENTBUSIMPL_HPP_ */ 43 | -------------------------------------------------------------------------------- /zertco5/suit/event/details/EventHandlerImpl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * EventHandlerImpl.hpp 3 | * 4 | * Created on: 2015年8月18日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_SUIT_EVENT_DETAILS_EVENTHANDLERIMPL_HPP_ 9 | #define ZERTCORE_SUIT_EVENT_DETAILS_EVENTHANDLERIMPL_HPP_ 10 | 11 | #include "../EventHandler.h" 12 | #include "../EventBus.h" 13 | 14 | namespace zertcore { namespace suit { 15 | 16 | template 17 | EventHandler::EventHandler() { 18 | addListener(); 19 | } 20 | 21 | template 22 | EventHandler::~EventHandler() { 23 | removeListener(); 24 | } 25 | 26 | template 27 | void EventHandler:: 28 | addListener() { 29 | EventBus::Instance().addHandler(this); 30 | } 31 | 32 | template 33 | void EventHandler:: 34 | removeListener() { 35 | EventBus::Instance().removeHandler(this); 36 | } 37 | 38 | }} 39 | 40 | 41 | #endif /* SUIT_EVENT_DETAILS_EVENTHANDLERIMPL_HPP_ */ 42 | -------------------------------------------------------------------------------- /zertco5/suit/period32/period.h: -------------------------------------------------------------------------------- 1 | /* 2 | * period.h 3 | * 4 | * Created on: 2015年9月15日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_SUIT_PERIOD32_PERIOD_H_ 9 | #define ZERTCORE_SUIT_PERIOD32_PERIOD_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { namespace suit { 15 | 16 | /** 17 | * the structure was design for 3 digit accuracy time and took just 32bit. 18 | * Mainly for transfer the time. 19 | * Notice the valid period was about 1 YEAR. 20 | */ 21 | struct Period32 22 | { 23 | u32 value; 24 | 25 | Period32& now(); 26 | 27 | public: 28 | static void init(); 29 | 30 | private: 31 | static u32 offset_; 32 | }; 33 | 34 | }} 35 | 36 | 37 | #endif /* SUIT_TIME32_TIME_H_ */ 38 | -------------------------------------------------------------------------------- /zertco5/suit/period32/period32.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * period32.cpp 3 | * 4 | * Created on: 2015年9月15日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "period.h" 9 | 10 | namespace zertcore { namespace suit { 11 | u32 Period32::offset_ = 0; 12 | }} 13 | 14 | namespace zertcore { namespace suit { 15 | 16 | Period32& Period32:: 17 | now() { 18 | struct timeval tv; 19 | gettimeofday(&tv, NULL); 20 | 21 | value = ((tv.tv_sec - offset_) * 1000) + (tv.tv_usec / 1000); 22 | 23 | return *this; 24 | } 25 | 26 | void Period32:: 27 | init() { 28 | offset_ = time(NULL); 29 | } 30 | 31 | }} 32 | -------------------------------------------------------------------------------- /zertco5/suit/session/details/CommandImpl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CommandImpl.hpp 3 | * 4 | * Created on: 2015年7月27日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_SUIT_SESSION_DETAILS_COMMANDIMPL_HPP_ 9 | #define ZERTCORE_SUIT_SESSION_DETAILS_COMMANDIMPL_HPP_ 10 | 11 | #include "../Session.h" 12 | 13 | namespace zertcore { namespace suit { 14 | 15 | template 16 | bool Session:: 17 | runPrepare() { 18 | SessionManager::Instance().registerSync(this->template thisPtr()); 19 | return true; 20 | } 21 | 22 | template 23 | bool Session:: 24 | runCommand() { 25 | SharedBuffer sb; 26 | if (!popMessage(sb)) { 27 | return false; 28 | } 29 | 30 | if (hasMessage()) { 31 | SessionManager::Instance().registerSync(this->template thisPtr()); 32 | } 33 | 34 | /** 35 | cmd::key_type key; 36 | cmd::params_type params; 37 | 38 | * parse command 39 | 40 | if (!cmd::parseCommand(sb, key, params)) { 41 | ZCLOG(ERROR) << "Parse failed" << End; 42 | return false; 43 | } 44 | */ 45 | 46 | /** 47 | typename cmd::CommandBase::ptr c = cmd::fetchCommand(sb); //cmd::CommandManager::Instance().get(key); 48 | if (!c) { 49 | ZCLOG(ERROR) << "Command not found" << End; 50 | return false; 51 | } 52 | c->run(this->template thisPtr(), sb); 53 | */ 54 | 55 | if (on_data_handler_) { 56 | on_data_handler_.setParams(this->template thisPtr(), sb); 57 | on_data_handler_.push(); 58 | } 59 | 60 | return true; 61 | } 62 | 63 | }} 64 | 65 | 66 | #endif /* SUIT_SESSION_DETAILS_COMMANDIMPL_HPP_ */ 67 | -------------------------------------------------------------------------------- /zertco5/suit/session/details/SessionManagerImpl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SessionManagerImpl.hpp 3 | * 4 | * Created on: 2015年8月17日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_SUIT_SESSION_DETAILS_SESSIONMANAGERIMPL_HPP_ 9 | #define ZERTCORE_SUIT_SESSION_DETAILS_SESSIONMANAGERIMPL_HPP_ 10 | 11 | #include "../Session.h" 12 | #include 13 | 14 | namespace zertcore { namespace suit { 15 | using namespace zertcore::concurrent; 16 | }} 17 | 18 | namespace zertcore { namespace suit { 19 | 20 | template 21 | typename SessionManager::session_ptr SessionManager:: 22 | createSession() { 23 | return this->template create(++id_counter_, 0); 24 | } 25 | 26 | template 27 | bool SessionManager:: 28 | setup() { 29 | if (update::UpdateClient::Instance().isEnabled()) { 30 | update::updater_type handler([this] (u32 count) { 31 | handleSessions(); 32 | }, this->template getThreadIndex()); 33 | 34 | update::UpdateClient::Instance().registerHandler(handler); 35 | } 36 | else { 37 | RT.addUpdater(&SessionManager::handleSessions, this); 38 | } 39 | 40 | is_setup_ = true; 41 | return true; 42 | } 43 | 44 | template 45 | void SessionManager:: 46 | registerSync(session_ptr session) { 47 | ZC_ASSERT(is_setup_); 48 | sync_list_.add(session); 49 | } 50 | 51 | template 52 | u32 SessionManager:: 53 | handleSessions() { 54 | u32 ret = sync_list_.size(); 55 | sync_list_.foreach([] (session_ptr session) { 56 | session->runCommand(); 57 | }); 58 | 59 | return ret; 60 | } 61 | 62 | }} 63 | 64 | 65 | #endif /* SUIT_SESSION_DETAILS_SESSIONMANAGERIMPL_HPP_ */ 66 | -------------------------------------------------------------------------------- /zertco5/suit/skill/Skill.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Skill.h 3 | * 4 | * Created on: 2015年6月24日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_SUIT_SKILL_SKILL_H_ 9 | #define ZERTCORE_SUIT_SKILL_SKILL_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include "buff/Buff.h" 15 | 16 | namespace zertcore { namespace utils { 17 | 18 | struct SkillTarget 19 | { 20 | }; 21 | 22 | }} 23 | 24 | 25 | 26 | #endif /* SUIT_SKILL_SKILL_H_ */ 27 | -------------------------------------------------------------------------------- /zertco5/suit/utils/RateValue.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * RateValue.cpp 3 | * 4 | * Created on: 2015年7月14日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "RateValue.h" 9 | 10 | namespace zertcore { namespace suit { 11 | 12 | RateValue& RateValue:: 13 | operator += (const RateValue& rv) { 14 | rate += rv.rate; 15 | value += rv.value; 16 | return *this; 17 | } 18 | 19 | double RateValue:: 20 | operator() (const double& v) const { 21 | return (v + value) * (1 + rate); 22 | } 23 | 24 | RateValue operator+ (const RateValue& r1, const RateValue& r2) { 25 | RateValue rv(r1); 26 | return rv += r2; 27 | } 28 | 29 | double operator* (const RateValue& rv, const double& v) { 30 | return rv(v); 31 | } 32 | 33 | double operator* (const double& v, const RateValue& rv) { 34 | return rv(v); 35 | } 36 | 37 | }} 38 | 39 | -------------------------------------------------------------------------------- /zertco5/suit/utils/RateValue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * RateValue.h 3 | * 4 | * Created on: 2015年7月14日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_SUIT_UTILS_RATEVALUE_H_ 9 | #define ZERTCORE_SUIT_UTILS_RATEVALUE_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { namespace suit { 15 | 16 | /** 17 | * RateValue 18 | */ 19 | struct RateValue : Unserializable, Serializable 20 | { 21 | double rate{0}; 22 | double value{0}; 23 | 24 | public: 25 | template 26 | void serialize(Archiver& archiver) const { 27 | archiver["rate"] & rate; 28 | archiver["value"] & value; 29 | } 30 | 31 | template 32 | bool unserialize(Archiver& archiver) { 33 | archiver["rate"] & rate; 34 | archiver["value"] & value; 35 | 36 | return rate > 0 || value > 0; 37 | } 38 | 39 | public: 40 | RateValue& operator += (const RateValue& rv); 41 | double operator() (const double& v) const; 42 | }; 43 | 44 | 45 | RateValue operator+ (const RateValue& r1, const RateValue& r2); 46 | double operator* (const RateValue& rv, const double& v); 47 | double operator* (const double& v, const RateValue& rv); 48 | 49 | }} 50 | 51 | 52 | #endif /* SUIT_UTILS_RATEVALUE_H_ */ 53 | -------------------------------------------------------------------------------- /zertco5/test/buffer/test1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test1.cpp 3 | * 4 | * Created on: 2015年1月29日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | 10 | using namespace zertcore; 11 | using namespace zertcore::utils; 12 | 13 | void f1(const SharedBuffer& buff) { 14 | ZC_ASSERT(buff.size() == 60); 15 | for (u32 i = 0; i < 17; ++i) { 16 | ::printf("%c", buff[i]); 17 | } 18 | ::printf("\n"); 19 | } 20 | 21 | void f2(const SharedBuffer& buff) { 22 | for (u32 i = 0; i < 17; ++i) { 23 | ::printf("%c", buff[i]); 24 | } 25 | ::printf("\n"); 26 | f1(buff.slice(4)); 27 | } 28 | 29 | void f3(SharedBuffer buff) { 30 | for (u32 i = 0; i < 17; ++i) { 31 | ::printf("%c", buff[i]); 32 | } 33 | ::printf("\n"); 34 | 35 | f2(buff); 36 | } 37 | 38 | void f4() { 39 | // SharedBuffer buff_error_here; 40 | SharedBuffer buff(64); 41 | strcpy((char *)&buff[0], "show me the money"); 42 | 43 | f3(buff); 44 | } 45 | 46 | int main() { 47 | f4(); 48 | 49 | printf("the buffer should be released\n"); 50 | 51 | return 0; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /zertco5/test/circular_buffer_test1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/test/circular_buffer_test1.cpp -------------------------------------------------------------------------------- /zertco5/test/concurrent/context2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * context2.cpp 3 | * 4 | * Created on: 2015年7月31日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | ucontext_t fcm, begin_fc; 12 | 13 | class ContextState 14 | { 15 | public: 16 | void run() { 17 | static int a = 123; 18 | ::printf("in state run:%d\n", a++); 19 | yeild(); 20 | ::printf("resume state run:%d\n", a++); 21 | } 22 | void yeild() { 23 | ::printf("before yeild\n"); 24 | swapcontext(&now_fc_, &begin_fc); 25 | ::printf("after yeild\n"); 26 | } 27 | void resume() { 28 | swapcontext(&begin_fc, &now_fc_); 29 | } 30 | 31 | private: 32 | ucontext_t now_fc_; 33 | }; 34 | 35 | void run(void * params) { 36 | ::printf("in run\n"); 37 | ContextState* state = (ContextState*)params; 38 | 39 | ::printf("begin run\n"); 40 | state->run(); 41 | ::printf("end run\n"); 42 | swapcontext(&fcm, &begin_fc); 43 | } 44 | 45 | #define N 1000 46 | 47 | int main() { 48 | char * buffer; 49 | ContextState states[N]; 50 | 51 | 52 | for (int i = 0; i < N; ++i) { 53 | ContextState* state = & states[i]; 54 | getcontext(&fcm); 55 | fcm.uc_stack.ss_sp = new char[8192]; 56 | fcm.uc_stack.ss_size = 8192; 57 | fcm.uc_link = &begin_fc; 58 | makecontext(&fcm, (void (*)())run, 1, state); 59 | 60 | printf("jump run:%d\n", i); 61 | swapcontext(&begin_fc, &fcm); 62 | } 63 | 64 | printf("------------------------------------\n"); 65 | 66 | for (int i = 0; i < N; ++i) { 67 | ContextState* state = & states[i]; 68 | 69 | printf("before resume\n"); 70 | state->resume(); 71 | printf("after resume:%d\n", i); 72 | } 73 | 74 | ::printf("ALL End\n"); 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /zertco5/test/concurrent/rpc_test1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * rpc_test1.cpp 3 | * 4 | * Created on: 2015年3月4日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | 10 | using namespace zertcore::concurrent::rpc; 11 | 12 | void hello(const key_type&, const oachiver_type& params, iachiver_type& ret_data) { 13 | ret_data["ret"] & 1; 14 | } 15 | 16 | int main() { 17 | RPCManager::Instance().registerRPCHandler("hello", hello); 18 | return 0; 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /zertco5/test/concurrent/test1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/test/concurrent/test1.cpp -------------------------------------------------------------------------------- /zertco5/test/database/test1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/test/database/test1.cpp -------------------------------------------------------------------------------- /zertco5/test/encrypt/test1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test1.cpp 3 | * 4 | * Created on: 2015年6月18日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | 10 | using namespace zertcore::utils; 11 | 12 | int main() { 13 | Crypto::randkey_type rdk; 14 | Crypto::prepareRandkey(rdk, "show me the money"); 15 | 16 | SharedBuffer sb; 17 | sb.assign(std::string("operation cwal")); 18 | 19 | ZC_ASSERT( Crypto::doXor(sb, rdk) ); 20 | ::printf("%s\n", (const char *)sb.data()); 21 | 22 | ZC_ASSERT( Crypto::doXor(sb, rdk) ); 23 | 24 | ::printf("%s\n", (const char *)sb.data()); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /zertco5/test/event/e1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * e1.cpp 3 | * 4 | * Created on: 2015年8月24日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | 10 | namespace zertcore { 11 | using namespace zertcore::suit; 12 | 13 | struct MoveEvent 14 | { 15 | u32 x, 16 | y; 17 | }; 18 | 19 | class Player : 20 | public EventHandler 21 | { 22 | public: 23 | void onEvent(MoveEvent& event) { 24 | ::printf("Player receive:(%u, %u)\n", event.x, event.y); 25 | } 26 | 27 | public: 28 | void move(u32 x, u32 y) { 29 | MoveEvent evt; 30 | evt.x = x; evt.y = y; 31 | 32 | dispatchEvent(evt); 33 | } 34 | }; 35 | 36 | 37 | class Map : 38 | public EventHandler 39 | { 40 | public: 41 | void onEvent(MoveEvent& event) { 42 | ::printf("map receive:(%u, %u)\n", event.x, event.y); 43 | } 44 | }; 45 | 46 | 47 | } 48 | 49 | 50 | int main() { 51 | using namespace zertcore; 52 | config.concurrent.thread_nums = 1; 53 | 54 | Player player1, player2; 55 | Map map; 56 | 57 | player1.move(1, 2); 58 | player2.move(2, 3); 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /zertco5/test/http/server.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * server.cpp 3 | * 4 | * Created on: 2015年10月19日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | 10 | using namespace zertcore; 11 | 12 | int main() { 13 | net::HttpServer server; 14 | config.concurrent.thread_nums = 1; 15 | 16 | ZC_ASSERT( server.init() ); 17 | 18 | utils::SharedBuffer sb; 19 | sb.assign("show me the money"); 20 | 21 | RT.globalInit([&]() { 22 | server.setHandler([&](ServerConnection::ptr conn) { 23 | conn->response(sb); 24 | }); 25 | }); 26 | 27 | RT.run(); 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /zertco5/test/http/test2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test2.cpp 3 | * 4 | * Created on: 2015年10月17日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace zertcore; 13 | using namespace zertcore::utils; 14 | 15 | int main() { 16 | ZCLOG_SETUP(); 17 | 18 | SharedBuffer sb; 19 | sb.assign("GET /s?wd=hahahahah&rsv_spt=1&rsv_iqid=0xd8e006760008468e&issp=1&f=8&rsv_bp=0&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_enter=1&rsv_sug3=9&rsv_sug1=7&rsv_t=d827qxhuzWkayyj2%2FUMfElGgk8c%2BUb2Hj82UVXsYrMWMYvoVi8IP5kOpI78wz9LUR3W1&rsv_sug2=0&inputT=1196&rsv_sug4=1196 HTTP/1.1\nHost: www.atool.org\nUser-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0\nAccept: application/json, text/javascript, */*; q=0.01\nAccept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3\nAccept-Encoding: gzip, deflate\nContent-Type: application/x-www-form-urlencoded; charset=UTF-8\nX-Requested-With: XMLHttpRequest\nReferer: http://www.atool.org/httptest.php\nContent-Length: 223\nCookie: PHPSESSID=ch6jf0gfsleueobtchlu41hhi4; Hm_lvt_b169f904ade5ef8ef30b1f93eb03f0ef=1444978828; Hm_lpvt_b169f904ade5ef8ef30b1f93eb03f0ef=1444978828; CNZZDATA5763499=cnzz_eid%3D674376197-1444977118-http%253A%252F%252Fwww.baidu.com%252F%26ntime%3D1444977118; http_url=www.baidu.com; method=POST; params=hahahahaha%3Dhehehehehe%26lalala%3D123%26gogogo%3Dpppppp; headers=\nConnection: keep-alive\nPragma: no-cache\nCache-Control: no-cache\n\n"); 20 | 21 | HttpContext hc; 22 | ret_type r = parseHttp(sb, hc); 23 | 24 | ::printf("r=%u\n", r); 25 | ::printf("uri:%s\n\n", (const char *)hc.header.uri.data()); 26 | 27 | string rsv_t = hc.getQuery("rsv_t"); 28 | 29 | hc.printQuery(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /zertco5/test/log/test1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test1.cpp 3 | * 4 | * Created on: 2015��1��22�� 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace zertcore; 13 | using namespace zertcore::object; 14 | using namespace zertcore::core; 15 | 16 | struct Test : public PoolObject 17 | { 18 | uint a, b, c; 19 | 20 | ZC_TO_STRING("a" << a << "b" << b << "c" << c); 21 | }; 22 | 23 | int main() { 24 | RT.init([]() { 25 | ZCLOG(NOTICE) << "Hello there!" << End; 26 | Test::ptr test = Test::create(); 27 | test->a = 1; 28 | test->b = 2; 29 | test->c = 3; 30 | 31 | ZCLOG(ERROR) << test << End; 32 | }); 33 | RT.run(); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /zertco5/test/msgpack-test1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/test/msgpack-test1.cpp -------------------------------------------------------------------------------- /zertco5/test/msgpack-test2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * msgpack-test2.cpp 3 | * 4 | * Created on: 2015年2月3日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | void f() { 14 | ; 15 | } 16 | 17 | int main() { 18 | // This is target object. 19 | std::vector target; 20 | target.push_back("Hello,"); 21 | target.push_back("World!"); 22 | 23 | // Serialize it. 24 | msgpack::sbuffer sbuf; // simple buffer 25 | msgpack::pack(&sbuf, target); 26 | 27 | std::cout << sbuf.size() << std::endl; 28 | 29 | // Deserialize the serialized data. 30 | msgpack::unpacked msg; // includes memory pool and deserialized object 31 | msgpack::unpack(msg, sbuf.data(), sbuf.size()); 32 | msgpack::object obj = msg.get(); 33 | 34 | msgpack::sbuffer otherbuf; 35 | msgpack::pack(&otherbuf, obj); 36 | msgpack::unpacked othermsg; 37 | msgpack::unpack(othermsg, otherbuf.data(), otherbuf.size()); 38 | msgpack::object otherobj = othermsg.get(); 39 | 40 | // Print the deserialized object to stdout. 41 | std::cout << otherobj << std::endl; // ["Hello," "World!"] 42 | 43 | // Convert the deserialized object to staticaly typed object. 44 | std::vector result; 45 | obj.convert(&result); 46 | 47 | } 48 | 49 | 50 | -------------------------------------------------------------------------------- /zertco5/test/net/client/client.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | namespace zertcore { 7 | using namespace zertcore::net; 8 | using namespace zertcore::net::client; 9 | 10 | class RPCClient; 11 | 12 | class RPCClientConnection : 13 | public ConnectionBase 14 | { 15 | public: 16 | RPCClientConnection(RPCClient& service) : ConnectionBase(service) {} 17 | virtual ~RPCClientConnection() {} 18 | 19 | public: 20 | virtual size_t onRead(const SharedBuffer& buffer) { 21 | ::printf("onRead : %s\n\n\n", buffer.data()); 22 | return buffer.size(); 23 | } 24 | 25 | public: 26 | void sendRequest() { 27 | string req("GET / HTTP/1.0\r\nHost: www.baidu.com\r\nConnection: close\r\n\r\n"); 28 | asyncWrite((const u8 *)req.data(), req.size()); 29 | } 30 | }; 31 | 32 | class RPCClient : 33 | public ClientBase, 34 | public Singleton 35 | { 36 | public: 37 | RPCClient() : ClientBase() {} 38 | virtual ~RPCClient() {} 39 | }; 40 | 41 | } 42 | 43 | int main() { 44 | zertcore::net::ClientConfig cc; 45 | cc.thread_nums = 1; 46 | cc.enable_ssl = false; 47 | 48 | zertcore::RPCClientConnection::ptr conn; 49 | zertcore::RPCClient::Instance().init(cc); 50 | 51 | conn = zertcore::RPCClient::Instance().connect("www.baidu.com", 80); 52 | ZC_ASSERT(conn); 53 | conn->sendRequest(); 54 | 55 | RT.init([&conn] { 56 | 57 | }); 58 | // zertcore::RPCClient::Instance().getIOService().run(); 59 | RT.run(); 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /zertco5/test/net/server/http_test1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * http_test1.cpp 3 | * 4 | * Created on: 2015��1��12�� 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace zertcore; 14 | using namespace zertcore::net; 15 | 16 | int main() { 17 | ServerConfig server_config; 18 | server_config.accept_nums = 10; 19 | server_config.enable_ssl = false; 20 | server_config.host = "0.0.0.0"; 21 | server_config.port = 80; 22 | server_config.thread_nums = 10; 23 | 24 | ::printf("define server\n"); 25 | server::HttpServer server; 26 | 27 | config.concurrent.thread_nums = 1; 28 | 29 | ::printf("init server..\n"); 30 | ZC_ASSERT(server.init(server_config)); 31 | 32 | ::printf("RT.init\n"); 33 | RT.init([&]() { 34 | 35 | server::HttpServer::handler_type hd([] (HttpServerConnection::ptr conn) -> void { 36 | ZCLOG(NOTICE) << "Hello there!" << End; 37 | 38 | string s = "

Hello there:" 39 | + conn->request().getURI() + "

"; 40 | 41 | if (conn->request().getAction() == zertcore::net::details::HttpRequest::ACTION_POST) { 42 | s += "
You are posting to this page, content:XXX
"; 43 | } 44 | else { 45 | s += "
"; 46 | } 47 | s += ""; 48 | 49 | conn->response().setResponse(s); 50 | conn->flush(); 51 | }); 52 | 53 | ::printf("set handler..\n"); 54 | server.setHandler(hd); 55 | }); 56 | RT.run(); 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /zertco5/test/net/udp/test1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test1.cpp 3 | * 4 | * Created on: 2015年6月14日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | 10 | namespace zertcore { namespace net { namespace udp { 11 | 12 | class Server; 13 | 14 | class Connection : public PackageConnection 15 | { 16 | public: 17 | explicit Connection(Server& server, peer_ptr peer) : 18 | PackageConnection(server, peer) {} 19 | 20 | ZC_TO_STRING("Connection" << getRemoteConfig().toString()); 21 | }; 22 | 23 | class Server : public ServerBase 24 | { 25 | }; 26 | 27 | }}} 28 | 29 | using namespace zertcore; 30 | 31 | int main() { 32 | config.concurrent.thread_nums = 1; 33 | net::udp::Server server; 34 | net::udp::ServerConfig server_config; 35 | server_config.host = "0.0.0.0"; 36 | server_config.port = 1333; 37 | 38 | ZC_ASSERT( server.setup(server_config) ); 39 | 40 | RT.globalInit([&] () { 41 | 42 | }); 43 | RT.run(); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /zertco5/test/practice/plot1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/test/practice/plot1.cpp -------------------------------------------------------------------------------- /zertco5/test/practice/test1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/test/practice/test1.cpp -------------------------------------------------------------------------------- /zertco5/test/practice/test2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/test/practice/test2.cpp -------------------------------------------------------------------------------- /zertco5/test/practice/test3.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/test/practice/test3.cpp -------------------------------------------------------------------------------- /zertco5/test/practice/test4.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test4.cpp 3 | * 4 | * Created on: 2015年2月4日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | 10 | namespace zertcore { 11 | 12 | struct Callable 13 | { 14 | int v; 15 | void operator() () {printf("%d\n", v);} 16 | }; 17 | 18 | void call(const function& handler) { 19 | handler(); 20 | } 21 | 22 | } 23 | 24 | using namespace zertcore; 25 | 26 | int main() { 27 | std::vector > list; 28 | Callable ca; 29 | ca.v = 0; 30 | list.push_back(ca); 31 | ca.v = 1; 32 | list.push_back(ca); 33 | ca.v = 2; 34 | list.push_back(ca); 35 | 36 | std::for_each(list.begin(), list.end(), &call); 37 | 38 | return 0; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /zertco5/test/practice/test5.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test5.cpp 3 | * 4 | * Created on: 2015年2月6日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | 10 | int main() { 11 | unsigned long long t = 0xECA16DB97F6789AC; 12 | t ^= 0x1357924680987654; 13 | t = ~t; 14 | 15 | unsigned int prestige_level = (t >> 48); 16 | t &= 0xFFFFFFFFFFFF; 17 | 18 | printf("prestige=%u %u\n", prestige_level, t); 19 | 20 | return 0; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /zertco5/test/practice/test6.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test6.cpp 3 | * 4 | * Created on: 2015年4月27日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | template 12 | class Base 13 | { 14 | public: 15 | typedef Final self; 16 | 17 | public: 18 | }; 19 | 20 | class F : public Base 21 | { 22 | public: 23 | void work() { 24 | bind(&self::work, this); 25 | } 26 | }; 27 | 28 | int main() { 29 | return 0; 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /zertco5/test/practice/test7.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test7.cpp 3 | * 4 | * Created on: 2015年6月1日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace boost; 14 | 15 | class C 16 | { 17 | public: 18 | template 19 | void push(Callable caller) { 20 | _push(is_member_function_pointer(), caller); 21 | } 22 | 23 | public: 24 | template 25 | void _push(const true_type& _, Callable caller) { 26 | typedef decltype((this->*caller)()) r_type; 27 | bind(caller, this)(); 28 | } 29 | 30 | template 31 | void _push(const false_type& _, Callable caller) { 32 | bind(caller)(); 33 | } 34 | 35 | public: 36 | void test() {printf("test\n");} 37 | 38 | private: 39 | }; 40 | 41 | int main() { 42 | C c; 43 | c.push(&C::test); 44 | 45 | return 0; 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /zertco5/test/rpc/cond_test1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * cond_test1.cpp 3 | * 4 | * Created on: 2015年6月29日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | 10 | using namespace zertcore; 11 | using namespace zertcore::concurrent; 12 | 13 | bool test(const rpc::condition_group& expr, rpc::oarchiver_type& v) { 14 | return expr(v); 15 | } 16 | 17 | int main() { 18 | rpc::iarchiver_type iar; 19 | iar["test"] & 8; 20 | 21 | rpc::oarchiver_type oar(iar); 22 | 23 | if (test(rpc::condition("test", cond::BETWEEN, 5, 8), oar)) { 24 | ::printf("yes\n"); 25 | } 26 | else { 27 | ::printf("no\n"); 28 | } 29 | 30 | return 0; 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /zertco5/test/rpc/test1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test1.cpp 3 | * 4 | * Created on: 2015年2月3日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace zertcore; 14 | using namespace zertcore::concurrent::rpc; 15 | 16 | int main() { 17 | ZC_ASSERT( 18 | RPCManager::Instance().init( 19 | RemoteConfig("127.0.0.1", 20010), 20 | RemoteConfig("127.0.0.1", 20011) 21 | )); 22 | config.concurrent.thread_nums = 3; 23 | 24 | RT.init([&]() { 25 | RPCRouterConfig router_config; 26 | router_config.host = "127.0.0.1"; 27 | router_config.port = 20007; 28 | 29 | RPCManager::Instance().connectRouter(router_config); 30 | 31 | RPCManager::Instance().registerRPCHandler("echo", [] (key_type, 32 | oarchiver_type params, iarchiver_type& ret_data) { 33 | string text; 34 | 35 | sleep(1000); 36 | params["text"] & text; 37 | ret_data["text"] & text; 38 | }); 39 | 40 | RPCManager::Instance().setRPCReadyHandler([] () { 41 | ZCLOG(NOTE) << "RPC is now ready." << End; 42 | 43 | RPCManager::Instance().setRPCReadyHandler(); 44 | 45 | iarchiver_type i; 46 | i["text"] & "show me the money"; 47 | 48 | ZC_ASSERT( 49 | RPCManager::Instance().asyncCall("echo", i, [] (key_type key, Error error, oarchiver_type o) { 50 | string text; 51 | o["text"] & text; 52 | 53 | if (error) { 54 | ZCLOG(NOTE) << "Got Error:" << error << End; 55 | } 56 | 57 | ZCLOG(NOTE) << key << " ret=" << text << End; 58 | 59 | }) ); 60 | }); 61 | RPCManager::Instance().finishRegister(); 62 | }); 63 | 64 | RT.run(); 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /zertco5/test/rpc/test2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test2.cpp 3 | * 4 | * Created on: 2015年4月10日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace zertcore; 14 | using namespace zertcore::concurrent::rpc; 15 | 16 | int main() { 17 | ZC_ASSERT( 18 | RPCManager::Instance().init( 19 | RemoteConfig("127.0.0.1", 20020), 20 | RemoteConfig("127.0.0.1", 20021) 21 | )); 22 | config.concurrent.thread_nums = 3; 23 | 24 | RT.init([&]() { 25 | RPCRouterConfig router_config; 26 | router_config.host = "127.0.0.1"; 27 | router_config.port = 20007; 28 | 29 | RPCManager::Instance().connectRouter(router_config); 30 | 31 | RPCManager::Instance().setRPCReadyHandler([] () { 32 | ZCLOG(NOTE) << "RPC is now ready." << End; 33 | 34 | for (int index = 0; index < 10000; ++index) { 35 | iarchiver_type i; 36 | i["text"] & ("operation cwal:" + lexical_cast(index)); 37 | 38 | ZC_ASSERT( 39 | RPCManager::Instance().asyncCall("echo", i, [] (key_type key, Error error, oarchiver_type o) { 40 | string text; 41 | o["text"] & text; 42 | 43 | ZCLOG(NOTE) << "echo ret=" << text.c_str() << End; 44 | 45 | RT.stop(); 46 | }) ); 47 | } 48 | 49 | }); 50 | 51 | RPCManager::Instance().finishRegister(); 52 | }); 53 | 54 | RT.run(); 55 | return 0; 56 | } 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /zertco5/test/rpc/update1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * update1.cpp 3 | * 4 | * Created on: 2015年5月28日 5 | * Author: Administrator 6 | */ 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | using namespace zertcore; 13 | using namespace zertcore::concurrent::rpc; 14 | using namespace zertcore::concurrent::update; 15 | 16 | int main(int argc, char *argv[]) { 17 | u32 port = lexical_cast(argv[1]); 18 | config.concurrent.thread_nums = 3; 19 | 20 | ZC_ASSERT( 21 | RPC.setup( 22 | RemoteConfig("127.0.0.1", port), 23 | RemoteConfig("127.0.0.1", port + 1) 24 | )); 25 | 26 | RPCRouterConfig router_config; 27 | router_config.host = "127.0.0.1"; 28 | router_config.port = 20007; 29 | 30 | RT.globalInit([&]() { 31 | ZC_ASSERT(RT.setupRouter(router_config)); 32 | ZC_ASSERT(UpdateClient::Instance().globalInit()); 33 | 34 | UpdateClient::Instance().registerHandler([] (const tick_type& tick) { 35 | ZCLOG(NOTICE) << "Got tick!" << End; 36 | }); 37 | }); 38 | RT.run(); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /zertco5/test/serialize/bsonstream_test2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * bsonstream_test2.cpp 3 | * 4 | * Created on: 2015年9月10日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | 10 | 11 | using namespace zertcore; 12 | using namespace zertcore::serialization; 13 | using namespace zertcore::db::mongodb::serialization; 14 | 15 | int main() { 16 | Serializer in; 17 | Unserializer out; 18 | 19 | map m1, m2; 20 | m1["haha"] = 1; 21 | m1["hehe"] = 2; 22 | 23 | in["show1"] & 1; 24 | in["show2"]["me"] & 2; 25 | in["show3"]["me"]["the"] & 3; 26 | in["show4"]["me"]["the"]["money"] & 4; 27 | 28 | in["black1"] & "black"; 29 | in["black2"]["sheep"] & "sheep"; 30 | in["black3"]["sheep"]["wall"] & "wall"; 31 | 32 | in["laugth"]["for"]["ever"] & m1; 33 | 34 | SharedBuffer sb = in.buffer(); 35 | ::printf("%s\n", sb.data()); 36 | out.buffer(sb); 37 | 38 | u32 a, b, c, d; 39 | string s1, s2, s3; 40 | 41 | out["show1"] & a; 42 | out["show2"]["me"] & b; 43 | out["show3"]["me"]["the"] & c; 44 | out["show4"]["me"]["the"]["money"] & d; 45 | 46 | out["black1"] & s1; 47 | out["black2"]["sheep"] & s2; 48 | out["black3"]["sheep"]["wall"] & s3; 49 | 50 | out["laugth"]["for"]["ever"] & m2; 51 | 52 | ::printf("%d %d %d %d\n%s %s %s\n", a, b, c, d, s1.c_str(), s2.c_str(), s3.c_str()); 53 | 54 | for (auto it = m2.begin(); it != m2.end(); ++it) { 55 | ::printf("k:%s v:%u\n", it->first.c_str(), it->second); 56 | } 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /zertco5/test/serialize/serialize_object_test1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * serialize_object_test1.cpp 3 | * 4 | * Created on: 2015年7月17日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | 10 | using namespace zertcore; 11 | using namespace zertcore::utils; 12 | using namespace zertcore::serialization; 13 | 14 | struct TestS : public SerializableObject 15 | { 16 | ZCVal(int, v1); 17 | ZCVal(string, v2); 18 | }; 19 | 20 | struct TestS1 : public SerializableObject 21 | { 22 | ZCVal(int, id); 23 | ZCVal(TestS, s); 24 | }; 25 | 26 | 27 | int main() { 28 | TestS1 ts; 29 | 30 | ts.id = 123456; 31 | ts.s.v1 = 0; 32 | ts.s.v2 = "show"; 33 | 34 | 35 | mongodb_iarchiver_type iar; 36 | iar.setIgnoreNull(); 37 | iar & ts; 38 | 39 | printf("%s\n", iar.buffer().data()); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /zertco5/test/serialize/simple-bson-input.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/test/serialize/simple-bson-input.cpp -------------------------------------------------------------------------------- /zertco5/test/serialize/simple-bson-output.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/test/serialize/simple-bson-output.cpp -------------------------------------------------------------------------------- /zertco5/test/serialize/test1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * test1.cpp 3 | * 4 | * Created on: 2014-4-29 5 | * Author: Administrator 6 | */ 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | using namespace zertcore; 13 | using namespace zertcore::utils; 14 | 15 | typedef serialization::Serializer 16 | iachiver_type; 17 | 18 | void f(iachiver_type i) {} 19 | 20 | int main() { 21 | iachiver_type i; 22 | f(i); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /zertco5/test/serialize/test2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/test/serialize/test2.cpp -------------------------------------------------------------------------------- /zertco5/test/utils/tags_map_test1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * tags_map_test1.cpp 3 | * 4 | * Created on: 2015-2-17 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | 10 | using namespace zertcore; 11 | using namespace zertcore::utils; 12 | 13 | int main() { 14 | typedef TagsMap tags_map_type; 15 | tags_map_type tags; 16 | 17 | tags.insert(32, "show"); 18 | tags.insert(84, "me", 1000); 19 | tags.insert(139, 1001); 20 | auto it = tags.insert(233); 21 | it.tag("the"); 22 | it.tag(12); 23 | 24 | tags.erase(it); 25 | tags.erase(12); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /zertco5/third_parties/enet/callbacks.h: -------------------------------------------------------------------------------- 1 | /** 2 | @file callbacks.h 3 | @brief ENet callbacks 4 | */ 5 | #ifndef __ENET_CALLBACKS_H__ 6 | #define __ENET_CALLBACKS_H__ 7 | 8 | #include 9 | 10 | typedef struct _ENetCallbacks 11 | { 12 | void * (ENET_CALLBACK * malloc) (size_t size); 13 | void (ENET_CALLBACK * free) (void * memory); 14 | void (ENET_CALLBACK * no_memory) (void); 15 | } ENetCallbacks; 16 | 17 | /** @defgroup callbacks ENet internal callbacks 18 | @{ 19 | @ingroup private 20 | */ 21 | extern void * enet_malloc (size_t); 22 | extern void enet_free (void *); 23 | 24 | /** @} */ 25 | 26 | #endif /* __ENET_CALLBACKS_H__ */ 27 | 28 | -------------------------------------------------------------------------------- /zertco5/third_parties/enet/list.h: -------------------------------------------------------------------------------- 1 | /** 2 | @file list.h 3 | @brief ENet list management 4 | */ 5 | #ifndef __ENET_LIST_H__ 6 | #define __ENET_LIST_H__ 7 | 8 | #include 9 | 10 | typedef struct _ENetListNode 11 | { 12 | struct _ENetListNode * next; 13 | struct _ENetListNode * previous; 14 | } ENetListNode; 15 | 16 | typedef ENetListNode * ENetListIterator; 17 | 18 | typedef struct _ENetList 19 | { 20 | ENetListNode sentinel; 21 | } ENetList; 22 | 23 | extern void enet_list_clear (ENetList *); 24 | 25 | extern ENetListIterator enet_list_insert (ENetListIterator, void *); 26 | extern void * enet_list_remove (ENetListIterator); 27 | extern ENetListIterator enet_list_move (ENetListIterator, void *, void *); 28 | 29 | extern size_t enet_list_size (ENetList *); 30 | 31 | #define enet_list_begin(list) ((list) -> sentinel.next) 32 | #define enet_list_end(list) (& (list) -> sentinel) 33 | 34 | #define enet_list_empty(list) (enet_list_begin (list) == enet_list_end (list)) 35 | 36 | #define enet_list_next(iterator) ((iterator) -> next) 37 | #define enet_list_previous(iterator) ((iterator) -> previous) 38 | 39 | #define enet_list_front(list) ((void *) (list) -> sentinel.next) 40 | #define enet_list_back(list) ((void *) (list) -> sentinel.previous) 41 | 42 | #endif /* __ENET_LIST_H__ */ 43 | 44 | -------------------------------------------------------------------------------- /zertco5/third_parties/enet/time.h: -------------------------------------------------------------------------------- 1 | /** 2 | @file time.h 3 | @brief ENet time constants and macros 4 | */ 5 | #ifndef __ENET_TIME_H__ 6 | #define __ENET_TIME_H__ 7 | 8 | #define ENET_TIME_OVERFLOW 86400000 9 | 10 | #define ENET_TIME_LESS(a, b) ((a) - (b) >= ENET_TIME_OVERFLOW) 11 | #define ENET_TIME_GREATER(a, b) ((b) - (a) >= ENET_TIME_OVERFLOW) 12 | #define ENET_TIME_LESS_EQUAL(a, b) (! ENET_TIME_GREATER (a, b)) 13 | #define ENET_TIME_GREATER_EQUAL(a, b) (! ENET_TIME_LESS (a, b)) 14 | 15 | #define ENET_TIME_DIFFERENCE(a, b) ((a) - (b) >= ENET_TIME_OVERFLOW ? (b) - (a) : (a) - (b)) 16 | 17 | #endif /* __ENET_TIME_H__ */ 18 | 19 | -------------------------------------------------------------------------------- /zertco5/third_parties/enet/types.h: -------------------------------------------------------------------------------- 1 | /** 2 | @file types.h 3 | @brief type definitions for ENet 4 | */ 5 | #ifndef __ENET_TYPES_H__ 6 | #define __ENET_TYPES_H__ 7 | 8 | typedef unsigned char enet_uint8; /**< unsigned 8-bit type */ 9 | typedef unsigned short enet_uint16; /**< unsigned 16-bit type */ 10 | typedef unsigned int enet_uint32; /**< unsigned 32-bit type */ 11 | 12 | #endif /* __ENET_TYPES_H__ */ 13 | 14 | -------------------------------------------------------------------------------- /zertco5/third_parties/enet/unix.h: -------------------------------------------------------------------------------- 1 | /** 2 | @file unix.h 3 | @brief ENet Unix header 4 | */ 5 | #ifndef __ENET_UNIX_H__ 6 | #define __ENET_UNIX_H__ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef MSG_MAXIOVLEN 16 | #define ENET_BUFFER_MAXIMUM MSG_MAXIOVLEN 17 | #endif 18 | 19 | typedef int ENetSocket; 20 | 21 | #define ENET_SOCKET_NULL -1 22 | 23 | #define ENET_HOST_TO_NET_16(value) (htons (value)) /**< macro that converts host to net byte-order of a 16-bit value */ 24 | #define ENET_HOST_TO_NET_32(value) (htonl (value)) /**< macro that converts host to net byte-order of a 32-bit value */ 25 | 26 | #define ENET_NET_TO_HOST_16(value) (ntohs (value)) /**< macro that converts net to host byte-order of a 16-bit value */ 27 | #define ENET_NET_TO_HOST_32(value) (ntohl (value)) /**< macro that converts net to host byte-order of a 32-bit value */ 28 | 29 | typedef struct 30 | { 31 | void * data; 32 | size_t dataLength; 33 | } ENetBuffer; 34 | 35 | #define ENET_CALLBACK 36 | 37 | #define ENET_API extern 38 | 39 | typedef fd_set ENetSocketSet; 40 | 41 | #define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO (& (sockset)) 42 | #define ENET_SOCKETSET_ADD(sockset, socket) FD_SET (socket, & (sockset)) 43 | #define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLR (socket, & (sockset)) 44 | #define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET (socket, & (sockset)) 45 | 46 | #endif /* __ENET_UNIX_H__ */ 47 | 48 | -------------------------------------------------------------------------------- /zertco5/third_parties/enet/utility.h: -------------------------------------------------------------------------------- 1 | /** 2 | @file utility.h 3 | @brief ENet utility header 4 | */ 5 | #ifndef __ENET_UTILITY_H__ 6 | #define __ENET_UTILITY_H__ 7 | 8 | #define ENET_MAX(x, y) ((x) > (y) ? (x) : (y)) 9 | #define ENET_MIN(x, y) ((x) < (y) ? (x) : (y)) 10 | 11 | #endif /* __ENET_UTILITY_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /zertco5/third_parties/enet/win32.h: -------------------------------------------------------------------------------- 1 | /** 2 | @file win32.h 3 | @brief ENet Win32 header 4 | */ 5 | #ifndef __ENET_WIN32_H__ 6 | #define __ENET_WIN32_H__ 7 | 8 | #ifdef _MSC_VER 9 | #ifdef ENET_BUILDING_LIB 10 | #pragma warning (disable: 4267) // size_t to int conversion 11 | #pragma warning (disable: 4244) // 64bit to 32bit int 12 | #pragma warning (disable: 4018) // signed/unsigned mismatch 13 | #pragma warning (disable: 4146) // unary minus operator applied to unsigned type 14 | #endif 15 | #endif 16 | 17 | #include 18 | #include 19 | 20 | typedef SOCKET ENetSocket; 21 | 22 | #define ENET_SOCKET_NULL INVALID_SOCKET 23 | 24 | #define ENET_HOST_TO_NET_16(value) (htons (value)) 25 | #define ENET_HOST_TO_NET_32(value) (htonl (value)) 26 | 27 | #define ENET_NET_TO_HOST_16(value) (ntohs (value)) 28 | #define ENET_NET_TO_HOST_32(value) (ntohl (value)) 29 | 30 | typedef struct 31 | { 32 | size_t dataLength; 33 | void * data; 34 | } ENetBuffer; 35 | 36 | #define ENET_CALLBACK __cdecl 37 | 38 | #ifdef ENET_DLL 39 | #ifdef ENET_BUILDING_LIB 40 | #define ENET_API __declspec( dllexport ) 41 | #else 42 | #define ENET_API __declspec( dllimport ) 43 | #endif /* ENET_BUILDING_LIB */ 44 | #else /* !ENET_DLL */ 45 | #define ENET_API extern 46 | #endif /* ENET_DLL */ 47 | 48 | typedef fd_set ENetSocketSet; 49 | 50 | #define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO (& (sockset)) 51 | #define ENET_SOCKETSET_ADD(sockset, socket) FD_SET (socket, & (sockset)) 52 | #define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLR (socket, & (sockset)) 53 | #define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET (socket, & (sockset)) 54 | 55 | #endif /* __ENET_WIN32_H__ */ 56 | 57 | 58 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C 3 | * 4 | * Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | /** 19 | * @defgroup msgpack MessagePack C 20 | * @{ 21 | * @} 22 | */ 23 | 24 | #include "msgpack/util.h" 25 | #include "msgpack/object.h" 26 | #include "msgpack/zone.h" 27 | #include "msgpack/pack.h" 28 | #include "msgpack/unpack.h" 29 | #include "msgpack/sbuffer.h" 30 | #include "msgpack/vrefbuffer.h" 31 | #include "msgpack/version.h" 32 | 33 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ 3 | // 4 | // Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #include "msgpack/object.hpp" 19 | #include "msgpack/zone.hpp" 20 | #include "msgpack/pack.hpp" 21 | #include "msgpack/unpack.hpp" 22 | #include "msgpack/sbuffer.hpp" 23 | #include "msgpack/vrefbuffer.hpp" 24 | #include "msgpack/version.hpp" 25 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/bool.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_BOOL_HPP 19 | #define MSGPACK_TYPE_BOOL_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | #include 24 | 25 | namespace msgpack { 26 | 27 | MSGPACK_API_VERSION_NAMESPACE(v1) { 28 | 29 | inline object const& operator>> (object const& o, bool& v) 30 | { 31 | if(o.type != type::BOOLEAN) { throw type_error(); } 32 | v = o.via.boolean; 33 | return o; 34 | } 35 | 36 | template 37 | inline packer& operator<< (packer& o, const bool& v) 38 | { 39 | if(v) { o.pack_true(); } 40 | else { o.pack_false(); } 41 | return o; 42 | } 43 | 44 | inline void operator<< (object& o, bool v) 45 | { 46 | o.type = type::BOOLEAN; 47 | o.via.boolean = v; 48 | } 49 | 50 | inline void operator<< (object::with_zone& o, bool v) 51 | { static_cast(o) << v; } 52 | 53 | 54 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 55 | 56 | } // namespace msgpack 57 | 58 | #endif // MSGPACK_TYPE_BOOL_HPP 59 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/bool_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_BOOL_FWD_HPP 19 | #define MSGPACK_TYPE_BOOL_FWD_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | 24 | namespace msgpack { 25 | 26 | MSGPACK_API_VERSION_NAMESPACE(v1) { 27 | 28 | object const& operator>> (object const& o, bool& v); 29 | template 30 | packer& operator<< (packer& o, const bool& v); 31 | void operator<< (object& o, bool v); 32 | void operator<< (object::with_zone& o, bool v); 33 | 34 | 35 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 36 | 37 | } // namespace msgpack 38 | 39 | #endif // MSGPACK_TYPE_BOOL_FWD_HPP 40 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/char_ptr_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2014 KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_CHAR_PTR_FWD_HPP 19 | #define MSGPACK_TYPE_CHAR_PTR_FWD_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | #include 24 | 25 | namespace msgpack { 26 | 27 | MSGPACK_API_VERSION_NAMESPACE(v1) { 28 | 29 | template 30 | packer& operator<< (packer& o, const char* v); 31 | void operator<< (object::with_zone& o, const char* v); 32 | void operator<< (object& o, const char* v); 33 | 34 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 35 | 36 | } // namespace msgpack 37 | 38 | #endif // MSGPACK_TYPE_CHAR_PTR_FWD_HPP 39 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/cpp11/array_char_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2014 KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_ARRAY_CHAR_FWD_HPP 19 | #define MSGPACK_TYPE_ARRAY_CHAR_FWD_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | #include 24 | 25 | namespace msgpack { 26 | 27 | MSGPACK_API_VERSION_NAMESPACE(v1) { 28 | 29 | template 30 | object const& operator>> (object const& o, std::array& v); 31 | 32 | template 33 | packer& operator<< (packer& o, const std::array& v); 34 | 35 | template 36 | void operator<< (object& o, const std::array& v); 37 | 38 | template 39 | void operator<< (object::with_zone& o, const std::array& v); 40 | 41 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 42 | 43 | } // namespace msgpack 44 | 45 | #endif // MSGPACK_TYPE_ARRAY_CHAR_FWD_HPP 46 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/cpp11/array_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2014 KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | #ifndef MSGPACK_CPP11_ARRAY_FWD_HPP 20 | #define MSGPACK_CPP11_ARRAY_FWD_HPP 21 | 22 | #include "msgpack/versioning.hpp" 23 | #include "msgpack/object_fwd.hpp" 24 | 25 | #include 26 | 27 | namespace msgpack { 28 | 29 | MSGPACK_API_VERSION_NAMESPACE(v1) { 30 | 31 | template 32 | object const& operator>> (object const& o, std::array& v); 33 | 34 | template 35 | packer& operator<< (packer& o, const std::array& v); 36 | 37 | template 38 | void operator<< (object::with_zone& o, const std::array& v); 39 | 40 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 41 | 42 | } // namespace msgpack 43 | 44 | #endif // MSGPACK_CPP11_ARRAY_FWD_HPP 45 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/cpp11/forward_list_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2014 KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | #ifndef MSGPACK_CPP11_FORWARD_LIST_FWD_HPP 20 | #define MSGPACK_CPP11_FORWARD_LIST_FWD_HPP 21 | 22 | #include "msgpack/versioning.hpp" 23 | #include "msgpack/object_fwd.hpp" 24 | 25 | #include 26 | 27 | namespace msgpack { 28 | 29 | MSGPACK_API_VERSION_NAMESPACE(v1) { 30 | 31 | template 32 | object const& operator>> (object const& o, std::forward_list& v); 33 | 34 | template 35 | packer& operator<< (packer& o, const std::forward_list& v); 36 | 37 | template 38 | void operator<< (object::with_zone& o, const std::forward_list& v); 39 | 40 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 41 | 42 | } // namespace msgpack 43 | 44 | #endif // MSGPACK_CPP11_FORWARD_LIST_FWD_HPP 45 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/define.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_DEFINE_HPP 19 | #define MSGPACK_DEFINE_HPP 20 | 21 | #include "msgpack/cpp_config.hpp" 22 | 23 | #if defined(MSGPACK_USE_CPP03) 24 | #include "detail/cpp03_define.hpp" 25 | #else // MSGPACK_USE_CPP03 26 | #include "detail/cpp11_define.hpp" 27 | #endif // MSGPACK_USE_CPP03 28 | 29 | #endif // MSGPACK_DEFINE_HPP 30 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/deque_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_DEQUE_FWD_HPP 19 | #define MSGPACK_TYPE_DEQUE_FWD_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | #include 24 | 25 | namespace msgpack { 26 | 27 | MSGPACK_API_VERSION_NAMESPACE(v1) { 28 | 29 | template 30 | object const& operator>> (object const& o, std::deque& v); 31 | template 32 | packer& operator<< (packer& o, const std::deque& v); 33 | template 34 | void operator<< (object::with_zone& o, const std::deque& v); 35 | 36 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 37 | 38 | } // namespace msgpack 39 | 40 | #endif // MSGPACK_TYPE_DEQUE_FWD_HPP 41 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/float_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_FLOAT_FWD_HPP 19 | #define MSGPACK_TYPE_FLOAT_FWD_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | #include 24 | 25 | namespace msgpack { 26 | 27 | MSGPACK_API_VERSION_NAMESPACE(v1) { 28 | 29 | object const& operator>> (object const& o, float& v); 30 | template 31 | packer& operator<< (packer& o, const float& v); 32 | object const& operator>> (object const& o, double& v); 33 | template 34 | packer& operator<< (packer& o, const double& v); 35 | void operator<< (object& o, float v); 36 | void operator<< (object& o, double v); 37 | void operator<< (object::with_zone& o, float v); 38 | void operator<< (object::with_zone& o, double v); 39 | 40 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 41 | 42 | } // namespace msgpack 43 | 44 | #endif // MSGPACK_TYPE_FLOAT_FWD_HPP 45 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/list_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_LIST_FWD_HPP 19 | #define MSGPACK_TYPE_LIST_FWD_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | #include 24 | 25 | namespace msgpack { 26 | 27 | MSGPACK_API_VERSION_NAMESPACE(v1) { 28 | 29 | template 30 | object const& operator>> (object const& o, std::list& v); 31 | template 32 | packer& operator<< (packer& o, const std::list& v); 33 | template 34 | void operator<< (object::with_zone& o, const std::list& v); 35 | 36 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 37 | 38 | } // namespace msgpack 39 | 40 | #endif // MSGPACK_TYPE_LIST_FWD_HPP 41 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/msgpack_tuple.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_MSGPACK_TUPLE_HPP 19 | #define MSGPACK_MSGPACK_TUPLE_HPP 20 | 21 | #include "msgpack/cpp_config.hpp" 22 | 23 | #if defined(MSGPACK_USE_CPP03) 24 | #include "detail/cpp03_msgpack_tuple.hpp" 25 | #else // MSGPACK_USE_CPP03 26 | #include "detail/cpp11_msgpack_tuple.hpp" 27 | #endif // MSGPACK_USE_CPP03 28 | 29 | #endif // MSGPACK_MSGPACK_TUPLE_HPP 30 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/msgpack_tuple_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_MSGPACK_TUPLE_FWD_HPP 19 | #define MSGPACK_MSGPACK_TUPLE_FWD_HPP 20 | 21 | #include "msgpack/cpp_config.hpp" 22 | 23 | #if defined(MSGPACK_USE_CPP03) 24 | #include "detail/cpp03_msgpack_tuple_fwd.hpp" 25 | #else // MSGPACK_USE_CPP03 26 | #include "detail/cpp11_msgpack_tuple_fwd.hpp" 27 | #endif // MSGPACK_USE_CPP03 28 | 29 | #endif // MSGPACK_MSGPACK_TUPLE_FWD_HPP 30 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/nil_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_NIL_FWD_HPP 19 | #define MSGPACK_TYPE_NIL_FWD_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | 24 | namespace msgpack { 25 | 26 | MSGPACK_API_VERSION_NAMESPACE(v1) { 27 | 28 | namespace type { 29 | 30 | struct nil; 31 | 32 | } // namespace type 33 | 34 | 35 | object const& operator>> (object const& o, type::nil&); 36 | 37 | template 38 | packer& operator<< (packer& o, const type::nil&); 39 | 40 | void operator<< (object& o, type::nil); 41 | 42 | void operator<< (object::with_zone& o, type::nil v); 43 | 44 | template <> 45 | inline void object::as() const; 46 | 47 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 48 | 49 | } // namespace msgpack 50 | 51 | #endif // MSGPACK_TYPE_NIL_FWD_HPP 52 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/pair_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_PAIR_FWD_HPP 19 | #define MSGPACK_TYPE_PAIR_FWD_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | #include 24 | 25 | namespace msgpack { 26 | 27 | MSGPACK_API_VERSION_NAMESPACE(v1) { 28 | 29 | template 30 | object const& operator>> (object const& o, std::pair& v); 31 | 32 | template 33 | packer& operator<< (packer& o, const std::pair& v); 34 | 35 | template 36 | void operator<< (object::with_zone& o, const std::pair& v); 37 | 38 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 39 | 40 | } // namespace msgpack 41 | 42 | #endif // MSGPACK_TYPE_PAIR_FWD_HPP 43 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/raw_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_RAW_FWD_HPP 19 | #define MSGPACK_TYPE_RAW_FWD_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | #include 24 | #include 25 | 26 | namespace msgpack { 27 | 28 | MSGPACK_API_VERSION_NAMESPACE(v1) { 29 | 30 | namespace type { 31 | 32 | struct raw_ref; 33 | 34 | } // namespace type 35 | 36 | 37 | object const& operator>> (object const& o, type::raw_ref& v); 38 | 39 | template 40 | packer& operator<< (packer& o, const type::raw_ref& v); 41 | 42 | void operator<< (object& o, const type::raw_ref& v); 43 | 44 | void operator<< (object::with_zone& o, const type::raw_ref& v); 45 | 46 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 47 | 48 | } // namespace msgpack 49 | 50 | #endif // MSGPACK_TYPE_RAW_FWD_HPP 51 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/set_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_SET_FWD_HPP 19 | #define MSGPACK_TYPE_SET_FWD_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | 24 | #include 25 | 26 | namespace msgpack { 27 | 28 | MSGPACK_API_VERSION_NAMESPACE(v1) { 29 | 30 | template 31 | object const& operator>> (object const& o, std::set& v); 32 | 33 | template 34 | packer& operator<< (packer& o, const std::set& v); 35 | 36 | template 37 | void operator<< (object::with_zone& o, const std::set& v); 38 | 39 | template 40 | object const& operator>> (object const& o, std::multiset& v); 41 | 42 | template 43 | packer& operator<< (packer& o, const std::multiset& v); 44 | 45 | template 46 | void operator<< (object::with_zone& o, const std::multiset& v); 47 | 48 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 49 | 50 | } // namespace msgpack 51 | 52 | #endif // MSGPACK_TYPE_SET_FWD_HPP 53 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/string_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_STRING_FWD_HPP 19 | #define MSGPACK_TYPE_STRING_FWD_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | #include 24 | 25 | namespace msgpack { 26 | 27 | MSGPACK_API_VERSION_NAMESPACE(v1) { 28 | 29 | object const& operator>> (object const& o, std::string& v); 30 | 31 | template 32 | packer& operator<< (packer& o, const std::string& v); 33 | 34 | void operator<< (object::with_zone& o, const std::string& v); 35 | 36 | void operator<< (object& o, const std::string& v); 37 | 38 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 39 | 40 | } // namespace msgpack 41 | 42 | #endif // MSGPACK_TYPE_STRING_FWD_HPP 43 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/vector_char_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2014 KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_VECTOR_CHAR_FWD_HPP 19 | #define MSGPACK_TYPE_VECTOR_CHAR_FWD_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | #include 24 | 25 | namespace msgpack { 26 | 27 | MSGPACK_API_VERSION_NAMESPACE(v1) { 28 | 29 | object const& operator>> (object const& o, std::vector& v); 30 | 31 | template 32 | packer& operator<< (packer& o, const std::vector& v); 33 | 34 | void operator<< (object& o, const std::vector& v); 35 | 36 | void operator<< (object::with_zone& o, const std::vector& v); 37 | 38 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 39 | 40 | } // namespace msgpack 41 | 42 | #endif // MSGPACK_TYPE_VECTOR_CHAR_FWD_HPP 43 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/adaptor/vector_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_VECTOR_FWD_HPP 19 | #define MSGPACK_TYPE_VECTOR_FWD_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | #include 24 | 25 | namespace msgpack { 26 | 27 | MSGPACK_API_VERSION_NAMESPACE(v1) { 28 | 29 | template 30 | object const& operator>> (object const& o, std::vector& v); 31 | 32 | template 33 | packer& operator<< (packer& o, const std::vector& v); 34 | 35 | template 36 | void operator<< (object::with_zone& o, const std::vector& v); 37 | 38 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 39 | 40 | } // namespace msgpack 41 | 42 | #endif // MSGPACK_TYPE_VECTOR_FWD_HPP 43 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/fbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C FILE* buffer adaptor 3 | * 4 | * Copyright (C) 2013 Vladimir Volodko 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_FBUFFER_H__ 19 | #define MSGPACK_FBUFFER_H__ 20 | 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | 28 | /** 29 | * @defgroup msgpack_fbuffer FILE* buffer 30 | * @ingroup msgpack_buffer 31 | * @{ 32 | */ 33 | 34 | static inline int msgpack_fbuffer_write(void* data, const char* buf, unsigned int len) 35 | { 36 | return (1 == fwrite(buf, len, 1, (FILE *)data)) ? 0 : -1; 37 | } 38 | 39 | /** @} */ 40 | 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif /* msgpack/fbuffer.h */ 47 | 48 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/gcc_atomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | #ifndef MSGPACK_GCC_ATOMIC_H 16 | #define MSGPACK_GCC_ATOMIC_H 17 | 18 | #if defined(__cplusplus) 19 | extern "C" { 20 | #endif 21 | 22 | typedef int _msgpack_atomic_counter_t; 23 | 24 | int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr); 25 | int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr); 26 | 27 | 28 | #if defined(__cplusplus) 29 | } 30 | #endif 31 | 32 | 33 | #endif // MSGPACK_GCC_ATOMIC_H 34 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/pack_define.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack unpacking routine template 3 | * 4 | * Copyright (C) 2008-2010 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_PACK_DEFINE_H 19 | #define MSGPACK_PACK_DEFINE_H 20 | 21 | #include "msgpack/sysdep.h" 22 | #include 23 | #include 24 | 25 | #endif /* msgpack/pack_define.h */ 26 | 27 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/type.hpp: -------------------------------------------------------------------------------- 1 | #include "cpp_config.hpp" 2 | #include "adaptor/bool.hpp" 3 | #include "adaptor/char_ptr.hpp" 4 | #include "adaptor/deque.hpp" 5 | #include "adaptor/fixint.hpp" 6 | #include "adaptor/float.hpp" 7 | #include "adaptor/int.hpp" 8 | #include "adaptor/list.hpp" 9 | #include "adaptor/map.hpp" 10 | #include "adaptor/nil.hpp" 11 | #include "adaptor/pair.hpp" 12 | #include "adaptor/raw.hpp" 13 | #include "adaptor/set.hpp" 14 | #include "adaptor/string.hpp" 15 | #include "adaptor/vector.hpp" 16 | #include "adaptor/vector_char.hpp" 17 | #include "adaptor/msgpack_tuple.hpp" 18 | #include "adaptor/define.hpp" 19 | 20 | #if defined(MSGPACK_USE_CPP03) 21 | 22 | #include "adaptor/tr1/unordered_map.hpp" 23 | #include "adaptor/tr1/unordered_set.hpp" 24 | 25 | #else // defined(MSGPACK_USE_CPP03) 26 | 27 | #include "adaptor/cpp11/array.hpp" 28 | #include "adaptor/cpp11/array_char.hpp" 29 | #include "adaptor/cpp11/forward_list.hpp" 30 | #include "adaptor/cpp11/tuple.hpp" 31 | #include "adaptor/cpp11/unordered_map.hpp" 32 | #include "adaptor/cpp11/unordered_set.hpp" 33 | 34 | #endif // defined(MSGPACK_USE_CPP03) 35 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C utilities 3 | * 4 | * Copyright (C) 2014 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_UTIL_H 19 | #define MSGPACK_UTIL_H 20 | 21 | #define MSGPACK_UNUSED(a) (void)(a) 22 | 23 | #endif /* MSGPACK_UTIL_H */ 24 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C version information 3 | * 4 | * Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_VERSION_H 19 | #define MSGPACK_VERSION_H 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | MSGPACK_DLLEXPORT 26 | const char* msgpack_version(void); 27 | MSGPACK_DLLEXPORT 28 | int msgpack_version_major(void); 29 | MSGPACK_DLLEXPORT 30 | int msgpack_version_minor(void); 31 | 32 | #include "version_master.h" 33 | 34 | #define MSGPACK_STR(v) #v 35 | #define MSGPACK_VERSION_I(maj, min, rev) MSGPACK_STR(maj) "." MSGPACK_STR(min) "." MSGPACK_STR(rev) 36 | 37 | #define MSGPACK_VERSION MSGPACK_VERSION_I(MSGPACK_VERSION_MAJOR, MSGPACK_VERSION_MINOR, MSGPACK_VERSION_REVISION) 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif /* msgpack/version.h */ 44 | 45 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/version.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C++ version information 3 | * 4 | * Copyright (C) 2008-2013 FURUHASHI Sadayuki and Takatoshi Kondo 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_VERSION_HPP 19 | #define MSGPACK_VERSION_HPP 20 | 21 | #include "version_master.h" 22 | 23 | #define MSGPACK_STR(v) #v 24 | #define MSGPACK_VERSION_I(maj, min, rev) MSGPACK_STR(maj) "." MSGPACK_STR(min) "." MSGPACK_STR(rev) 25 | 26 | #define MSGPACK_VERSION MSGPACK_VERSION_I(MSGPACK_VERSION_MAJOR, MSGPACK_VERSION_MINOR, MSGPACK_VERSION_REVISION) 27 | 28 | inline const char* msgpack_version(void) { 29 | return MSGPACK_VERSION; 30 | } 31 | 32 | inline int msgpack_version_major(void) { 33 | return MSGPACK_VERSION_MAJOR; 34 | } 35 | 36 | inline int msgpack_version_minor(void) { 37 | return MSGPACK_VERSION_MINOR; 38 | } 39 | 40 | inline int msgpack_version_revision(void) { 41 | return MSGPACK_VERSION_REVISION; 42 | } 43 | 44 | #endif /* msgpack/version.hpp */ 45 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/version_master.h: -------------------------------------------------------------------------------- 1 | #define MSGPACK_VERSION_MAJOR 0 2 | #define MSGPACK_VERSION_MINOR 6 3 | #define MSGPACK_VERSION_REVISION 0 4 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack/zone.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ memory pool 3 | // 4 | // Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_ZONE_HPP 19 | #define MSGPACK_ZONE_HPP 20 | 21 | #include "msgpack/cpp_config.hpp" 22 | 23 | #if defined(MSGPACK_USE_CPP03) 24 | #include "detail/cpp03_zone.hpp" 25 | #else // MSGPACK_USE_CPP03 26 | #include "detail/cpp11_zone.hpp" 27 | #endif // MSGPACK_USE_CPP03 28 | 29 | #endif // MSGPACK_ZONE_HPP 30 | -------------------------------------------------------------------------------- /zertco5/third_parties/msgpack_fwd.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C++ version switcher 3 | * 4 | * Copyright (C) 2014 KONDO Takatoshi 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_FWD_HPP 19 | #define MSGPACK_FWD_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/zone.hpp" 23 | #include "msgpack/object_fwd.hpp" 24 | #include "msgpack/adaptor/define.hpp" 25 | #include "msgpack/pack.hpp" 26 | 27 | #endif // MSGPACK_FWD_HPP 28 | -------------------------------------------------------------------------------- /zertco5/third_parties/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ 16 | #define RAPIDJSON_INTERNAL_STRFUNC_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | //! Custom strlen() which works on different character types. 24 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 25 | \param s Null-terminated input string. 26 | \return Number of characters in the string. 27 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 28 | */ 29 | template 30 | inline SizeType StrLen(const Ch* s) { 31 | const Ch* p = s; 32 | while (*p) ++p; 33 | return SizeType(p - s); 34 | } 35 | 36 | } // namespace internal 37 | RAPIDJSON_NAMESPACE_END 38 | 39 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 40 | -------------------------------------------------------------------------------- /zertco5/thread/SConscript: -------------------------------------------------------------------------------- 1 | import GenCPP 2 | 3 | GenCPP.generate_callwrapper_ipp('details/ThreadHandlerSetParams.ipp', """ 4 | template <{template}> 5 | void setParams({params}) const { 6 | params_ = params_ptr(new params_type({call})); 7 | } 8 | """, 5, False, True) 9 | 10 | -------------------------------------------------------------------------------- /zertco5/thread/ThreadSingleton.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ThreadSingleton.h 3 | * 4 | * Created on: 2015��1��5�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_THREADSINGLETON_H_ 9 | #define ZERTCORE_THREADSINGLETON_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include "Thread.h" 17 | #include "ThreadLocal.h" 18 | #include "ThreadHandlerSet.h" 19 | 20 | namespace zertcore { namespace concurrent { 21 | using namespace zertcore::object; 22 | }} 23 | 24 | namespace zertcore { namespace concurrent { 25 | 26 | template 27 | class ThreadSingleton : 28 | public ThreadHandlerSet, 29 | noncopyable 30 | { 31 | public: 32 | typedef vector thread_map_type; 33 | 34 | public: 35 | virtual ~ThreadSingleton() {} 36 | 37 | public: 38 | virtual void init() {} 39 | virtual tid_type getThreadIndex() const final {return Thread::getCurrentTid();} 40 | 41 | public: 42 | /** 43 | * the Instance() return the unique instance of this Thread! 44 | * with the tid would get the instance of other instance 45 | */ 46 | static Final& Instance(); 47 | static Final& Instance(tid_type tid); 48 | 49 | public: 50 | virtual bool deinit(); 51 | 52 | private: 53 | static void __initInstance(); 54 | 55 | private: 56 | static ThreadLocal p_instance_; 57 | 58 | private: 59 | static pthread_once_t ponce_; 60 | static thread_map_type thread_map_; 61 | }; 62 | 63 | }} 64 | 65 | 66 | #endif /* THREADSINGLETON_H_ */ 67 | -------------------------------------------------------------------------------- /zertco5/thread/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | * Created on: 2015年6月4日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_THREAD_CONFIG_H_ 9 | #define ZERTCORE_THREAD_CONFIG_H_ 10 | 11 | #include 12 | 13 | namespace zertcore { namespace concurrent { 14 | 15 | typedef function init_handler_type; 16 | typedef function after_all_init_handler_type; 17 | 18 | }} 19 | 20 | #endif /* THREAD_CONFIG_H_ */ 21 | -------------------------------------------------------------------------------- /zertco5/thread/details/ThreadHandlerSetDetails.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ThreadHandlerSetDetails.hpp 3 | * 4 | * Created on: 2015年6月4日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_THREAD_DETAILS_THREADHANDLERSETDETAILS_HPP_ 9 | #define ZERTCORE_THREAD_DETAILS_THREADHANDLERSETDETAILS_HPP_ 10 | 11 | #include "../ThreadHandlerSet.h" 12 | #include "../ThreadPool.h" 13 | #include "../ThreadHandler.h" 14 | #include "../Thread.h" 15 | 16 | namespace zertcore { namespace concurrent { 17 | 18 | template 19 | void ThreadHandlerSet:: 20 | initHandler(const init_handler_type& handler) { 21 | ThreadPool::Instance().registerInitHandler(getThreadIndex(), handler); 22 | } 23 | 24 | template 25 | tid_type ThreadHandlerSet:: 26 | getThreadIndex() { 27 | return Thread::lazyTid(Final::THREAD_INDEX); 28 | } 29 | 30 | template 31 | template 32 | bool ThreadHandlerSet:: 33 | go(Callable caller) { 34 | return ::zertcore::goThread(getThreadIndex(), caller); 35 | } 36 | 37 | }} 38 | 39 | #endif /* THREAD_DETAILS_THREADHANDLERSETDETAILS_HPP_ */ 40 | -------------------------------------------------------------------------------- /zertco5/thread/details/ThreadSingletonDetails.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ThreadSingletonDetails.hpp 3 | * 4 | * Created on: 2015年6月4日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_THREAD_DETAILS_THREADSINGLETONDETAILS_HPP_ 9 | #define ZERTCORE_THREAD_DETAILS_THREADSINGLETONDETAILS_HPP_ 10 | 11 | #include "../ThreadSingleton.h" 12 | 13 | namespace zertcore { namespace concurrent { 14 | 15 | 16 | 17 | }} 18 | 19 | 20 | #endif /* THREAD_DETAILS_THREADSINGLETONDETAILS_HPP_ */ 21 | -------------------------------------------------------------------------------- /zertco5/todo.txt: -------------------------------------------------------------------------------- 1 | 2015/8/5: 2 | 1. Optimize the thread module, make it more clean. [this week] 3 | 2(?). support rapidjson (or just need it support in client) 4 | key: performace ( rapidjson vs mongobson ) 5 | 3. start to make some sample(like px?) to make benchmark for the framework [for the right time] 6 | 7 | ISSUE: (2015/8/17) 8 | session design of command got bugs: 9 | 1) one command just would work for one session. 10 | 2) pop message just worked when new message come, change that to every new message parsed and pushed, but just do 1 in every frame. 11 | when the message slot full, reject new messages. 12 | 13 | -------------------------------------------------------------------------------- /zertco5/utils/SConscript: -------------------------------------------------------------------------------- 1 | import GenCPP 2 | 3 | -------------------------------------------------------------------------------- /zertco5/utils/buffer/details/SharedBufferSerialization.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SharedBufferSerialization.hpp 3 | * 4 | * Created on: 2015年5月25日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_UTILS_BUFFER_DETAILS_SHAREDBUFFERSERIALIZATION_HPP_ 9 | #define ZERTCORE_UTILS_BUFFER_DETAILS_SHAREDBUFFERSERIALIZATION_HPP_ 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { namespace serialization { 15 | using namespace zertcore::utils; 16 | 17 | 18 | /** 19 | * NOTICE: these two serialization function JUST support BSON since just bson support bin data! 20 | * 21 | */ 22 | template 23 | inline Serializer& operator << (Serializer& s, const SharedBuffer& v) { 24 | s.setValue(v); 25 | return s; 26 | } 27 | 28 | template 29 | inline bool operator >> (const Unserializer& s, SharedBuffer& v) { 30 | return s.getValue(v); 31 | } 32 | 33 | }} 34 | 35 | 36 | #endif /* UTILS_BUFFER_DETAILS_SHAREDBUFFERSERIALIZATION_HPP_ */ 37 | -------------------------------------------------------------------------------- /zertco5/utils/collision/DoubleTiles.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DoubleTiles.h 3 | * 4 | * Created on: 2015年6月24日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_UTILS_COLLISION_DOUBLETILES_H_ 9 | #define ZERTCORE_UTILS_COLLISION_DOUBLETILES_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { namespace utils { 15 | 16 | template 17 | struct Rectage 18 | { 19 | typedef T value_type; 20 | 21 | value_type x{0}, 22 | y{0}, 23 | width{0}, 24 | height{0}; 25 | }; 26 | 27 | }} 28 | 29 | namespace zertcore { namespace utils { 30 | 31 | typedef double size_type; 32 | 33 | namespace details { 34 | 35 | typedef Rectage rect_type; 36 | typedef vector data_list_type; 37 | 38 | class Sensor; 39 | typedef unordered_set sensor_set_type; 40 | /** 41 | * Tile 42 | */ 43 | struct Tile 44 | { 45 | sensor_set_type sensor_set; 46 | data_list_type data_list; 47 | }; 48 | typedef vector tile_map_type; 49 | 50 | /** 51 | * Sensor 52 | */ 53 | class Sensor 54 | { 55 | vector tiles; 56 | }; 57 | 58 | /** 59 | * Tiles 60 | */ 61 | template 62 | class Tiles 63 | { 64 | public: 65 | 66 | 67 | public: 68 | explicit Tiles(const rect_type& rect); 69 | 70 | public: 71 | bool setupSensor(Sensor& sensor); 72 | 73 | private: 74 | tile_map_type tile_map_; 75 | }; 76 | 77 | } 78 | 79 | /** 80 | * DoubleTiles<> 81 | */ 82 | template 83 | class DoubleTiles 84 | { 85 | public: 86 | }; 87 | 88 | }} 89 | 90 | 91 | #endif /* UTILS_COLLISION_DOUBLETILES_H_ */ 92 | -------------------------------------------------------------------------------- /zertco5/utils/collision/QuadTree.h: -------------------------------------------------------------------------------- 1 | /* 2 | * QuadTree.h 3 | * 4 | * Created on: 2015年6月24日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_UTILS_COLLISION_QUADTREE_H_ 9 | #define ZERTCORE_UTILS_COLLISION_QUADTREE_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace zertcore { namespace utils { 17 | using namespace zertcore::object; 18 | 19 | namespace details { 20 | 21 | enum dir_type { 22 | DIR_NONE = 0, 23 | DIR_TL = 1, 24 | DIR_TR = 2, 25 | DIR_BL = 3, 26 | DIR_BR = 4, 27 | }; 28 | 29 | } 30 | 31 | }} 32 | 33 | namespace zertcore { namespace utils { 34 | 35 | template 36 | class QuadTreeNode 37 | { 38 | public: 39 | typedef PoolObject data_type; 40 | typedef typename data_type::ptr data_ptr; 41 | 42 | public: 43 | bool isDataNode() const; 44 | 45 | private: 46 | data_ptr data_; 47 | u32 data_amount_{0}; 48 | 49 | details::dir_type dir_{details::DIR_NONE}; 50 | }; 51 | 52 | 53 | template 54 | class QuadTree 55 | { 56 | public: 57 | 58 | private: 59 | }; 60 | 61 | }} 62 | 63 | 64 | #endif /* UTILS_COLLISION_QUADTREE_H_ */ 65 | -------------------------------------------------------------------------------- /zertco5/utils/condition/KeysHolder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * KeysHolder.h 3 | * 4 | * Created on: 2015年10月9日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_UTILS_CONDITION_KEYSHOLDER_H_ 9 | #define ZERTCORE_UTILS_CONDITION_KEYSHOLDER_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { namespace utils { namespace details { 15 | 16 | /** 17 | * KeysHolder 18 | */ 19 | template 20 | class KeysHolder 21 | { 22 | public: 23 | KeysHolder() {} 24 | KeysHolder(const KeyType& v) { 25 | key_list_.push_back(v); 26 | } 27 | 28 | public: 29 | KeysHolder& operator() (const KeyType& v) { 30 | key_list_.push_back(v); 31 | return *this; 32 | } 33 | 34 | public: 35 | vector& keyList() { return key_list_; } 36 | const vector& keyList() const { return key_list_; } 37 | 38 | private: 39 | vector key_list_; 40 | }; 41 | 42 | }}} 43 | 44 | #include 45 | #include 46 | 47 | namespace zertcore { namespace serialization { 48 | using namespace zertcore::utils::details; 49 | 50 | template 51 | inline Serializer& operator << (Serializer& s, const KeysHolder& v) { 52 | s << v.keyList(); 53 | return s; 54 | } 55 | 56 | template 57 | inline bool operator >> (const Unserializer& s, KeysHolder& v) { 58 | return s >> v.keyList(); 59 | } 60 | 61 | }} 62 | 63 | #endif /* UTILS_CONDITION_KEYSHOLDER_H_ */ 64 | -------------------------------------------------------------------------------- /zertco5/utils/crypto/Crypto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Crypto.h 3 | * 4 | * Created on: 2015年4月28日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_UTILS_CRYPTO_CRYPTO_H_ 9 | #define ZERTCORE_UTILS_CRYPTO_CRYPTO_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #ifndef ZC_ENCRYPT_RANDKEY_LENGTH 17 | # define ZC_ENCRYPT_RANDKEY_LENGTH 256 18 | #endif 19 | 20 | namespace zertcore{ namespace utils{ 21 | 22 | /** 23 | * provides the normal math algorithm 24 | */ 25 | class Crypto 26 | { 27 | public: 28 | static string sha256(const string& str); 29 | static string md5(const string& str); 30 | 31 | public: 32 | typedef array 33 | randkey_type; 34 | 35 | public: 36 | static bool prepareRandkey(randkey_type& randkey, const string& password); 37 | /** 38 | * if need compress the data, do it before encrypt 39 | */ 40 | static bool doXor(SharedBuffer& input, const randkey_type& randkey); 41 | 42 | public: 43 | static string genRandomKey(); 44 | }; 45 | 46 | }} 47 | 48 | 49 | #endif /* UTILS_CRYPTO_CRYPTO_H_ */ 50 | -------------------------------------------------------------------------------- /zertco5/utils/details/errors.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * errors.hpp 3 | * 4 | * Created on: 2015��1��14�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_ERRORS_HPP_ 9 | #define ZERTCORE_ERRORS_HPP_ 10 | 11 | #define ZC_ERROR_DEF(name, code) namespace zertcore { namespace error {const static Error name(code, #name);}} 12 | 13 | /** 14 | * 15 | * Default Error Defines 16 | * 17 | */ 18 | 19 | ZC_ERROR_DEF(NONE, 0); 20 | 21 | ZC_ERROR_DEF(UNKNOWN, 1); 22 | 23 | ZC_ERROR_DEF(TIME_OUT, 403); 24 | 25 | ZC_ERROR_DEF(NOT_FOUND, 404); 26 | 27 | ZC_ERROR_DEF(SYS_FAULT, 500); 28 | 29 | ZC_ERROR_DEF(INIT_FAILED, 510); 30 | 31 | ZC_ERROR_DEF(SERIALIZE_FAILED, 530); 32 | 33 | #endif /* ERRORS_HPP_ */ 34 | -------------------------------------------------------------------------------- /zertco5/utils/file/FileManager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FileManager.cpp 3 | * 4 | * Created on: 2015年4月27日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "FileManager.h" 13 | 14 | namespace zertcore { namespace utils { 15 | 16 | bool FileManager:: 17 | getContent(const string& filename, SharedBuffer& buffer) { 18 | std::ifstream file(filename.c_str(), std::ifstream::binary | std::ifstream::in); 19 | 20 | if (!file.is_open()) { 21 | ZCLOG(ERROR) << "Try to read " << filename << " failed" << End; 22 | return false; 23 | } 24 | 25 | file.seekg(0, file.end); 26 | int length = file.tellg(); 27 | file.seekg(0, file.beg); 28 | 29 | buffer.resize(length); 30 | buffer.setSize(0); 31 | 32 | file.read((char *)buffer.data(), buffer.capacity()); 33 | file.close(); 34 | 35 | return true; 36 | } 37 | 38 | bool FileManager:: 39 | saveContent(const string& filename, const SharedBuffer& buffer) { 40 | vector path; 41 | path.assign(filename.begin(), filename.end()); 42 | 43 | dirname(&path[0]); 44 | mkdir(&path[0], S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); 45 | 46 | std::ofstream file(filename.c_str(), std::ofstream::binary | std::ofstream::out); 47 | 48 | if (!file.is_open()) { 49 | ZCLOG(ERROR) << "Try to write " << filename << " failed" << End; 50 | return false; 51 | } 52 | 53 | file.write((const char *)buffer.data(), buffer.size()); 54 | file.close(); 55 | 56 | return true; 57 | } 58 | 59 | }} 60 | 61 | 62 | -------------------------------------------------------------------------------- /zertco5/utils/file/FileManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FileManager.h 3 | * 4 | * Created on: 2015年4月27日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_UTILS_FILE_FILEMANAGER_H_ 9 | #define ZERTCORE_UTILS_FILE_FILEMANAGER_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace zertcore { namespace utils { 17 | 18 | /** 19 | * FileManager 20 | */ 21 | class FileManager 22 | { 23 | public: 24 | static bool getContent(const string& filename, SharedBuffer& buffer); 25 | static bool saveContent(const string& filename, const SharedBuffer& buffer); 26 | }; 27 | 28 | }} 29 | 30 | 31 | #endif /* UTILS_FILE_FILEMANAGER_H_ */ 32 | -------------------------------------------------------------------------------- /zertco5/utils/http/HttpClient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * HttpClient.cpp 3 | * 4 | * Created on: 2015��1��13�� 5 | * Author: Administrator 6 | */ 7 | 8 | #include "HttpClient.h" 9 | 10 | namespace zertcore { namespace net { namespace tcp { namespace client { 11 | 12 | HttpClient::~HttpClient() { 13 | // TODO Auto-generated destructor stub 14 | } 15 | 16 | void HttpClient:: 17 | get(const string& url, const handler_type& handler) { 18 | ; 19 | } 20 | 21 | void HttpClient:: 22 | post(const string& url, const string& post, const handler_type& handler) { 23 | ; 24 | } 25 | 26 | 27 | }}}} 28 | -------------------------------------------------------------------------------- /zertco5/utils/http/HttpClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HttpClient.h 3 | * 4 | * Created on: 2015��1��13�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZRETCORE_HTTPCLIENT_H_ 9 | #define ZRETCORE_HTTPCLIENT_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include "HttpConnection.h" 17 | 18 | namespace zertcore { namespace concurrent { 19 | using namespace zertcore::concurrent; 20 | }} 21 | 22 | namespace zertcore { namespace net { namespace tcp { namespace client{ 23 | 24 | /** 25 | * HttpClient 26 | */ 27 | class HttpClient : 28 | public ClientBase 29 | { 30 | public: 31 | typedef ThreadHandler 32 | handler_type; 33 | 34 | public: 35 | virtual ~HttpClient(); 36 | 37 | public: 38 | void get(const string& url, const handler_type& handler); 39 | void post(const string& url, const string& post, 40 | const handler_type& handler); 41 | 42 | private: 43 | }; 44 | 45 | }}}} 46 | 47 | #endif /* HTTPCLIENT_H_ */ 48 | -------------------------------------------------------------------------------- /zertco5/utils/http/HttpClientConnection.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * HttpClientConnection.cpp 3 | * 4 | * Created on: 2015年2月1日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "HttpConnection.h" 9 | #include "HttpClient.h" 10 | 11 | namespace zertcore { namespace net { namespace tcp { 12 | 13 | HttpClientConnection::HttpClientConnection(client::HttpClient& client) : 14 | ConnectionBase(client) { 15 | ; 16 | } 17 | 18 | HttpClientConnection::~HttpClientConnection() { 19 | ::printf("~HttpClientConnection()\n"); 20 | } 21 | 22 | void HttpClientConnection:: 23 | connect(const string& host, const u32 port) { 24 | ; 25 | } 26 | 27 | void HttpClientConnection:: 28 | onConnect() { 29 | ;// write HTTP request header 30 | } 31 | 32 | size_t HttpClientConnection:: 33 | onRead(const SharedBuffer& buffer) { 34 | return 0; 35 | } 36 | 37 | }}} 38 | -------------------------------------------------------------------------------- /zertco5/utils/http/HttpResponse.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/utils/http/HttpResponse.cpp -------------------------------------------------------------------------------- /zertco5/utils/http/HttpResponse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HttpResponse.h 3 | * 4 | * Created on: 2015��1��11�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_HTTPRESPONSE_H_ 9 | #define ZERTCORE_HTTPRESPONSE_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { namespace net { namespace details { 15 | 16 | /** 17 | * HttpConnection 18 | */ 19 | class HttpResponse 20 | { 21 | public: 22 | enum { 23 | STATUS_NONE = 0, 24 | 25 | STATUS_OK = 200, 26 | 27 | STATUS_MOVED_PERMANENTLY = 301, 28 | 29 | STATUS_BAD_REQUEST = 400, 30 | STATUS_UNAUTHORIZED = 401, 31 | STATUS_FORBIDDDEN = 403, 32 | STATUS_NOT_FOUND = 404, 33 | STATUS_NOT_ACCEPTABLE = 406, 34 | 35 | STATUS_SERVER_ERROR = 500, 36 | STATUS_BAD_GATEWAY = 502, 37 | STATUS_SERVICE_UNAVAILABLE = 503, 38 | STATUS_GATEWAY_TIMEOUT = 504, 39 | }; 40 | 41 | public: 42 | HttpResponse(); 43 | virtual ~HttpResponse(); 44 | 45 | public: 46 | void setStatus(const u32& status, const string& status_msg = string()); 47 | void setResponse(const string& content) {response_content_ = content;} 48 | 49 | public: 50 | string output(); 51 | 52 | private: 53 | u32 status_; 54 | string response_content_; 55 | }; 56 | 57 | }}} 58 | 59 | #endif /* HTTPRESPONSE_H_ */ 60 | -------------------------------------------------------------------------------- /zertco5/utils/http/HttpServer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * HttpServer.cpp 3 | * 4 | * Created on: 2015��1��11�� 5 | * Author: Administrator 6 | */ 7 | 8 | #include "HttpServer.h" 9 | 10 | namespace zertcore {namespace net { namespace tcp { namespace server { 11 | 12 | HttpServer::~HttpServer() { 13 | // TODO Auto-generated destructor stub 14 | } 15 | 16 | void HttpServer:: 17 | runHandler(HttpServerConnection::ptr conn) { 18 | /** 19 | ConcurrentState::ptr state = ConcurrentState::create(callback_type([conn] (RuntimeContext::ptr rc) { 20 | ::printf("on State\n"); 21 | if (!rc.error) 22 | conn->flush(); 23 | })); 24 | */ 25 | 26 | handler_.setParams(conn); 27 | handler_.push(); 28 | } 29 | 30 | }}}} 31 | -------------------------------------------------------------------------------- /zertco5/utils/http/HttpServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HttpServer.h 3 | * 4 | * Created on: 2015��1��11�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_HTTPSERVER_H_ 9 | #define ZERTCORE_HTTPSERVER_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include "HttpConnection.h" 17 | 18 | namespace zertcore { namespace net { namespace tcp { namespace server { 19 | 20 | /** 21 | * HttpServer 22 | */ 23 | class HttpServer : 24 | public ServerBase 25 | { 26 | public: 27 | typedef concurrent::ThreadHandler 28 | handler_type; 29 | public: 30 | virtual ~HttpServer(); 31 | 32 | public: 33 | void setHandler(const handler_type& handler) { 34 | handler_ = handler; 35 | } 36 | 37 | public: 38 | void runHandler(HttpServerConnection::ptr conn); 39 | 40 | private: 41 | handler_type handler_; 42 | }; 43 | 44 | }}}} 45 | 46 | #endif /* HTTPSERVER_H_ */ 47 | -------------------------------------------------------------------------------- /zertco5/utils/http/HttpServerConnection.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * HttpConnection.cpp 3 | * 4 | * Created on: 2015��1��11�� 5 | * Author: Administrator 6 | */ 7 | 8 | #include "HttpConnection.h" 9 | #include "HttpServer.h" 10 | 11 | namespace zertcore { namespace net { namespace tcp { 12 | 13 | HttpServerConnection::HttpServerConnection(server::HttpServer& server): 14 | ConnectionBase(server) { 15 | ; 16 | } 17 | 18 | HttpServerConnection::~HttpServerConnection() { 19 | // TODO Auto-generated destructor stub 20 | ::printf("~HttpServerConnection()\n"); 21 | } 22 | 23 | size_t HttpServerConnection:: 24 | onRead(const SharedBuffer& buffer) { 25 | u32 handle_size = 0; 26 | if (!request_.parse(buffer, handle_size)) { 27 | response_.setStatus(details::HttpResponse::STATUS_BAD_REQUEST); 28 | return 0; 29 | } 30 | 31 | ::printf("handle_size = %u\n", handle_size); 32 | 33 | if (request_.isDone()) { 34 | getService().runHandler(thisPtr()); 35 | } 36 | 37 | return handle_size; 38 | } 39 | 40 | void HttpServerConnection:: 41 | flush() { 42 | string output = move(response_.output()); 43 | write((const u8 *)output.data(), output.size(), true); 44 | } 45 | 46 | }}} 47 | -------------------------------------------------------------------------------- /zertco5/utils/http/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | The mainly purpose of this method to enable HTTP protocol as API. 3 | So just support GET & POST tow actions. 4 | -------------------------------------------------------------------------------- /zertco5/utils/msgpack/msgpack_stream_intend.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * msgpack_stream_intend.cpp 3 | * 4 | * Created on: 2015��1��23�� 5 | * Author: Administrator 6 | */ 7 | 8 | #include "msgpack_stream_intend.h" 9 | 10 | namespace msgpack { 11 | MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) { 12 | 13 | void zc_safe_input_object::alloc() { 14 | if (!size) 15 | return ; 16 | 17 | ptr = smart_ptr(new char[real_size(size)]); 18 | } 19 | 20 | void zc_safe_input_object::dump() { 21 | if (!via.str.size) { 22 | via.str.ptr = ptr.get(); 23 | return; 24 | } 25 | 26 | if (via.str.size > size) { 27 | size = via.str.size; 28 | alloc(); 29 | } 30 | 31 | char* mem = ptr.get(); 32 | if (mem == via.str.ptr) 33 | return ; 34 | 35 | memcpy(mem, via.str.ptr, real_size(via.str.size)); 36 | via.str.ptr = mem; 37 | } 38 | 39 | uint32_t zc_safe_input_object::real_size(const uint32_t& s) const { 40 | uint32_t need_size = s; 41 | 42 | switch (type) { 43 | case type::STR: 44 | break; 45 | case type::BIN: 46 | break; 47 | case type::ARRAY: 48 | need_size *= sizeof(object); 49 | break; 50 | case type::MAP: 51 | need_size *= sizeof(object_kv); 52 | break; 53 | case type::EXT: 54 | need_size++; 55 | break ; 56 | 57 | default: 58 | return 0; 59 | } 60 | 61 | return need_size; 62 | } 63 | 64 | }} 65 | 66 | -------------------------------------------------------------------------------- /zertco5/utils/perf/Performance.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Performance.cpp 3 | * 4 | * Created on: 2015年3月5日 5 | * Author: Administrator 6 | */ 7 | #include "Performance.h" 8 | 9 | #include 10 | 11 | namespace zertcore { namespace utils { 12 | 13 | void PerformanceManager:: 14 | init() { 15 | /** 16 | * make it to slow log method way 17 | * 18 | ZC_ASSERT(ThreadPool::Instance().registerExclusiveHandler( 19 | bind(&PerformanceManager::logData, this))); 20 | */ 21 | } 22 | 23 | void PerformanceManager:: 24 | add(const mod_type& mod, const time_type& cost) { 25 | // spinlock_guard_type guard(lock_); 26 | 27 | Cell& cell = perf_map_[mod]; 28 | cell.times++; 29 | cell.total_cost += cost; 30 | } 31 | 32 | time_type PerformanceManager:: 33 | getAverageCost(const mod_type& mod) { 34 | perf_map_type::const_iterator it = perf_map_.find(mod); 35 | if (it == perf_map_.end()) 36 | return 0; 37 | 38 | const Cell& cell = it->second; 39 | return cell.total_cost.value / cell.times; 40 | } 41 | 42 | size_t PerformanceManager:: 43 | logData() { 44 | do { 45 | spinlock_guard_type guard(lock_); 46 | 47 | //save the data 48 | } 49 | while(false); 50 | 51 | usleep(1000); 52 | return 0; 53 | } 54 | 55 | }} 56 | 57 | 58 | -------------------------------------------------------------------------------- /zertco5/utils/random/Random.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Random.cpp 3 | * 4 | * Created on: 2015年7月6日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "Random.h" 9 | 10 | namespace zertcore { namespace utils { 11 | 12 | i32 Random::seed_ = 0; 13 | }} 14 | 15 | namespace zertcore { namespace utils { 16 | 17 | void Random:: 18 | init() { 19 | ; 20 | } 21 | 22 | double Random:: 23 | value() { 24 | srand(seed_); 25 | seed_ = rand(); 26 | return (double)seed_ / RAND_MAX; 27 | } 28 | 29 | bool Random:: 30 | happen(double rate) { 31 | return value() < rate; 32 | } 33 | 34 | }} 35 | -------------------------------------------------------------------------------- /zertco5/utils/random/Random.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Random.h 3 | * 4 | * Created on: 2015年7月6日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_UTILS_RANDOM_RANDOM_H_ 9 | #define ZERTCORE_UTILS_RANDOM_RANDOM_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace zertcore{ namespace utils { 16 | 17 | /** 18 | * Random 19 | */ 20 | struct Random 21 | { 22 | static void init(); 23 | 24 | static double value(); 25 | /** 26 | * rate >= 1: 100% happen! 27 | * rate <= 0: 100% not happen 28 | * 0 < rate < 1: (rate * 100) percent happen 29 | */ 30 | static bool happen(double rate); 31 | 32 | template 33 | static Iterator get(Iterator begin, Iterator end, size_t size = 0) { 34 | size_t r = size; 35 | if (r == 0) 36 | for (Iterator it = begin; it != end; ++it) ++r; 37 | 38 | r = r * value(); 39 | Iterator it = begin; 40 | for (; r && it != end; ++it, --r); 41 | 42 | return it; 43 | } 44 | 45 | private: 46 | static i32 seed_; 47 | }; 48 | 49 | }} 50 | 51 | 52 | #endif /* UTILS_RANDOM_RANDOM_H_ */ 53 | -------------------------------------------------------------------------------- /zertco5/utils/simplehttp/HttpResponse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HttpResponse.h 3 | * 4 | * Created on: 2015年10月16日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_UTILS_SIMPLEHTTP_HTTPRESPONSE_H_ 9 | #define ZERTCORE_UTILS_SIMPLEHTTP_HTTPRESPONSE_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace zertcore { namespace utils { 17 | namespace http { 18 | 19 | enum status_type { 20 | STATUS_NONE = 0, 21 | 22 | STATUS_OK, 23 | STATUS_MOVED_PERMANENTLY, 24 | 25 | STATUS_BAD_REQUEST, 26 | STATUS_UNAUTHORIZED, 27 | STATUS_FORBIDDDEN, 28 | STATUS_NOT_FOUND, 29 | STATUS_NOT_ALLOWED, 30 | STATUS_NOT_ACCEPTABLE, 31 | 32 | STATUS_SERVER_ERROR, 33 | STATUS_NOT_IMPLEMENTED, 34 | STATUS_BAD_GATEWAY, 35 | STATUS_SERVICE_UNAVAILABLE, 36 | STATUS_GATEWAY_TIMEOUT, 37 | }; 38 | 39 | }}} 40 | 41 | namespace zertcore { namespace utils { 42 | 43 | /** 44 | * HttpConnection 45 | */ 46 | class HttpResponse 47 | { 48 | public: 49 | bool response(const http::status_type& status, const SharedBuffer& content); 50 | 51 | public: 52 | const SharedBuffer& output(); 53 | 54 | private: 55 | u32 status_; 56 | SharedBuffer response_; 57 | }; 58 | 59 | }} 60 | 61 | #endif /* UTILS_SIMPLEHTTP_HTTPRESPONSE_H_ */ 62 | -------------------------------------------------------------------------------- /zertco5/utils/simplehttp/HttpServer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * HttpServer.cpp 3 | * 4 | * Created on: 2015��1��11�� 5 | * Author: Administrator 6 | */ 7 | 8 | #include "HttpServer.h" 9 | #include "ServerConnection.h" 10 | 11 | #include 12 | 13 | namespace zertcore { namespace net { 14 | 15 | HttpServer::HttpServer() : inited_(false) { 16 | config_.host = "0.0.0.0"; 17 | config_.port = 80; 18 | config_.thread_nums = 6; 19 | } 20 | 21 | HttpServer::~HttpServer() {} 22 | 23 | bool HttpServer:: 24 | init() { 25 | if (inited_) { 26 | return false; 27 | } 28 | 29 | return inited_ = setup(config_); 30 | } 31 | 32 | bool HttpServer:: 33 | setConfig(const ServerConfig& config) { 34 | if (inited_) 35 | return false; 36 | 37 | config_ = config; 38 | return true; 39 | } 40 | 41 | void HttpServer:: 42 | handle(SMART_PTR(ServerConnection) conn) { 43 | /** 44 | ConcurrentState::ptr state = ConcurrentState::create(callback_type([conn] (RuntimeContext::ptr rc) { 45 | ::printf("on State\n"); 46 | if (!rc.error) 47 | conn->flush(); 48 | })); 49 | */ 50 | 51 | handler_.setParams(conn); 52 | handler_.push(); 53 | } 54 | 55 | }} 56 | -------------------------------------------------------------------------------- /zertco5/utils/simplehttp/HttpServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HttpServer.h 3 | * 4 | * Created on: 2015��1��11�� 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_HTTPSERVER_H_ 9 | #define ZERTCORE_HTTPSERVER_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace zertcore { namespace net { 17 | 18 | class ServerConnection; 19 | 20 | /** 21 | * HttpServer 22 | */ 23 | class HttpServer : 24 | public tcp::server::ServerBase 25 | { 26 | public: 27 | typedef concurrent::ThreadHandler 28 | handler_type; 29 | public: 30 | HttpServer(); 31 | virtual ~HttpServer(); 32 | 33 | /** 34 | * must set config before init 35 | */ 36 | bool setConfig(const ServerConfig& config); 37 | bool init(); 38 | 39 | public: 40 | void setHandler(const handler_type& handler) { 41 | handler_ = handler; 42 | } 43 | 44 | public: 45 | void handle(SMART_PTR(ServerConnection) conn); 46 | 47 | private: 48 | bool inited_; 49 | ServerConfig config_; 50 | handler_type handler_; 51 | }; 52 | 53 | }} 54 | 55 | #endif /* HTTPSERVER_H_ */ 56 | -------------------------------------------------------------------------------- /zertco5/utils/simplehttp/ServerConnection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ServerConnection.h 3 | * 4 | * Created on: 2015年10月18日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_UTILS_SIMPLEHTTP_SERVERCONNECTION_H_ 9 | #define ZERTCORE_UTILS_SIMPLEHTTP_SERVERCONNECTION_H_ 10 | 11 | #include 12 | #include 13 | 14 | #include "HttpParser.h" 15 | #include "HttpResponse.h" 16 | 17 | namespace zertcore { namespace net { 18 | using namespace zertcore::utils; 19 | 20 | class HttpServer; 21 | }} 22 | 23 | namespace zertcore { namespace net { 24 | 25 | /** 26 | * ServerConnection 27 | */ 28 | class ServerConnection : 29 | public tcp::ConnectionBase 30 | { 31 | public: 32 | ServerConnection(HttpServer& server); 33 | virtual ~ServerConnection() {} 34 | 35 | public: 36 | const HttpContext& context() const { return context_; } 37 | const string& get(const string& key); 38 | const string& cookie(const string& key); 39 | 40 | public: 41 | bool response(const http::status_type& status, const SharedBuffer& content); 42 | bool response(const http::status_type& status); 43 | bool response(const SharedBuffer& content); 44 | 45 | public: 46 | virtual size_t onRead(const SharedBuffer& buffer); 47 | 48 | private: 49 | 50 | private: 51 | HttpContext context_; 52 | HttpResponse response_; 53 | }; 54 | 55 | }} 56 | 57 | #endif /* UTILS_SIMPLEHTTP_SERVERCONNECTION_H_ */ 58 | -------------------------------------------------------------------------------- /zertco5/utils/simplehttp/utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * utils.cpp 3 | * 4 | * Created on: 2015年10月18日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "utils.h" 9 | 10 | namespace zertcore { namespace utils { 11 | 12 | char mcodes[256] = { 13 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 14 | }; 15 | 16 | }} 17 | -------------------------------------------------------------------------------- /zertco5/utils/simplehttp/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * utils.h 3 | * 4 | * Created on: 2015年10月18日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_UTILS_SIMPLEHTTP_UTILS_H_ 9 | #define ZERTCORE_UTILS_SIMPLEHTTP_UTILS_H_ 10 | 11 | namespace zertcore { namespace utils { 12 | extern char mcodes[256]; 13 | }} 14 | 15 | 16 | 17 | #endif /* UTILS_SIMPLEHTTP_UTILS_H_ */ 18 | -------------------------------------------------------------------------------- /zertco5/utils/spinlock/SpinLock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SpinLock.h 3 | * 4 | * Created on: 2015年4月22日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_UTILS_SPINLOCK_SPINLOCK_H_ 9 | #define ZERTCORE_UTILS_SPINLOCK_SPINLOCK_H_ 10 | 11 | #include 12 | 13 | namespace zertcore { namespace utils { 14 | 15 | /** 16 | * LockGuard 17 | */ 18 | template 19 | class LockGuard : noncopyable 20 | { 21 | public: 22 | typedef LockType lock_type; 23 | 24 | public: 25 | explicit LockGuard( lock_type & lock ) : lock_(lock) { 26 | lock_.lock(); 27 | } 28 | ~LockGuard() { 29 | lock_.unlock(); 30 | } 31 | 32 | private: 33 | lock_type& lock_; 34 | }; 35 | 36 | namespace details { 37 | /** 38 | * yield 39 | */ 40 | inline static void yield(unsigned long long t) { 41 | if (t < 5) {} 42 | else if (t < 50) {usleep(0);} 43 | else {usleep(1);} 44 | } 45 | 46 | } 47 | 48 | class SpinLock 49 | { 50 | public: 51 | SpinLock() : v_(0) {} 52 | 53 | public: 54 | bool try_lock() { 55 | int r = __sync_lock_test_and_set(&v_, 1); 56 | return r == 0; 57 | } 58 | 59 | void lock(){ 60 | for(unsigned long long k = 0; !try_lock(); ++k) { 61 | details::yield( k ); 62 | } 63 | } 64 | 65 | void unlock() { 66 | __sync_lock_release(&v_); 67 | } 68 | 69 | private: 70 | int v_; 71 | }; 72 | 73 | }} 74 | 75 | 76 | #endif /* UTILS_SPINLOCK_SPINLOCK_H_ */ 77 | -------------------------------------------------------------------------------- /zertco5/utils/sys/System.h: -------------------------------------------------------------------------------- 1 | /* 2 | * System.h 3 | * 4 | * Created on: 2015年6月24日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_UTILS_SYS_SYSTEM_H_ 9 | #define ZERTCORE_UTILS_SYS_SYSTEM_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { namespace utils { 15 | 16 | /** 17 | * System 18 | */ 19 | class System 20 | { 21 | public: 22 | static u32 CPUCoreCount() { 23 | return sysconf(_SC_NPROCESSORS_ONLN); 24 | } 25 | }; 26 | 27 | }} 28 | 29 | 30 | #endif /* UTILS_SYS_SYSTEM_H_ */ 31 | -------------------------------------------------------------------------------- /zertco5/utils/tags/TagsValue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TagsValue.h 3 | * 4 | * Created on: 2015-2-17 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_TAGSVALUE_H_ 9 | #define ZERTCORE_TAGSVALUE_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "details/Tags.h" 16 | #include "../group/Group.h" 17 | 18 | namespace zertcore { namespace utils { 19 | 20 | /** 21 | * TagsValue 22 | */ 23 | template 24 | class TagsValue 25 | { 26 | public: 27 | typedef Value value_type; 28 | 29 | typedef Group group_type; 30 | 31 | public: 32 | typedef tags::Tags 33 | tags_type; 34 | public: 35 | typedef typename tags_type::ptr node_ptr; 36 | 37 | public: 38 | template 39 | group_type find(const Tag& v) { 40 | typedef typename tags::TagTraits::map_type map_type; 41 | typedef typename map_type::iterator iterator; 42 | pair p; 43 | tags_.find(v, p); 44 | 45 | return p; 46 | } 47 | 48 | node_ptr make(const value_type& v) { 49 | node_ptr node = tags_type::create(); 50 | node->value = v; 51 | return node; 52 | } 53 | void remove(node_ptr node) { 54 | tags_.erase(node); 55 | } 56 | 57 | template 58 | void addTag(node_ptr node, const Tag& v) { 59 | tags_.insert(node, v); 60 | } 61 | 62 | private: 63 | tags_type tags_; 64 | }; 65 | 66 | }} 67 | 68 | #endif /* TAGSVALUE_H_ */ 69 | -------------------------------------------------------------------------------- /zertco5/utils/time/CPUTime.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/utils/time/CPUTime.cpp -------------------------------------------------------------------------------- /zertco5/utils/time/CPUTime.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warriorguo/zertcore5/9f6c9a352ce1526f7fd55cb546d6a5c5c0ebee7c/zertco5/utils/time/CPUTime.h -------------------------------------------------------------------------------- /zertco5/utils/time/TimeType.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * TimeType.cpp 3 | * 4 | * Created on: 2015��1��3�� 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | 10 | #include "TimeType.h" 11 | 12 | 13 | namespace zertcore{ namespace time_utils { 14 | 15 | TimeType operator + (const TimeType& t1, const TimeType& t2) { 16 | TimeType r(t1); r += t2; 17 | return r; 18 | } 19 | TimeType operator - (const TimeType& t1, const TimeType& t2) { 20 | TimeType r(t1); r -= t2; 21 | return r; 22 | } 23 | 24 | }} 25 | -------------------------------------------------------------------------------- /zertco5/utils/time/Timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Timer.cpp 3 | * 4 | * Created on: 2015年2月6日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "Timer.h" 9 | #include "TimerManager.h" 10 | 11 | #include 12 | 13 | namespace zertcore { namespace time_utils { 14 | 15 | Timer::Timer() : 16 | interval_(0), is_expired_(false), 17 | is_registered_(false) { 18 | ; 19 | } 20 | 21 | Timer::~Timer() { 22 | remove(); 23 | } 24 | 25 | void Timer:: 26 | remove() { 27 | spinlock_guard_type guard(lock_); 28 | if (is_registered_) { 29 | is_registered_ = false; 30 | list_key_->second = null; 31 | } 32 | } 33 | 34 | void Timer:: 35 | add() { 36 | spinlock_guard_type guard(lock_); 37 | ZC_ASSERT(!is_registered_); 38 | 39 | is_expired_ = false; 40 | is_registered_ = true; 41 | 42 | list_key_ = TimerManager::Instance().registerTimer(this); 43 | } 44 | 45 | void Timer:: 46 | reset() { 47 | remove(); 48 | add(); 49 | } 50 | 51 | bool Timer:: 52 | expired() { 53 | return is_expired_; 54 | } 55 | 56 | void Timer:: 57 | onExpired(const handler_type& handler) { 58 | expired_handler_ = handler; 59 | } 60 | 61 | bool Timer:: 62 | start(const counter_type& intval) { 63 | if (!intval) 64 | return false; 65 | 66 | interval_ = intval; 67 | 68 | reset(); 69 | return true; 70 | } 71 | 72 | void Timer:: 73 | stop() { 74 | remove(); 75 | } 76 | 77 | void Timer:: 78 | timeUp() { 79 | spinlock_guard_type guard(lock_); 80 | ZC_ASSERT(is_registered_); 81 | 82 | is_registered_ = false; 83 | is_expired_ = true; 84 | 85 | if (expired_handler_) { 86 | expired_handler_.setParams(interval_); 87 | expired_handler_.push(); 88 | } 89 | } 90 | 91 | }} 92 | 93 | -------------------------------------------------------------------------------- /zertco5/utils/time/TimerManager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * TimerManager.cpp 3 | * 4 | * Created on: 2015年2月6日 5 | * Author: Administrator 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #include "TimerManager.h" 12 | 13 | namespace zertcore { namespace time_utils { 14 | using namespace zertcore::core; 15 | }} 16 | 17 | namespace zertcore { namespace time_utils { 18 | 19 | void TimerManager:: 20 | init() {} 21 | 22 | timer_list_key_type TimerManager:: 23 | registerTimer(timer_ptr timer) { 24 | ZC_ASSERT(timer); 25 | 26 | timer_type::counter_type now(Now); 27 | return timer_list_.insert( 28 | timer_sorted_list_type::value_type(now + timer->getInterval(), timer)); 29 | } 30 | 31 | u32 TimerManager:: 32 | update() { 33 | u32 update_size = 0; 34 | timer_type::counter_type now(Now); 35 | 36 | for (auto it = timer_list_.begin(); it != timer_list_.end(); ) { 37 | auto hit(it++); 38 | 39 | if (now < hit->first) 40 | break; 41 | 42 | timer_ptr timer = hit->second; 43 | timer_list_.erase(hit); 44 | 45 | if (timer) { 46 | timer->timeUp(); 47 | } 48 | 49 | ++update_size; 50 | } 51 | 52 | return update_size; 53 | } 54 | 55 | }} 56 | 57 | -------------------------------------------------------------------------------- /zertco5/utils/time/TimerManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TimerManager.h 3 | * 4 | * Created on: 2015年2月6日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_TIMERMANAGER_H_ 9 | #define ZERTCORE_TIMERMANAGER_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "Timer.h" 16 | 17 | namespace zertcore { namespace time_utils { 18 | using namespace zertcore::concurrent; 19 | using namespace zertcore::utils; 20 | }} 21 | 22 | namespace zertcore { namespace time_utils { 23 | 24 | /** 25 | * TimerManager 26 | */ 27 | class TimerManager : 28 | public ThreadSingleton 29 | { 30 | public: 31 | timer_list_key_type registerTimer(timer_ptr timer); 32 | 33 | public: 34 | void init(); 35 | u32 update(); 36 | 37 | private: 38 | timer_sorted_list_type timer_list_; 39 | }; 40 | 41 | }} 42 | 43 | 44 | 45 | #endif /* TIMERMANAGER_H_ */ 46 | -------------------------------------------------------------------------------- /zertco5/utils/time/details/TickTypeSerialization.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * TickTypeSerialization.hpp 3 | * 4 | * Created on: 2015年5月8日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_UTILS_TIME_DETAILS_TICKTYPESERIALIZATION_HPP_ 9 | #define ZERTCORE_UTILS_TIME_DETAILS_TICKTYPESERIALIZATION_HPP_ 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { namespace serialization { 15 | using namespace zertcore::time_utils; 16 | 17 | template 18 | inline Serializer& operator << (Serializer& s, const Tick& v) { 19 | s.setValue(v.value()); 20 | return s; 21 | } 22 | 23 | template 24 | inline bool operator >> (const Unserializer& s, Tick& v) { 25 | return s.getValue(v.value()); 26 | } 27 | 28 | }} 29 | 30 | 31 | 32 | #endif /* UTILS_TIME_DETAILS_TICKTYPESERIALIZATION_HPP_ */ 33 | -------------------------------------------------------------------------------- /zertco5/utils/time/details/TimeTypeSerialization.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * TimeTypeSerialization.h 3 | * 4 | * Created on: 2014-10-5 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_TIMETYPESERIALIZATION_H_ 9 | #define ZERTCORE_TIMETYPESERIALIZATION_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { namespace serialization { 15 | using namespace zertcore::time_utils; 16 | 17 | template 18 | inline Serializer& operator << (Serializer& s, const TimeType& v) { 19 | s.setValue(v.value); 20 | return s; 21 | } 22 | 23 | template 24 | inline bool operator >> (const Unserializer& s, TimeType& v) { 25 | return s.getValue(v.value); 26 | } 27 | 28 | /** 29 | template 30 | inline Archiver& operator << (Archiver& archiver, const time_type& time) { 31 | archiver << time.value; 32 | return true; 33 | } 34 | template 35 | inline bool operator >> (Archiver& archiver, time_type& time) { 36 | archiver >> time.value; 37 | return true; 38 | } 39 | */ 40 | 41 | }} 42 | 43 | #endif /* TIMETYPESERIALIZATION_H_ */ 44 | -------------------------------------------------------------------------------- /zertco5/utils/tools/SameThreadChecker.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SameThreadChecker.cpp 3 | * 4 | * Created on: 2015年5月29日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "SameThreadChecker.h" 9 | #include 10 | #include 11 | 12 | namespace zertcore { namespace utils { 13 | using namespace zertcore::concurrent; 14 | }} 15 | 16 | namespace zertcore { namespace utils { 17 | 18 | #ifdef DISABLE_THREAD_CHECKER 19 | 20 | void SameThreadChecker::init() {} 21 | void SameThreadChecker::check() const {} 22 | 23 | #else 24 | 25 | void SameThreadChecker:: 26 | init() { 27 | if (!Thread::isSetup()) { 28 | ZCLOG(FATAL) << "Thread was not setup" << End; 29 | } 30 | 31 | tid_ = Thread::getCurrentTid(); 32 | } 33 | 34 | void SameThreadChecker:: 35 | check() const { 36 | tid_type current_tid = Thread::getCurrentTid(); 37 | if (tid_ != current_tid) { 38 | ZCLOG(FATAL) << "Thread Checker failed: Should In " << tid_ << " Current In " << current_tid << End; 39 | } 40 | } 41 | 42 | #endif 43 | 44 | }} 45 | 46 | -------------------------------------------------------------------------------- /zertco5/utils/tools/SameThreadChecker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SameThreadChecker.h 3 | * 4 | * Created on: 2015年5月29日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_UTILS_TOOLS_SAMETHREADCHECKER_H_ 9 | #define ZERTCORE_UTILS_TOOLS_SAMETHREADCHECKER_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { namespace utils { 15 | 16 | /** 17 | * SameThreadChecker 18 | */ 19 | class SameThreadChecker 20 | { 21 | public: 22 | void init(); 23 | 24 | public: 25 | void check() const; 26 | 27 | private: 28 | tid_type tid_; 29 | }; 30 | 31 | }} 32 | 33 | #define ZC_THREAD_CHECKER private: \ 34 | ::zertcore:utils::SameThreadChecker __sthread_checker; 35 | #define ZC_THREAD_CHECKER_INIT do{__sthread_checker.init();}while(false); 36 | #define ZC_THREAD_CHECKER_DO do{__sthread_checker.check();}while(false); 37 | 38 | #endif /* UTILS_TOOLS_SAMETHREADCHECKER_H_ */ 39 | -------------------------------------------------------------------------------- /zertco5/utils/types.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * types.cpp 3 | * 4 | * Created on: 2014��12��11�� 5 | * Author: Administrator 6 | */ 7 | #include 8 | #include "types.h" 9 | 10 | namespace zertcore { 11 | 12 | Error& Error::setError(const string& msg) { 13 | *this = error::UNKNOWN; 14 | message = msg; 15 | 16 | return *this; 17 | } 18 | 19 | Error& Error::setError(const error_code& c) { 20 | type = (c == NONE)? NONE: ERROR; 21 | code = c; 22 | 23 | return *this; 24 | } 25 | 26 | Error& Error::setError(const error_code& c, const string& msg) { 27 | type = (c == NONE)? NONE: ERROR; 28 | code = c; 29 | message = msg; 30 | 31 | return *this; 32 | } 33 | 34 | Error::operator bool() const { 35 | return type == ERROR; 36 | } 37 | 38 | void Error:: 39 | clear() { 40 | type = NONE; 41 | code = 0; 42 | message.clear(); 43 | } 44 | 45 | } 46 | 47 | 48 | namespace zertcore { 49 | 50 | } 51 | 52 | -------------------------------------------------------------------------------- /zertco5/utils/uuid/UUIDGenerator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * UUIDGenerator.cpp 3 | * 4 | * Created on: 2015年5月4日 5 | * Author: Administrator 6 | */ 7 | 8 | #include "UUIDGenerator.h" 9 | 10 | namespace zertcore { namespace utils { 11 | 12 | uuid_t UUIDGenerator:: 13 | generate() { 14 | return 0; 15 | } 16 | 17 | }} 18 | -------------------------------------------------------------------------------- /zertco5/utils/uuid/UUIDGenerator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * UUIDGenerator.h 3 | * 4 | * Created on: 2015年5月4日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_UTILS_UUID_UUIDGENERATOR_H_ 9 | #define ZERTCORE_UTILS_UUID_UUIDGENERATOR_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace zertcore { namespace utils { 15 | 16 | /** 17 | * UUIDGenerator 18 | */ 19 | class UUIDGenerator 20 | { 21 | public: 22 | static uuid_t generate(); 23 | 24 | private: 25 | }; 26 | 27 | }} 28 | 29 | 30 | #endif /* UTILS_UUID_UUIDGENERATOR_H_ */ 31 | -------------------------------------------------------------------------------- /zertco5/zertcore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * zertcore.h 3 | * 4 | * Created on: 2015年5月8日 5 | * Author: Administrator 6 | */ 7 | 8 | #ifndef ZERTCORE_H_ 9 | #define ZERTCORE_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | #include 42 | 43 | #include
44 | 45 | #include 46 | #include 47 | #include 48 | 49 | #include 50 | #include 51 | 52 | #include 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #include 60 | #include 61 | #include 62 | 63 | #endif /* ZERTCORE_H_ */ 64 | --------------------------------------------------------------------------------