winlin

init st, add error code

... ... @@ -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[@]}"
... ...
/*
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 <srs_core_error.hpp>
... ...
/*
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 <srs_core_error.hpp>
*/
#define ERROR_SUCCESS 0
#define ERROR_ST_SET_EPOLL 100
#define ERROR_ST_INITIALIZE 101
#endif
\ No newline at end of file
... ...
... ... @@ -31,10 +31,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <st.h>
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();
}
... ...
/*
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 <st.h>
#include <srs_core_log.hpp>
#include <srs_core_error.hpp>
#include <srs_core_server.hpp>
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;
}
... ...
/*
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 <srs_core_server.hpp>
*/
class SrsServer
{
public:
SrsServer();
virtual ~SrsServer();
public:
virtual int initialize();
};
#endif
\ No newline at end of file
... ...
... ... @@ -24,12 +24,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <unistd.h>
#include <srs_core_log.hpp>
#include <srs_core_error.hpp>
#include <srs_core_server.hpp>
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;
}
... ...
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
... ...