main.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <QCoreApplication>
  2. #include "dogcore.h"
  3. #include "datacollector.h"
  4. DataCollectorShm *dataColShm;
  5. SmokerDeviceSensorList *smokerDeviceList;
  6. bool load_shm()
  7. {
  8. key_t key;
  9. int shmid;
  10. if((key = ftok(SHM_PATH,static_cast<int>(SHM_PORT))) == -1){
  11. return false;
  12. }
  13. if((shmid = shmget(key,sizeof(DataCollectorShm),IPC_CREAT|0666))==-1){
  14. return false;
  15. }
  16. printf("shmid1: %d\n",shmid);
  17. dataColShm = static_cast<DataCollectorShm *>(shmat(shmid,nullptr,0));
  18. if((key = ftok(SHM_DEVPATH,static_cast<int>(SHM_DEVPORT))) == -1){
  19. return false;
  20. }
  21. printf("shmid11: %d\n",shmid);
  22. if((shmid = shmget(key,sizeof(SmokerDeviceSensorList),IPC_CREAT|0666))==-1){
  23. return false;
  24. }
  25. printf("shmid2: %d\n",shmid);
  26. smokerDeviceList = static_cast<SmokerDeviceSensorList *>(shmat(shmid,nullptr,0));
  27. return true;
  28. }
  29. int main(int argc, char *argv[])
  30. {
  31. QCoreApplication a(argc, argv);
  32. if(load_shm()){
  33. DogCore *dogcore = new DogCore(nullptr);
  34. dogcore->start();
  35. }else{
  36. exit(1);
  37. }
  38. return a.exec();
  39. }