2 * Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
7 #include "CliThreadCommand.h"
11 #include <AutoLocker.h>
13 #include "CliContext.h"
17 CliThreadCommand::CliThreadCommand()
19 CliCommand("set or print the current thread",
20 "%s [ <thread ID> ]\n"
21 "Sets the current thread to <thread ID>, if supplied. Otherwise prints "
29 CliThreadCommand::Execute(int argc
, const char* const* argv
,
38 // no arguments -- print the current thread
39 context
.PrintCurrentThread();
45 long threadID
= strtol(argv
[1], &endPointer
, 0);
46 if (*endPointer
!= '\0' || threadID
< 0) {
47 printf("Error: Invalid parameter \"%s\"\n", argv
[1]);
51 // get the thread and change the current thread
52 Team
* team
= context
.GetTeam();
53 AutoLocker
<Team
> teamLocker(team
);
54 if (Thread
* thread
= team
->ThreadByID(threadID
))
55 context
.SetCurrentThread(thread
);
57 printf("Error: No thread with ID %ld\n", threadID
);