~ubuntu-branches/ubuntu/maverick/codelite/maverick

« back to all changes in this revision

Viewing changes to sdk/codelite_indexer/workerthread.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-02-10 02:27:55 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090210022755-m5692nfc1t5uf1w9
Tags: 1.0.2759+dfsg-0ubuntu1
* New upstream release (LP: #327216).
* debian/patches/series, debian/patches/00_fix-ia64-build.patch:
  + Dropped, applied upstream already.
* debian/patches/02_fix-desktop.patch,
  debian/patches/03_fix-sh.patch:
  + Refreshed to patch cleanly.
* debian/rules:
  + Make get-orig-source honour UPSTREAM_VERSION if set.
* debian/ctags-le.1,
  debian/codelite_indexer.1,
  debian/codelite.manpages:
  + Dropped ctags-le manpage, since ctags-le was replaced by
    codelite_indexer.
  + Added codelite_indexer manpage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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"
 
9
#include "utils.h"
 
10
 
 
11
WorkerThread::WorkerThread(eQueue<clNamedPipe*> *queue)
 
12
                : m_queue(queue)
 
13
{
 
14
}
 
15
 
 
16
WorkerThread::~WorkerThread()
 
17
{
 
18
}
 
19
 
 
20
void WorkerThread::start()
 
21
{
 
22
        printf("INFO: WorkerThread: Started\n");
 
23
        while ( !testDestroy() ) {
 
24
                clNamedPipe *conn(NULL);
 
25
                if (!m_queue->get(conn, 100)) {
 
26
                        continue;
 
27
                }
 
28
 
 
29
                if (conn) {
 
30
                        // get request from the client
 
31
                        clIndexerRequest req;
 
32
                        if ( !clIndexerProtocol::ReadRequest(conn, req) ) {
 
33
                                continue;
 
34
                        }
 
35
 
 
36
                        char *tags(NULL);
 
37
                        // create fies for the requested files
 
38
                        for (size_t i=0; i<req.getFiles().size(); i++) {
 
39
 
 
40
#ifdef __DEBUG
 
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());
 
46
#endif
 
47
 
 
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);
 
54
                                        strcat(ptmp, tags);
 
55
                                        strcat(ptmp, "\n");
 
56
                                        strcat(ptmp, new_tags);
 
57
 
 
58
                                        ctags_free(new_tags);
 
59
                                        ctags_free(tags);
 
60
 
 
61
                                        tags = ptmp;
 
62
 
 
63
                                } else if(new_tags) {
 
64
                                        // first time
 
65
                                        tags = new_tags;
 
66
                                        new_tags = NULL;
 
67
                                }
 
68
                        }
 
69
 
 
70
                        // prepare the reply
 
71
#ifdef __DEBUG
 
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());
 
75
                        }
 
76
#endif
 
77
 
 
78
                        clIndexerReply reply;
 
79
                        if (tags) {
 
80
                                // prepare reply
 
81
                                reply.setCompletionCode(1);
 
82
                                reply.setTags(tags);
 
83
                        } else {
 
84
                                reply.setCompletionCode(0);
 
85
                        }
 
86
 
 
87
                        ctags_free(tags);
 
88
 
 
89
                        // send the reply
 
90
                        if ( !clIndexerProtocol::SendReply(conn, reply) ) {
 
91
                                fprintf(stderr, "ERROR: Protocol error: failed to send reply for file %s\n", reply.getFileName().c_str());
 
92
                                break;
 
93
                        }
 
94
                        delete conn;
 
95
 
 
96
                }
 
97
        }
 
98
        printf("INFO: WorkerThread: Going down\n");
 
99
}