1
#include "workerthread.h"
2
#include "network/named_pipe.h"
3
#include "network/named_pipe_client.h"
4
#include "network/cl_indexer_reply.h"
5
#include "network/cl_indexer_request.h"
6
#include "network/np_connections_server.h"
7
#include "network/clindexerprotocol.h"
8
#include "libctags/libctags.h"
11
WorkerThread::WorkerThread(eQueue<clNamedPipe*> *queue)
16
WorkerThread::~WorkerThread()
20
void WorkerThread::start()
22
printf("INFO: WorkerThread: Started\n");
23
while ( !testDestroy() ) {
24
clNamedPipe *conn(NULL);
25
if (!m_queue->get(conn, 100)) {
30
// get request from the client
32
if ( !clIndexerProtocol::ReadRequest(conn, req) ) {
37
// create fies for the requested files
38
for (size_t i=0; i<req.getFiles().size(); i++) {
41
printf("------------------------------------------------------------------\n");
42
printf("INFO: Source : %s\n", req.getFiles().at(i).c_str());
43
printf("INFO: Command : %d\n", req.getCmd());
44
printf("INFO: CTAGS options : %s\n", req.getCtagOptions().c_str());
45
printf("INFO: Database : %s\n", req.getDatabaseFileName().c_str());
48
char *new_tags = ctags_make_tags(req.getCtagOptions().c_str(), req.getFiles().at(i).c_str());
49
if (tags && new_tags) {
50
// re-allocate the buffer to containt the new tags + 2 chars: 1 for terminating null and one for the '\n'
51
// that will be appended
52
char *ptmp = (char*)malloc(strlen(tags) + strlen(new_tags) + 2);
53
memset(ptmp, 0, strlen(tags) + strlen(new_tags) + 2);
56
strcat(ptmp, new_tags);
72
std::vector<std::string> lines = string_tokenize(tags, "\n");
73
for(size_t i=0; i<lines.size(); i++){
74
printf("%s\n", lines.at(i).c_str());
81
reply.setCompletionCode(1);
84
reply.setCompletionCode(0);
90
if ( !clIndexerProtocol::SendReply(conn, reply) ) {
91
fprintf(stderr, "ERROR: Protocol error: failed to send reply for file %s\n", reply.getFileName().c_str());
98
printf("INFO: WorkerThread: Going down\n");