#ifndef _CDR_H
#define _CDR_H

#include <stdio.h>
#include <stdlib.h>

#define    CDR_SHM_KEY        0x60000006 
#define    CDR_SHM_PERM       0777
#define    CDR_SEM_KEY        0x60000007  
#define    CDR_SEM_PERM       0777

#define MAX_CDR_RECORDS    8192
#define CDR_RECORD_SIZE    256

#define MAX_CDR_PER_CYCLE  256
#define MAX_CDR_APP_NUM    4

typedef struct cdr_record
{
    char ssn;
    unsigned short length;
    char data[CDR_RECORD_SIZE];
}_cdr_record;

typedef struct cdr_vm_struct
{
    char plane_id; /* 0/1=mss0,mss1*/
    unsigned short head_ptr;
    unsigned short tail_ptr;
    _cdr_record cdr_data[MAX_CDR_RECORDS];
}_cdr_vm_struct;

typedef struct cdr_ssn_param
{
    unsigned char ssn;
    char name[32];
    char file_name[128];
    int  total_records;
    int  file_sn;
    FILE *fd;
}_cdr_ssn_param;

typedef struct cdr_param
{
    char system_id;
    char base_dir[128];
    char file_suffix[32];
    int  max_records_per_file;
    char max_days;
    char init_flag;
    char now_time[8]; 
    _cdr_ssn_param ssn_param[MAX_CDR_APP_NUM];
}_cdr_param;

int cdr_init(char plane_id, char memset_flag);
int cdr_timer();

int cdr_bakcup();

#endif
