#include <QCoreApplication>
#include "boxshm.h"
#include "dogcore.h"
#include <QFile>
#include <QDir>

AGBoxShm *agBoxShm;

bool shm_load(){
    int shmid;
    key_t key;
    if((key=ftok(SHM_PATH,static_cast<int>(SHM_PORT)))==-1){
        return false;
    }
    if((shmid=shmget(key,sizeof (AGBoxShm),IPC_CREAT|0666))==-1){
        return false;
    }
    agBoxShm = static_cast<AGBoxShm *>(shmat(shmid,nullptr,0));

    return true;
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QDir path("/opt/agBoxProcess");
    if(!path.exists()){
        system("mkdir -p /opt/agBoxProcess");
        system("mkdir -p /opt/agBoxProcess/log");
    }
    if(shm_load()){
        DogCore *dogcore = new DogCore(nullptr);
        dogcore->start();
    }else{
        fprintf(stderr,"shm load failed!\n");
        exit(1);
    }


    return a.exec();
}
