From 5b02f9c78b52b3ed328ed1f0183bb0ad0ace5617 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 18 Oct 2013 10:39:37 +0800 Subject: [PATCH] init st, add error code --- trunk/configure | 2 +- trunk/src/core/srs_core_error.cpp | 24 ++++++++++++ trunk/src/core/srs_core_error.hpp | 36 +++++++++++++++++ trunk/src/core/srs_core_log.cpp | 36 +++++++++++------ trunk/src/core/srs_core_server.cpp | 63 ++++++++++++++++++++++++++++++ trunk/src/core/srs_core_server.hpp | 40 +++++++++++++++++++ trunk/src/main/srs_main_server.cpp | 11 ++++-- trunk/src/srs/srs.upp | 8 +++- 8 files changed, 201 insertions(+), 19 deletions(-) create mode 100755 trunk/src/core/srs_core_error.cpp create mode 100755 trunk/src/core/srs_core_error.hpp create mode 100755 trunk/src/core/srs_core_server.cpp create mode 100755 trunk/src/core/srs_core_server.hpp diff --git a/trunk/configure b/trunk/configure index 29076aa84..7d58bb896 100755 --- a/trunk/configure +++ b/trunk/configure @@ -82,7 +82,7 @@ LibSTfile="${LibSTRoot}/libst.a" MODULE_ID="CORE" MODULE_DEPENDS=() ModuleLibIncs=(${LibSTRoot}) -MODULE_FILES=("srs_core" "srs_core_log") +MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server" "srs_core_error") MODULE_DIR="src/core" . auto/modules.sh CORE_OBJS="${MODULE_OBJS[@]}" diff --git a/trunk/src/core/srs_core_error.cpp b/trunk/src/core/srs_core_error.cpp new file mode 100755 index 000000000..ccb03dbce --- /dev/null +++ b/trunk/src/core/srs_core_error.cpp @@ -0,0 +1,24 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013 winlin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include diff --git a/trunk/src/core/srs_core_error.hpp b/trunk/src/core/srs_core_error.hpp new file mode 100755 index 000000000..a69b75521 --- /dev/null +++ b/trunk/src/core/srs_core_error.hpp @@ -0,0 +1,36 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013 winlin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef SRS_CORE_ERROR_HPP +#define SRS_CORE_ERROR_HPP + +/* +#include +*/ + +#define ERROR_SUCCESS 0 + +#define ERROR_ST_SET_EPOLL 100 +#define ERROR_ST_INITIALIZE 101 + +#endif \ No newline at end of file diff --git a/trunk/src/core/srs_core_log.cpp b/trunk/src/core/srs_core_log.cpp index 295921451..47b3ba440 100755 --- a/trunk/src/core/srs_core_log.cpp +++ b/trunk/src/core/srs_core_log.cpp @@ -31,10 +31,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include -ILogContext::ILogContext(){ +ILogContext::ILogContext() +{ } -ILogContext::~ILogContext(){ +ILogContext::~ILogContext() +{ } class LogContext : public ILogContext @@ -67,22 +69,25 @@ public: ILogContext* log_context = new LogContext(); -LogContext::DateTime::DateTime(){ +LogContext::DateTime::DateTime() +{ memset(time_data, 0, DATE_LEN); } -LogContext::DateTime::~DateTime(){ +LogContext::DateTime::~DateTime() +{ } -const char* LogContext::DateTime::FormatTime(){ +const char* LogContext::DateTime::FormatTime() +{ // clock time timeval tv; - if(gettimeofday(&tv, NULL) == -1){ + if (gettimeofday(&tv, NULL) == -1) { return ""; } // to calendar time struct tm* tm; - if((tm = localtime(&tv.tv_sec)) == NULL){ + if ((tm = localtime(&tv.tv_sec)) == NULL) { return ""; } @@ -95,22 +100,27 @@ const char* LogContext::DateTime::FormatTime(){ return time_data; } -LogContext::LogContext(){ +LogContext::LogContext() +{ } -LogContext::~LogContext(){ +LogContext::~LogContext() +{ } -void LogContext::SetId(){ - static int id = 0; +void LogContext::SetId() +{ + static int id = 1; cache[st_thread_self()] = id++; } -int LogContext::GetId(){ +int LogContext::GetId() +{ return cache[st_thread_self()]; } -const char* LogContext::FormatTime(){ +const char* LogContext::FormatTime() +{ return time.FormatTime(); } diff --git a/trunk/src/core/srs_core_server.cpp b/trunk/src/core/srs_core_server.cpp new file mode 100755 index 000000000..934a68078 --- /dev/null +++ b/trunk/src/core/srs_core_server.cpp @@ -0,0 +1,63 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013 winlin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include + +#include +#include + +#include + +SrsServer::SrsServer() +{ +} + +SrsServer::~SrsServer() +{ +} + +int SrsServer::initialize() +{ + int ret = ERROR_SUCCESS; + + // use linux epoll. + if (st_set_eventsys(ST_EVENTSYS_ALT) == -1) { + ret = ERROR_ST_SET_EPOLL; + SrsError("st_set_eventsys use linux epoll failed. ret=%d", ret); + return ret; + } + SrsInfo("st_set_eventsys use linux epoll success"); + + if(st_init() != 0){ + ret = ERROR_ST_INITIALIZE; + SrsError("st_init failed. ret=%d", ret); + return ret; + } + SrsTrace("st_init success"); + + // set current log id. + log_context->SetId(); + SrsInfo("log set id success"); + + return ret; +} diff --git a/trunk/src/core/srs_core_server.hpp b/trunk/src/core/srs_core_server.hpp new file mode 100755 index 000000000..01af144e7 --- /dev/null +++ b/trunk/src/core/srs_core_server.hpp @@ -0,0 +1,40 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013 winlin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef SRS_CORE_SERVER_HPP +#define SRS_CORE_SERVER_HPP + +/* +#include +*/ + +class SrsServer +{ +public: + SrsServer(); + virtual ~SrsServer(); +public: + virtual int initialize(); +}; + +#endif \ No newline at end of file diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp index 20dac0c76..31c830940 100755 --- a/trunk/src/main/srs_main_server.cpp +++ b/trunk/src/main/srs_main_server.cpp @@ -24,12 +24,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +#include +#include int main(int /*argc*/, char** /*argv*/){ - log_context->SetId(); + int ret = ERROR_SUCCESS; - SrsWarn("server start."); - SrsInfo("listen at 1935"); + SrsServer server; + + if ((ret = server.initialize()) != ERROR_SUCCESS) { + return ret; + } return 0; } diff --git a/trunk/src/srs/srs.upp b/trunk/src/srs/srs.upp index bff429b9f..de51d1711 100755 --- a/trunk/src/srs/srs.upp +++ b/trunk/src/srs/srs.upp @@ -1,9 +1,13 @@ file - main readonly separator, + main readonly separator, ..\main\srs_main_server.cpp, - core readonly separator, + core readonly separator, ..\core\srs_core.hpp, ..\core\srs_core.cpp, + ..\core\srs_core_error.hpp, + ..\core\srs_core_error.cpp, + ..\core\srs_core_server.hpp, + ..\core\srs_core_server.cpp, ..\core\srs_core_log.hpp, ..\core\srs_core_log.cpp; mainconfig