#include <stdio.h>

#define MXM_APM2

#include "appLauncher.h"
#include "callbacks/callbacks.h"
#include "config.h"
#include "lib/am/amDongle.h"
#include "lib/libpcp/libpcp.h"
#include "mxmEventLog.h"

typedef struct MX_MASTER_ {
    ushort m_controlPort;
    ushort m_dataPort;
    int m_openMode;

    bool m_processStateChange;
    bool m_changeIsSpawn;
    bool m_backupMetadataChanged;

    unsigned int m_current;
    unsigned int m_next;
    bool m_develop;
    bool m_fault;

    bool m_loggingAvailable;
    unsigned int m_backupCount;
    unsigned int m_clearCount;
    unsigned int m_interval;
    char m_nextPath[128];
    char m_gameId[8];
    char m_platformId[8];
    char m_message[256];
    char m_keychipId[32];
    IN_ADDR m_networkAddr;
    int m_countSystemBoot;
    int m_countGameBoot;
    int m_countSystemTest;
    int m_countGameTest;
    unsigned char m_binaryMessage[512];
    size_t m_binaryMessageLen;
    bool m_serverOpen;
    bool m_kcReady;
    bool m_pcpaHasInit;
    appLauncher_t* m_appLauncher;
    pcpa_cb_table_t m_pcpCallbacks[MXM_NUM_CALLBACKS];
    pcpa_t m_pcp;

} MX_MASTER;

void mxmBeforeBinaryCallback(pcpa_t* stream, MX_MASTER* mxMaster);
void mxmAfterBinaryCallback(pcpa_t* stream, MX_MASTER* mxMaster);
void mxmCopySystemFile(char* filename);
int mxmBackupEventlog(int destination);
#ifdef MXM_APM2
void mxmCopySystemFirmwareFile(char* filename);
appLauncherLaunch_t apmsTranslateNext(appLauncherLaunch_t which);
#endif
