main.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <QCoreApplication>
  2. #include "ytservicecore.h"
  3. #include "core.h"
  4. YT_SERVICE_SHM *ytShm;
  5. WebDataShm *webData;
  6. UserInfoShm *userinfoShm;
  7. bool load_shm(){
  8. int shmid;
  9. key_t key;
  10. if((key = ftok(SHM_PATH,static_cast<int>(SHM_PORT)))==-1)
  11. return false;
  12. if((shmid = shmget(key,sizeof(YT_SERVICE_SHM),IPC_CREAT|0666))==-1)
  13. return false;
  14. ytShm = static_cast<YT_SERVICE_SHM *>(shmat(shmid,nullptr,0));
  15. if((key = ftok(UISHM_PATH,static_cast<int>(UISHM_PORT)))==-1)
  16. return false;
  17. if((shmid = shmget(key,sizeof(UserInfoShm),IPC_CREAT|0666))==-1)
  18. return false;
  19. userinfoShm = static_cast<UserInfoShm *>(shmat(shmid,nullptr,0));
  20. if((key = ftok(WEB_SHM_PATH,static_cast<int>(WEB_SHM_PORT)))==-1)
  21. return false;
  22. if((shmid = shmget(key,sizeof(WebDataShm),IPC_CREAT|0666))==-1)
  23. return false;
  24. webData = static_cast<WebDataShm *>(shmat(shmid,nullptr,0));
  25. return true;
  26. }
  27. int main(int argc, char *argv[])
  28. {
  29. QCoreApplication a(argc, argv);
  30. if(load_shm()){
  31. Core *c = new Core(nullptr);
  32. c->start();
  33. }
  34. return a.exec();
  35. }