// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
//  »Project«   Talina Gaming System (TgS) (∂)
//  »File«      TgS Common - Console.h
//  »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
//  »Version«   4.0
// ------------------------------------------------------------------------------------------------------------------------------ //
//  Copyright: © 2002-2010, Andrew Aye.  All Rights Reserved.
//  This software is free for non-commercial use. Redistribution and use in source and binary forms, with or without modification,
//  are permitted provided that the following conditions are met: 
//    Redistributions of source code must retain this copyright notice, this list of conditions and the following disclaimers. 
//    Redistributions in binary form must reproduce this copyright notice, this list of conditions and the following
//      disclaimers in the documentation and other materials provided with the distribution. 
//  Neither the names of the copyright owner nor the names of its contributors may be used to endorse or promote products derived
//  from this software without specific prior written permission. 
//  The intellectual property rights of the algorithms used reside with Andrew Aye.  You may not use this software, in whole or
//  in part, in support of any commercial product without the express written consent of the author.
//  There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
#if !defined(_TGS_COMMON_CONSOLE_H_)
#define _TGS_COMMON_CONSOLE_H_
#pragma once


#if TgS_COMPILE_CONSOLE

// START TGS - CONSOLE /////////////////////////////////////////////////////////////////////////////////////////////////////////////

// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //
//  Constants
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //

// There are twenty-eight (28) console channels.  The first twelve (12) are system reserved (the below enumeration).  The remaining
// sixteen (16) are available to the user and can be assigned arbitrarily.  The first four bits are used to indicate the severity
// of the output (may only be valid for certain channels).

enum { KTgCON_SEVERITY_BITS                 = 4 }; //< Number of bits used to describe message severity (0-15)
enum { KTgCON_CHANEL_BITS                   = 32 - KTgCON_SEVERITY_BITS }; //< The remaining bits are used for the channel

enum { KTgCON_SEVERITY_0                    = 0 };
enum { KTgCON_SEVERITY_1                    = 1 };
enum { KTgCON_SEVERITY_2                    = 2 };
enum { KTgCON_SEVERITY_3                    = 3 };
enum { KTgCON_SEVERITY_4                    = 4 };
enum { KTgCON_SEVERITY_5                    = 5 };
enum { KTgCON_SEVERITY_6                    = 6 };
enum { KTgCON_SEVERITY_7                    = 7 };
enum { KTgCON_SEVERITY_8                    = 8 };
enum { KTgCON_SEVERITY_9                    = 9 };

enum { KTgCON_CHANEL_CONSOLE                = 1 <<  4 };
enum { KTgCON_CHANEL_LOG_SCREEN             = 1 <<  5 };
enum { KTgCON_CHANEL_LOG                    = 1 <<  6 };
enum { KTgCON_CHANEL_LOG_FCN                = 1 <<  7 };
enum { KTgCON_CHANEL_LOG_MEM                = 1 <<  8 };
enum { KTgCON_CHANEL_MESSAGE                = 1 <<  9 };
enum { KTgCON_CHANEL_WARNING                = 1 << 10 };
enum { KTgCON_CHANEL_ERROR                  = 1 << 11 };
enum { KTgCON_CHANEL_CRITICAL               = 1 << 12 };
enum { KTgCON_CHANEL_INITIALIZE             = 1 << 13 };
enum { KTgCON_CHANEL_LOADING                = 1 << 14 };
enum { KTgCON_CHANEL_USER                   = 1 << 15 };


// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //
//  Type Definitions
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //

typedef TgVOID (*TgFCN_CONSOLE)( C_TgUINT32 nuiArg, CP_TgCHAR pArgV[KTgMAX_CMD_LINE_COUNT] );
TgTYPE_PREFIX( TgFCN_CONSOLE );


// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //
//  Preprocessor Definitions
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //

