added ipc
This commit is contained in:
		| @ -18,6 +18,9 @@ | ||||
| #include <curses.h> | ||||
| #include <thread>  | ||||
| #include <unistd.h> | ||||
| #include <mutex> | ||||
| #include <sys/select.h> | ||||
|  | ||||
|  | ||||
| using namespace std; | ||||
|  | ||||
| @ -32,6 +35,8 @@ template <typename T, typename I> T* iterator_to_pointer(I i) | ||||
|     return (&(*i)); | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| class reHDD | ||||
| { | ||||
| protected: | ||||
| @ -44,13 +49,21 @@ private: | ||||
|  | ||||
|     vector <Drive> vecDrives; //stores all drive data | ||||
|  | ||||
|     void searchDrives(vector <Drive>* pvecDrives); | ||||
|    static void searchDrives(vector <Drive>* pvecDrives); | ||||
|  | ||||
|     static void printDrives(vector <Drive>* pvecDrives); | ||||
|  | ||||
|  | ||||
|   static  void filterIgnoredDrives(vector <Drive>* pvecDrives); | ||||
|  | ||||
|  | ||||
|     static void addSMARTData(vector <Drive>* pvecDrives); | ||||
|  | ||||
|     static void ThreadScannDevices(); | ||||
|  | ||||
|  | ||||
|  | ||||
|     void printDrives(vector <Drive>* pvecDrives); | ||||
|     void filterIgnoredDrives(vector <Drive>* pvecDrives); | ||||
|     void addSMARTData(vector <Drive>* pvecDrives); | ||||
|  | ||||
|     static void ThreadDevices(); | ||||
|  | ||||
|  | ||||
|     | ||||
|  | ||||
| @ -8,7 +8,16 @@ | ||||
| #include "../include/reHDD.h" | ||||
|  | ||||
|  | ||||
| static int fd[2];//File descriptor for creating a pipe | ||||
| static int fdSearchDrives[2];//File descriptor for pipe that informs if new drives are found | ||||
|  | ||||
| static int fdUserInput[2];//File descriptor for pipe that informs if a user input occoures | ||||
|  | ||||
| static std::mutex mxScannDrives; | ||||
|  | ||||
| static vector <Drive> vecNewDrives; //store found drives that are updated every 5sec | ||||
|  | ||||
|  | ||||
| static fd_set selectSet; | ||||
|  | ||||
| /** | ||||
|  * \brief   app constructor | ||||
| @ -29,23 +38,28 @@ void reHDD::app_logic(void) | ||||
| { | ||||
|     cout << "app logic" << endl; | ||||
|  | ||||
|     thread thDevices(ThreadDevices); | ||||
|  | ||||
|  int  result = pipe(fdSearchDrives); | ||||
|  | ||||
|     //searchDrives(&vecDrives);           //search for new drives and store them in list | ||||
|     //filterIgnoredDrives(&vecDrives);    //filter out ignored drives | ||||
|     //addSMARTData(&vecDrives);           //add S.M.A.R.T. Data to the drives | ||||
|   //  printDrives(&vecDrives);            //print currently attached drives | ||||
|     FD_ZERO(&selectSet); | ||||
|     FD_SET(fdSearchDrives[0], &selectSet); | ||||
|  | ||||
|     thread thDevices(ThreadScannDevices); | ||||
|  | ||||
|  | ||||
|    int  result = pipe (fd); | ||||
|     | ||||
|  | ||||
| while(1){ | ||||
|  | ||||
|  int iSelectReturn =    select(FD_SETSIZE, &selectSet, NULL, NULL, NULL); | ||||
|  | ||||
|  | ||||
|  if( FD_ISSET(fdSearchDrives[0], &selectSet)) { | ||||
|  | ||||
|  | ||||
|       char    ch; | ||||
|     | ||||
|  | ||||
|       result = read (fd[0],&ch,1); | ||||
|       result = read (fdSearchDrives[0],&ch,1); | ||||
|     | ||||
|           if (result != 1) { | ||||
|         perror("read"); | ||||
| @ -54,6 +68,17 @@ while(1){ | ||||
|  | ||||
|       printf ("From Main Thread: %c\n", ch);  | ||||
|        | ||||
|       mxScannDrives.lock(); | ||||
|       printDrives(&vecNewDrives); | ||||
|       //replace with old list | ||||
|       // action if needed | ||||
|       mxScannDrives.unlock(); | ||||
|  | ||||
|  } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|        | ||||
|         } | ||||
|  | ||||
| @ -62,8 +87,6 @@ while(1){ | ||||
|  | ||||
|     thDevices.join(); | ||||
|  | ||||
|     std::cout << std::endl; | ||||
|  | ||||
| /* | ||||
|  | ||||
|  | ||||
| @ -81,7 +104,7 @@ while(1){ | ||||
| */ | ||||
| } | ||||
|  | ||||
| void reHDD::ThreadDevices(){ | ||||
| void reHDD::ThreadScannDevices(){ | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -90,19 +113,22 @@ while(true){ | ||||
| cout << "Thread" << endl; | ||||
|  | ||||
|  | ||||
|   mxScannDrives.lock(); | ||||
|   vecNewDrives.clear(); | ||||
|  | ||||
|  | ||||
|     searchDrives(&vecNewDrives);           //search for new drives and store them in list | ||||
|     filterIgnoredDrives(&vecNewDrives);    //filter out ignored drives | ||||
|     addSMARTData(&vecNewDrives);           //add S.M.A.R.T. Data to the drives | ||||
|      | ||||
|  mxScannDrives.unlock(); | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|      int  result = write (fd[1], "A",1); | ||||
|      int  result = write (fdSearchDrives[1], "A",1); | ||||
|      //cout << result << endl; | ||||
|        if (result != 1){ | ||||
|            perror ("write error"); | ||||
|  | ||||
| @ -13,7 +13,54 @@ | ||||
| 			"string_view": "cpp", | ||||
| 			"ostream": "cpp", | ||||
| 			"chrono": "cpp", | ||||
| 			"thread": "cpp" | ||||
| 			"thread": "cpp", | ||||
| 			"deque": "cpp", | ||||
| 			"vector": "cpp", | ||||
| 			"cctype": "cpp", | ||||
| 			"clocale": "cpp", | ||||
| 			"cmath": "cpp", | ||||
| 			"cstdarg": "cpp", | ||||
| 			"cstddef": "cpp", | ||||
| 			"cstdio": "cpp", | ||||
| 			"cstdlib": "cpp", | ||||
| 			"cstring": "cpp", | ||||
| 			"ctime": "cpp", | ||||
| 			"cwchar": "cpp", | ||||
| 			"cwctype": "cpp", | ||||
| 			"array": "cpp", | ||||
| 			"atomic": "cpp", | ||||
| 			"bit": "cpp", | ||||
| 			"compare": "cpp", | ||||
| 			"concepts": "cpp", | ||||
| 			"condition_variable": "cpp", | ||||
| 			"cstdint": "cpp", | ||||
| 			"exception": "cpp", | ||||
| 			"algorithm": "cpp", | ||||
| 			"functional": "cpp", | ||||
| 			"iterator": "cpp", | ||||
| 			"memory": "cpp", | ||||
| 			"memory_resource": "cpp", | ||||
| 			"numeric": "cpp", | ||||
| 			"optional": "cpp", | ||||
| 			"random": "cpp", | ||||
| 			"ratio": "cpp", | ||||
| 			"system_error": "cpp", | ||||
| 			"tuple": "cpp", | ||||
| 			"type_traits": "cpp", | ||||
| 			"utility": "cpp", | ||||
| 			"fstream": "cpp", | ||||
| 			"initializer_list": "cpp", | ||||
| 			"iosfwd": "cpp", | ||||
| 			"istream": "cpp", | ||||
| 			"limits": "cpp", | ||||
| 			"mutex": "cpp", | ||||
| 			"new": "cpp", | ||||
| 			"ranges": "cpp", | ||||
| 			"sstream": "cpp", | ||||
| 			"stdexcept": "cpp", | ||||
| 			"stop_token": "cpp", | ||||
| 			"streambuf": "cpp", | ||||
| 			"typeinfo": "cpp" | ||||
| 		}, | ||||
| 		"git.ignoreLimitWarning": true | ||||
| 	} | ||||
|  | ||||
		Reference in New Issue
	
	Block a user