Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

rpcserver: introduce general request scheme

format is "cmd|arg0|arg1|..."
currently known commands: update, terminate

Changeset 4426aee7e00d

Parent c2d6a90e94e4

by Adrian Buehlmann

Changes to 2 files · Browse files at 4426aee7e00d Showing diff from parent c2d6a90e94e4 Diff from another changeset...

 
58
59
60
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
63
64
65
66
67
68
69
70
 
 
 
 
 
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
 
87
88
89
90
91
92
93
 
103
104
105
106
 
107
108
 
109
110
111
 
58
59
60
 
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
 
88
 
 
 
 
89
90
91
92
93
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
96
97
98
 
99
100
101
 
111
112
113
 
114
115
 
116
117
118
119
@@ -58,36 +58,44 @@
  logmsg('Shell notified')    requests = Queue.Queue(0) -_abort_request = r';:;:; Quit ;:;:;' # any invalid path would do + +def update(args): + batch = [] + r = args[0] + print "got update request %s (first in batch)" % r + batch.append(r) + print "wait a bit for additional requests..." + time.sleep(0.2) + try: + while True: + r = requests.get_nowait() + print "got update request %s" % r + batch.append(r) + except Queue.Empty: + pass + msg = "processing batch with %i update requests" + print msg % len(batch) + update_batch(batch) + +def dispatch(req, cmd, args): + if cmd == 'update': + update(args) + else: + logmsg("Error: unknown request '%s'" % req)    class Updater(threading.Thread):   def run(self): - n = 0   while True: - batch = [] - r = requests.get() - if r == _abort_request: - logmsg('Updater thread quiting') + req = requests.get() + s = req.split('|') + cmd, args = s[0], s[1:] + if cmd is 'terminate': + logmsg('Updater thread terminating')   return - print "got request %s (first in batch)" % r - batch.append(r) - print "wait a bit for additional requests..." - time.sleep(0.2) - try: - while True: - r = requests.get_nowait() - print "got request %s" % r - batch.append(r) - except Queue.Empty: - pass - n += 1 - msg = "--- processing batch %i with %i requests ---" - print msg % (n, len(batch)) - update_batch(batch) + dispatch(req, cmd, args)    Updater().start()   -  class PipeServer:   def __init__(self):   # Create an event which we will use to wait on. @@ -103,9 +111,9 @@
  self.overlapped.hEvent = win32event.CreateEvent(None,0,0,None)     def SvcStop(self): - print 'PipeServer thread quiting' + print 'PipeServer thread terminating'   win32event.SetEvent(self.hWaitStop) - requests.put(_abort_request) + requests.put('terminate')     def SvcDoRun(self):   # We create our named pipe.
 
42
43
44
 
 
45
46
 
47
48
49
 
50
51
52
 
42
43
44
45
46
47
 
48
49
50
 
51
52
53
54
@@ -42,11 +42,13 @@
    BOOL fSuccess;   DWORD cbRead; + + const std::string request = "update|" + path;   - TDEBUG_TRACE("Thgstatus::update(" << path << ") for " << pname); + TDEBUG_TRACE("Thgstatus::update: sending '" << request << "' to " << pname);     fSuccess = ::CallNamedPipeA( - pname.c_str(), (void*)path.c_str(), path.size(), 0, 0, &cbRead, + pname.c_str(), (void*)request.c_str(), request.size(), 0, 0, &cbRead,   200 /* ms */   );