main.cpp 715 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <QCoreApplication>
  2. #include "../DataWriteDog/writeshm.h"
  3. #include "writecore.h"
  4. DataWriteShm *dataWriteShm;
  5. bool shm_load()
  6. {
  7. key_t key;
  8. int shmid;
  9. if((key=ftok(IPC_PATH,static_cast<int>(IPC_PORT)))==-1){
  10. return false;
  11. }
  12. if((shmid=shmget(key,sizeof (DataWriteShm),IPC_CREAT|0666))==-1){
  13. return false;
  14. }
  15. dataWriteShm = static_cast<DataWriteShm *>(shmat(shmid,nullptr,0));
  16. return true;
  17. }
  18. int main(int argc, char *argv[])
  19. {
  20. QCoreApplication a(argc, argv);
  21. if(shm_load()){
  22. WriteCore *core = new WriteCore(nullptr);
  23. core->start();
  24. }else{
  25. fprintf(stderr,"write shm failed");
  26. exit(1);
  27. }
  28. return a.exec();
  29. }