src/AwkHandler.h
branchv_0
changeset 3 e086ae6a19c3
parent 2 580ccb511301
child 4 050ec7c1f2e7
equal deleted inserted replaced
2:580ccb511301 3:e086ae6a19c3
   130 			if (writerPid < 0) {
   130 			if (writerPid < 0) {
   131 				throw cli::RelpipeCLIException(L"Unable to fork Writer process.", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exceptions?
   131 				throw cli::RelpipeCLIException(L"Unable to fork Writer process.", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exceptions?
   132 			} else if (writerPid == 0) {
   132 			} else if (writerPid == 0) {
   133 				// Writer child process
   133 				// Writer child process
   134 				closeOrThrow(awkInputWriterFD);
   134 				closeOrThrow(awkInputWriterFD);
   135 				fwprintf(stderr, L"I am child Writer with PID: %d\n", getpid());
   135 				fwprintf(stderr, L"I am child Writer with PID: %d Writer: %p\n", getpid(), relationalWriter);
   136 
   136 
   137 				__gnu_cxx::stdio_filebuf<char> awkOutputReaderBuffer(awkOutputReaderFD, std::ios::in);
   137 				__gnu_cxx::stdio_filebuf<wchar_t> awkOutputReaderBuffer(awkOutputReaderFD, std::ios::in);
   138 				std::istream awkOutputReader(&awkOutputReaderBuffer);
   138 				std::wistream awkOutputReader(&awkOutputReaderBuffer);
   139 
   139 
   140 				std::cout << "--- PIPE start --------" << std::endl;
   140 				relationalWriter->startRelation(L"writer_debug",{
   141 				for (char ch = awkOutputReader.get(); awkOutputReader.good(); ch = awkOutputReader.get()) {
   141 					{L"message", writer::TypeId::STRING},
   142 					std::cout << ch;
   142 				}, true);
       
   143 
       
   144 				for (wchar_t ch = awkOutputReader.get(); awkOutputReader.good(); ch = awkOutputReader.get()) {
       
   145 					relationalWriter->writeAttribute(string_t(1, ch));
   143 				}
   146 				}
   144 				std::cout << "--- PIPE end ----------" << std::endl;
       
   145 
   147 
   146 				closeOrThrow(awkOutputReaderFD);
   148 				closeOrThrow(awkOutputReaderFD);
   147 				exit(0);
   149 				exit(0);
   148 			} else {
   150 			} else {
   149 				// Parent process
   151 				// Parent process
   150 				closeOrThrow(awkOutputReaderFD);
   152 				closeOrThrow(awkOutputReaderFD);
   151 				fwprintf(stderr, L"Forked Writer has PID: %d\n", writerPid);
   153 				fwprintf(stderr, L"Forked Writer has PID: %d\n", writerPid);
   152 
       
   153 				dprintf(awkInputWriterFD, "hello world :-)\n");
       
   154 				//closeOrThrow(awkInputWriterFD);
       
   155 
       
   156 				/*
       
   157 				__gnu_cxx::stdio_filebuf<char> awkInputWriterBuffer(awkInputWriterFD, std::ios::out);
       
   158 				std::ostream awkInputWriter(&awkInputWriterBuffer);
       
   159 				awkInputWriter << "hello world :-)" << std::endl;
       
   160 				awkInputWriter.flush();
       
   161 				closeOrThrow(awkInputWriterFD);
       
   162 				 */
       
   163 
       
   164 			}
   154 			}
   165 		}
   155 		}
   166 
   156 
   167 	}
   157 	}
   168 
   158