#define TgLOGF( ... )                       tgCO_PrintF( __VA_ARGS__ )
#define TgLOG( ... )                        tgCO_Print( __VA_ARGS__ )
#define TgLOGF_UID( ... )                   tgCO_UID_PrintF( __VA_ARGS__ )
#define TgLOG_UID( ... )                    tgCO_UID_Print( __VA_ARGS__ )


// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //
//  Public Interface
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //

                                            // Standard Module functions for lifetime and update control
TgRESULT                                    tgCO_Init_Module();
TgRESULT                                    tgCO_Boot_Module();
TgRESULT                                    tgCO_Stop_Module();
TgRESULT                                    tgCO_Free_Module();
TgRESULT                                    tgCO_Update_Module( C_TgFLOAT32 );

                                            // The hierarchical standard stream functions work like a stack.  That is the last one
                                            // added to the stack is the first one to receive the data stream. No stream processor
                                            // should steal the data stream from its children. Thus, order should not matter when
                                            // adding stream objects.  Multiple/Stacks of processors are allowed for the common case
                                            // where output to both a visual (screen) and a file simultaneously is desired.

                                            // The output functions are attached to the specified channel(s).
                                            // Return value is channel mask of succeeded attaches
                                            // 1: Channel Mask
TgUINT32                                    tgCO_Attach_Output( C_TgUINT32, PC_STg2_Output );
TgUINT32                                    tgCO_Attach_Default_Break( C_TgUINT32 );
TgUINT32                                    tgCO_Attach_Default_Abort( C_TgUINT32 );

                                            // Return value is channel mask of succeeded removes
                                            // 1: Channel Mask
TgUINT32                                    tgCO_Remove_Output( C_TgUINT32, PC_STg2_Output );
TgUINT32                                    tgCO_Remove_Default_Break( C_TgUINT32 );
TgUINT32                                    tgCO_Remove_Default_Abort( C_TgUINT32 );

                                            // The string must remain valid for as long as the channel is being used.
                                            // 1: Specific Channel Index
TgVOID                                      tgCO_Set_Prefix( C_TgUINT32, CPC_TgCHAR );

                                            // Limit output to a specific literal (class/system)
                                            // 1: Channel Mask
TgVOID                                      tgCO_Set_UID_Filter( C_TgUINT32, C_TgUINT32 );

                                            // Limit output to a specific literal (class/system)
                                            // 1: Channel Mask
TgVOID                                      tgCO_Set_Severity_Filter( C_TgUINT32, C_TgUINT32 );

                                            // Output the given printf formated variable argument string to the given channel

                                            // 1: Channel: A severity-channel(s) value
                                            // 2: String: All remainder parameters are part of the printf style string definition
TgVOID                                      tgCO_Print( C_TgUINT32, CP_TgCHAR );
TgVOID                                      tgCO_PrintF( C_TgUINT32, CP_TgCHAR, ... );

                                            // 1: UID associated with the output, rest same as above
TgVOID                                      tgCO_UID_Print( C_TgUINT32, C_TgUINT32, CP_TgCHAR );
TgVOID                                      tgCO_UID_PrintF( C_TgUINT32, C_TgUINT32, CP_TgCHAR, ... );

                                            // This will process input for the console display
                                            // 1: Character to be processed
                                            // 2: Ctrl State: true if ctrl is being held down
TgVOID                                      tgCO_Process_Input( TgCHAR, TgBOOL );

                                            // Functions used to manage the console commands supported by the module
TgBOOL                                      tgCO_Insert_Command( CPC_TgCHAR, TgFCN_CONSOLE );
TgBOOL                                      tgCO_Remove_Command( CPC_TgCHAR );
TgBOOL                                      tgCO_Execute_Command( CPC_TgCHAR );

#else // TgS_COMPILE_CONSOLE

    #define TgLOGF( ... )
    #define TgLOG( ... )
    #define TgLOGF_UID( ... )
    #define TgLOG_UID( ... )

#endif // TgS_COMPILE_CONSOLE

#endif //  END  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////