/********************************************************************
(c) Copyright 2014-2015 Mettler-Toledo CT. All Rights Reserved.

File Name: 		LogDefinationInternal.h
File Path:		MTLoggerLib

Description:	LogDefinationInternal

Author:			Wang Bin
Created:		2015/6/10 16:01
Remark:	        LogDefinationInternal
*********************************************************************/


#pragma once

#ifndef _MTLogger_LogDefinationInternal_H
#define _MTLogger_LogDefinationInternal_H

#include "Platform/COsString.h"
#include "Platform/stdutil.h"

#define  HEARTBEAT "\a"
#define LOG_SOCKET_RETRY_TIME 3
#define LOGCONFIG_FILE_NAME "LogService.config"
#define DEFAULT_LOG_LENTH 1024
#define LOGCONFIGDIR "LogConfigs/"
#define LOGCONFIGEXTENSION ".config"
#define LOGFILEEXTENSION ".log"
#define DEFAULTLOGDIR "Log/"
#define DEFAULTLOGHOSTNAME "Default"


/************************************************************************
日志命令
************************************************************************/
enum ELogCommand {
    E_LOGCOMMAND_LOGDELETE,
    E_LOGCOMMAND_LOGWRITE,
    E_LOGCOMMAND_LOGCONFIG,
    E_LOGCOMMAND_LOGSTOP,
};

/************************************************************************
日志对象类型
************************************************************************/
enum ELogObjType {
    E_LOGOBJTYPE_LOGMSG,
    E_LOGOBJTYPE_LOGCONFIG,
    E_LOGOBJTYPE_NULL,  //2015/2/28 add by wangbin 仅在保存日志配置的时候生效，不需要保存这个节点
};

/************************************************************************
日志服务状态
************************************************************************/
enum ELogServerStatus {
    E_LogServerStatus_Unknown,
    E_LogServerStatus_Outline,
    E_LogServerStatus_Online,
};

/************************************************************************
调用写日志线程的是服务端还是客户端
************************************************************************/
enum ELogHostType {
    E_LogHostType_Server,
    E_LogHostType_Client,
};


inline bool GetLogObjTypeValue(const char *strVal, ELogObjType &val)
{
    if (COsString::Compare(strVal, "LOGMSG", true) == 0) {
        val = E_LOGOBJTYPE_LOGMSG;
        return true;
    }
    else if (COsString::Compare(strVal, "LOGCONFIG", true) == 0) {
        val = E_LOGOBJTYPE_LOGCONFIG;
        return true;
    }
    else {
        return false;
    }
}

inline bool GetLogObjTypeString(ELogObjType val, char **strVal)
{
    switch (val) {
        case E_LOGOBJTYPE_LOGMSG: {
            COsString::Copy("LOGMSG", strVal);
            return true;
        }

        case E_LOGOBJTYPE_LOGCONFIG: {
            COsString::Copy("LOGCONFIG", strVal);
            return true;
        }

        case E_LOGOBJTYPE_NULL: {
            *strVal = NULL;
            return true;
        }

        default: {
            SAFE_DELETEA(*strVal);
            return false;
        }
    }
}

#endif // _MTLogger_LogDefinationInternal_H 

