Move all source files into src.

parent 68d9e393
......@@ -2,7 +2,7 @@
# vls Makefile
#-------------------------------------------------------------------------------
# (c)1999-2001 VideoLAN
# $Id: Makefile,v 1.58 2001/10/06 11:27:27 sam Exp $
# $Id: Makefile,v 1.59 2001/10/06 21:23:36 bozo Exp $
################################################################################
# Main Makefile to build the VideoLAN Server
......@@ -26,38 +26,38 @@ LIB += $(VLS_LIB)
#
# Source files
#
CORESRC= core/application.cpp \
core/exception.cpp \
core/file.cpp \
core/log.cpp \
core/parsers.cpp \
core/reflect.cpp \
core/regexp.cpp \
core/serialization.cpp \
core/settings.cpp \
core/socket.cpp \
core/string.cpp \
core/system.cpp \
core/thread.cpp \
MPEGSRC= mpeg/ts.cpp \
mpeg/streamdescr.cpp \
SHAREDSRC= server/buffer.cpp \
server/directory.cpp \
server/input.cpp \
server/output.cpp \
server/channel.cpp \
server/request.cpp \
SERVERSRC= server/admin.cpp \
server/broadcast.cpp \
server/manager.cpp \
server/program.cpp \
server/telnet.cpp \
server/nativeadmin.cpp \
server/vls.cpp \
server/tsstreamer.cpp \
CORESRC= src/core/application.cpp \
src/core/exception.cpp \
src/core/file.cpp \
src/core/log.cpp \
src/core/parsers.cpp \
src/core/reflect.cpp \
src/core/regexp.cpp \
src/core/serialization.cpp \
src/core/settings.cpp \
src/core/socket.cpp \
src/core/string.cpp \
src/core/system.cpp \
src/core/thread.cpp \
MPEGSRC= src/mpeg/ts.cpp \
src/mpeg/streamdescr.cpp \
SHAREDSRC= src/server/buffer.cpp \
src/server/directory.cpp \
src/server/input.cpp \
src/server/output.cpp \
src/server/channel.cpp \
src/server/request.cpp \
SERVERSRC= src/server/admin.cpp \
src/server/broadcast.cpp \
src/server/manager.cpp \
src/server/program.cpp \
src/server/telnet.cpp \
src/server/nativeadmin.cpp \
src/server/vls.cpp \
src/server/tsstreamer.cpp \
# server/file/fileinput.cpp \
# server/dvd/dvdinput.cpp \
# server/remote/remoteinput.cpp \
......@@ -73,16 +73,13 @@ INPUTS= local
INPUTTARGETS:=$(INPUTS:%:bin/%.so)
#REMOTESRC= server/remote/remoteinput.cpp \
#
# Object files
#
COREOBJ:=$(CORESRC:%.cpp=obj/%.o)
MPEGOBJ:=$(MPEGSRC:%.cpp=obj/%.o)
SHAREDOBJ:=$(SHAREDSRC:%.cpp=obj/%.o)
SERVEROBJ:=$(SERVERSRC:%.cpp=obj/%.o)
REMOTEOBJ:=$(REMOTESRC:%.cpp=obj/%.o)
COREOBJ:=$(CORESRC:src/%.cpp=obj/%.o)
MPEGOBJ:=$(MPEGSRC:src/%.cpp=obj/%.o)
SHAREDOBJ:=$(SHAREDSRC:src/%.cpp=obj/%.o)
SERVEROBJ:=$(SERVERSRC:src/%.cpp=obj/%.o)
OBJ:=$(COREOBJ) $(MPEGOBJ) $(SHAREDOBJ) $(SERVEROBJ)
LIBOBJ:=$(REMOTEOBJ)
......@@ -91,11 +88,10 @@ LIBOBJ:=$(REMOTEOBJ)
#
# Dependancies
#
COREDEP:=$(CORESRC:%.cpp=dep/%.d)
MPEGDEP:=$(MPEGSRC:%.cpp=dep/%.d)
SHAREDDEP:=$(SHAREDSRC:%.cpp=dep/%.d)
SERVERDEP:=$(SERVERSRC:%.cpp=dep/%.d)
REMOTEDEP:=$(REMOTESRC:%.cpp=dep/%.d)
COREDEP:=$(CORESRC:src/%.cpp=dep/%.d)
MPEGDEP:=$(MPEGSRC:src/%.cpp=dep/%.d)
SHAREDDEP:=$(SHAREDSRC:src/%.cpp=dep/%.d)
SERVERDEP:=$(SERVERSRC:src/%.cpp=dep/%.d)
DEP:=$(COREDEP) $(MPEGDEP) $(SHAREDDEP) $(SERVERDEP) $(REMOTEDEP)
......@@ -116,16 +112,16 @@ Makefile.opts:
clean:
rm -Rf obj/*
for input in "$(INPUTS)" ; do \
( cd inputs/$$input && $(MAKE) clean ) ; done
( cd src/inputs/$$input && $(MAKE) clean ) ; done
distclean: clean
rm -f bin/vls
rm -f config*status config*cache config*log
rm -f Makefile.opts core/defs.h server/config.h
rm -f Makefile.opts src/core/defs.h src/server/config.h
rm -Rf dep/*
rm -Rf *.log *.dbg
for input in "$(INPUTS)" ; do \
( cd inputs/$$input && $(MAKE) distclean ) ; done
( cd src/inputs/$$input && $(MAKE) distclean ) ; done
dep: Makefile.opts $(DEP)
......@@ -136,18 +132,18 @@ vls: Makefile.opts $(OBJ)
chmod 755 bin/$@
$(INPUTS): %: Makefile.opts
$(INPUTS): %: inputs/%/Makefile
cd inputs/$* && $(MAKE) ../../bin/$*.so
$(INPUTS): %: src/inputs/%/Makefile
cd src/inputs/$* && $(MAKE) ../../../bin/$*.so
$(OBJ): obj/%.o: Makefile.opts
$(OBJ): obj/%.o: dep/%.d
$(OBJ): obj/%.o: %.cpp
$(OBJ): obj/%.o: src/%.cpp
@test -d obj/$(dir $*) || mkdir -p obj/$(dir $*)
@echo "Compiling $<..."
$(CC) $(CCFLAGS) $(INCLUDE) -o $@ -c $<
$(DEP): Makefile.opts Makefile
$(DEP): dep/%.d: %.cpp
$(DEP): dep/%.d: src/%.cpp
@test -d dep/$(dir $*) || mkdir -p dep/$(dir $*)
@echo "Generating dependancies for $<..."
@$(SHELL) -ec '$(CC) $(DCFLAGS) $(INCLUDE) $< \
......
......@@ -41,7 +41,7 @@ distclean: clean
dep: $(DEP)
../../bin/$(INPUT).so: $(OBJ)
../../../bin/$(INPUT).so: $(OBJ)
@echo "Linking $@..."
@test -d ../../bin || mkdir -p ../../bin
$(CC) $(LCFLAGS) $(INPUT_LCFLAGS) -o $@ $^ $(LIB)
......
......@@ -457,7 +457,7 @@ echo > confdefs.h
# A filename unique to this package, relative to the directory that
# configure is in, which we can look for to find out if srcdir is correct.
ac_unique_file=core/core.h
ac_unique_file=src/core/core.h
# Find the source files, if location was not specified.
if test -z "$srcdir"; then
......@@ -3139,7 +3139,7 @@ done
ac_given_srcdir=$srcdir
ac_given_INSTALL="$INSTALL"
trap 'rm -fr `echo "Makefile.opts server/config.h core/defs.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
trap 'rm -fr `echo "Makefile.opts src/server/config.h src/core/defs.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
EOF
cat >> $CONFIG_STATUS <<EOF
......@@ -3244,7 +3244,7 @@ EOF
cat >> $CONFIG_STATUS <<EOF
CONFIG_FILES=\${CONFIG_FILES-"Makefile.opts server/config.h"}
CONFIG_FILES=\${CONFIG_FILES-"Makefile.opts src/server/config.h"}
EOF
cat >> $CONFIG_STATUS <<\EOF
for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then
......@@ -3325,7 +3325,7 @@ ac_eD='%g'
if test "${CONFIG_HEADERS+set}" != set; then
EOF
cat >> $CONFIG_STATUS <<EOF
CONFIG_HEADERS="core/defs.h"
CONFIG_HEADERS="src/core/defs.h"
EOF
cat >> $CONFIG_STATUS <<\EOF
fi
......
dnl Autoconf settings for vls
AC_INIT(core/core.h)
AC_CONFIG_HEADER(core/defs.h)
AC_INIT(src/core/core.h)
AC_CONFIG_HEADER(src/core/defs.h)
AC_CANONICAL_SYSTEM
......@@ -257,7 +257,7 @@ AC_SUBST(INPUT_LCFLAGS)
AC_SUBST(VLS_LCFLAGS)
AC_SUBST(VLS_LIB)
AC_OUTPUT([Makefile.opts server/config.h])
AC_OUTPUT([Makefile.opts src/server/config.h])
echo "
global configuration
......
/*******************************************************************************
* application.cpp: Application class
*-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN
* $Id: application.cpp,v 1.1 2001/10/06 21:23:36 bozo Exp $
*
* Authors: Benoit Steiner <benny@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*-------------------------------------------------------------------------------
* The C_Application class provides some core mecanisms for applications, such
* as a global logging service
*
*******************************************************************************/
//------------------------------------------------------------------------------
// Preamble
//------------------------------------------------------------------------------
#include "defs.h"
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <regex.h>
#include <dirent.h>
#include <signal.h>
#include <sys/types.h>
#include "common.h"
#include "debug.h"
#include "reflect.h"
#include "serialization.h"
#include "string.h"
#include "stack.h"
#include "vector.h"
#include "hashtable.h"
#include "buffers.h"
#include "exception.h"
#include "regexp.h"
#include "file.h"
#include "stream.h"
#include "parsers.h"
#include "settings.h"
#include "log.h"
#include "application.h"
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
C_Application* C_Application::s_pApplication = NULL;
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
C_Application::C_Application(const C_String& strName) : m_strName(strName)
{
ASSERT(s_pApplication == NULL);
s_pApplication = this;
m_hLog = NULL;
m_bOnStop = false;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
C_Application::~C_Application()
{
ASSERT(this == s_pApplication);
s_pApplication = NULL;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
int C_Application::Init(int iArgc, char* paArg[])
{
// Retrieve global configuration from cmd line and cfg file
// Shortly, this step will build a properties table
int iRc = RetrieveConfig(iArgc, paArg);
// Init the logger
if(!iRc)
{
C_String strLogFileSetting = m_strName + ".LogFile";
C_String strDfltLogFile = m_strName.ToLower() + ".log";
C_String strLogFile = GetSetting(strLogFileSetting, strDfltLogFile);
iRc |= m_cLog.Init(strLogFile);
}
// Register the application object by the logger
if(!iRc)
{
m_hLog = StartLog(m_strName, LOG_DBGMSG | LOG_FILE | LOG_SCR );
if(!m_hLog)
iRc = GEN_ERR;
}
// First install the signal handler
if(!iRc)
iRc = InstallSigHandler();
// Do application specific initialisations
if(!iRc)
iRc = OnAppInit();
return iRc;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
int C_Application::Run()
{
return OnAppRun();
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
int C_Application::Stop()
{
if(!m_bOnStop)
{
m_bOnStop = true;
return OnAppExit();
}
else return GEN_ERR;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
int C_Application::Destroy()
{
int iRc = OnAppDestroy();
if(!iRc)
{
if(m_hLog)
StopLog(m_hLog);
iRc = m_cLog.End();
}
return iRc;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
handle C_Application::StartLog(const C_String& strClientDescr, u8 iFlags)
{
handle hLog = m_cLog.Register(strClientDescr, iFlags);
ASSERT(hLog);
return hLog;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void C_Application::StopLog(handle hLog)
{
ASSERT(hLog);
m_cLog.Unregister(hLog);
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void C_Application::LogMsg(handle hLog, int iLevel, const C_String& strMsg)
{
if(hLog)
{
// Use the given handle to log
m_cLog.Append(hLog, iLevel, strMsg);
}
else
{
// Use the application handle to log
m_cLog.Append(m_hLog, iLevel, strMsg);
}
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
int C_Application::InstallSigHandler()
{
int iRc = NO_ERR;
#ifdef HAVE_SIGACTION
sigset_t sSigSet;
sigemptyset(&sSigSet);
struct sigaction sSigAction;
sSigAction.sa_mask = sSigSet;
sSigAction.sa_flags = 0;
//sSigAction.sa_restorer = NULL;
sSigAction.sa_handler = SignalHandler;
if(sigaction(SIGHUP, &sSigAction, NULL) != 0)
{
Log(m_hLog, LOG_ERROR, "Could not install handler for signal SIG_HUP");
iRc |= 1;
}
sSigAction.sa_handler = SignalHandler;
if(sigaction(SIGINT, &sSigAction, NULL) != 0)
{
Log(m_hLog, LOG_ERROR, "Could not install handler for signal SIG_INT");
iRc |= 1;
}
sSigAction.sa_handler = SignalHandler;
if(sigaction(SIGQUIT, &sSigAction, NULL) != 0)
{
Log(m_hLog, LOG_ERROR, "Could not install handler for signal SIG_QUIT");
iRc |= 1;
}
sSigAction.sa_handler = SignalHandler;
if(sigaction(SIGPIPE, &sSigAction, NULL) != 0)
{
Log(m_hLog, LOG_ERROR, "Could not install handler for signal SIG_PIPE");
iRc |= 1;
}
sSigAction.sa_handler = SignalHandler;
if(sigaction(SIGURG, &sSigAction, NULL) != 0)
{
Log(m_hLog, LOG_ERROR, "Could not install handler for signal SIG_URG");
iRc |= 1;
}
// Don't catch the signal if we are in debug mode unless we wouldn't get a core file
#ifndef DEBUG
sSigAction.sa_handler = SignalHandler;
if(sigaction(SIGSEGV, &sSigAction, NULL) != 0)
{
Log(m_hLog, LOG_ERROR, "Could not install handler for signal SIG_SEGV");
iRc |= 1;
}
#endif
sSigAction.sa_handler = SignalHandler;
if(sigaction(SIGTERM, &sSigAction, NULL) != 0)
{
Log(m_hLog, LOG_ERROR, "Could not install handler for signal SIG_TERM");
iRc |= 1;
}
#endif
return iRc;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
int C_Application::RetrieveConfig(int iArgc, char* paArg[])
{
int iRc = NO_ERR;
try
{
m_cSettings.Load(m_strName.ToLower()+".cfg", false);
}
catch(E_Exception e)
{
printf("Could not open configuration file: \n%s", e.Dump().GetString());
iRc = GEN_ERR;
}
return iRc;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void C_Application::SignalHandler(int iSignal)
{
C_Application* pApp = C_Application::GetApp();
ASSERT(pApp);
handle hLog = pApp->m_hLog;
switch(iSignal)
{
case SIGHUP:
{
Log(hLog, LOG_WARN, "Received SIGHUP: Hangup detected");
break;
}
case SIGINT:
{
Log(hLog, LOG_WARN,
"Received SIGINT: Interrupt from keyboard, launching shutdown sequence...");
pApp->Stop();
break;
}
case SIGQUIT:
{
Log(hLog, LOG_WARN,
"Received SIGQUIT: Quit from keyboard, launching shutdown sequence...");
pApp->Stop();
break;
}
case SIGTERM:
{
Log(hLog, LOG_WARN,
"Received SIGTERM: Software termination signal, launching shutdown sequence...");
pApp->Stop();
break;
}
case SIGSEGV:
{
Log(hLog, LOG_WARN,
"Received SIGSEGV: Segmentation Violation, exiting...");
exit(1);
break;
}
case SIGPIPE:
{
// This signal is sent upon attempt to write on a broken stream
// (such as a dead socket)
Log(hLog, LOG_WARN, "Received SIGPIPE: Unexpected Broken Pipe encountered");
break;
}
case SIGURG:
{
// This signal is sent when AOB data is received on a TCP connection
Log(hLog, LOG_NOTE, "Received SIGURG: unexpected AOB data received");
break;
}
default:
{
Log(hLog, LOG_NOTE, "Received signal " + iSignal);
break;
}
}
}
/*******************************************************************************
* application.h: Application class definition
*-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN
* $Id: application.h,v 1.1 2001/10/06 21:23:36 bozo Exp $
*
* Authors: Benoit Steiner <benny@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*-------------------------------------------------------------------------------
* The C_Application class provides some core mecanisms for applications, such
* as a global logging service
*
*******************************************************************************/
#ifndef _APPLICATION_H_
#define _APPLICATION_H_
//------------------------------------------------------------------------------
// C_Application class
//------------------------------------------------------------------------------
// The C_Application class is a singleton: only one instance can therefore
// exist at a time. The constructor is therefore protected. To create your
// application, you can either also protect your wn constructor or hide it and
// provide a static Create method that will ensure that only one application is
// created at a time.
//------------------------------------------------------------------------------
class C_Application
{
public:
// Construction / Destruction
virtual ~C_Application();
// Access to the appliction object
static void SetApp(C_Application* pApp)
{ s_pApplication = pApp; };
static C_Application* GetApp()
{ ASSERT(s_pApplication); return s_pApplication; };
// Application control
int Init(int iArgc, char* paArg[]);
int Run();
int Stop();
int Destroy();
// Access to the settings
C_String GetSetting(const C_String& strSetting, const C_String& strDflt) const
{ return m_cSettings.GetSetting(strSetting, strDflt); }
C_Vector<C_Setting> GetSettings(const C_String& strSettingsGroup) const
{ return m_cSettings.GetSettings(strSettingsGroup); }
// Access to the logging service
handle StartLog(const C_String& strClientDescr, u8 iFlags);
void StopLog(handle hLog);
void LogMsg(handle hLog, int iLevel, const C_String& strMsg);
protected:
// All the methods below can be rewritten to fit the special needs of a
// true application
// Actual instance creation
C_Application(const C_String& strName);
// Application lifecycle
virtual int OnAppInit() = 0;
virtual int OnAppRun() = 0;
virtual int OnAppExit() = 0;
virtual int OnAppDestroy() = 0;
// Default signal handler
static void SignalHandler(int iSignal);
// Loging endpoint local to the C_Application object
handle m_hLog;
protected:
// Protect the application against system signals
int InstallSigHandler();
// Build the property table ttat will store the application config parameters
int RetrieveConfig(int iArgc, char* paArg[]);
private:
// Application name
C_String m_strName;
// Application instance
static C_Application* s_pApplication;
// Application settings
C_Settings m_cSettings;
// Application logs
C_Log m_cLog;
bool m_bOnStop;
};
//------------------------------------------------------------------------------
// Logging facilities
//------------------------------------------------------------------------------
// This functions are defined as macros so that it is possible to use the global
// C_Log object of the application without providing a reference to it each time
// we need to log something. Moreover, some additonal informations are added to
// the debugging messages thanks to the compiler extensions allowed in macros.
//------------------------------------------------------------------------------
// Normal logging
#define Log(handle, level, message) \
C_Application::GetApp()->LogMsg(handle, level, message)
// Debugging logs (works only in DEBUG mode)
#ifdef DEBUG
#define LogDbg(handle, message) \
C_Application::GetApp()->LogMsg(handle, LOG_DEBUG, C_String("In ")+__FILE__+ \
" line "+__LINE__+" -> "+message)