From 6d17ef493bbec78ebda37e50e0cc8ce21fd9f46b Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 5 May 2015 17:41:10 -0700 Subject: 1266 - 'start-running' returns a unique routine id --- cpp/038scheduler.cc | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'cpp/038scheduler.cc') diff --git a/cpp/038scheduler.cc b/cpp/038scheduler.cc index f750e4a3..dbefe556 100644 --- a/cpp/038scheduler.cc +++ b/cpp/038scheduler.cc @@ -90,6 +90,20 @@ for (index_t i = 0; i < Routines.size(); ++i) delete Routines[i]; Routines.clear(); +//:: To schedule new routines to run, call 'start-scheduling'. + +//: 'start-scheduling' will return a unique id for the routine that was +//: created. +:(before "End routine Fields") +index_t id; +:(before "End Globals") +index_t Next_routine_id = 1; +:(before "End Setup") +Next_routine_id = 1; +:(before "End routine Constructor") +id = Next_routine_id; +Next_routine_id++; + :(before "End Primitive Recipe Declarations") START_RUNNING, :(before "End Primitive Recipe Numbers") @@ -98,7 +112,13 @@ Recipe_number["start-running"] = START_RUNNING; case START_RUNNING: { trace("run") << "ingredient 0 is " << current_instruction().ingredients[0].name; assert(!current_instruction().ingredients[0].initialized); - Routines.push_back(new routine(Recipe_number[current_instruction().ingredients[0].name])); + routine* new_routine = new routine(Recipe_number[current_instruction().ingredients[0].name]); + Routines.push_back(new_routine); + if (!current_instruction().products.empty()) { + vector result; + result.push_back(new_routine->id); + write_memory(current_instruction().products[0], result); + } break; } @@ -135,6 +155,16 @@ recipe f2 [ +schedule: f1 +run: instruction f1/2 +:(scenario start_running_returns_routine_id) +% Scheduling_interval = 1; +recipe f1 [ + 1:integer <- start-running f2:recipe +] +recipe f2 [ + 12:integer <- copy 44:literal +] ++mem: storing 2 in location 1 + :(scenario scheduler_skips_completed_routines) # this scenario will require some careful setup in escaped C++ # (straining our tangle capabilities to near-breaking point) -- cgit 1.4.1-2-gfad0 alue='author'>author
blob: 0c4e1ffaa7b5349698767666ceae6ed004bf15eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>

#include "config/preferences.h"

#include "ui/ui.h"
#include "ui/stub_ui.h"

#include "command/cmd_funcs.h"

#define CMD_PRESENCE "/presence"

void
cmd_presence_shows_usage_when_bad_subcmd(void** state)
{
    gchar* args[] = { "badcmd", NULL };

    expect_string(cons_bad_cmd_usage, cmd, CMD_PRESENCE);

    gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
    assert_true(result);
}

void
cmd_presence_shows_usage_when_bad_console_setting(void** state)
{
    gchar* args[] = { "console", "badsetting", NULL };

    expect_string(cons_bad_cmd_usage, cmd, CMD_PRESENCE);

    gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
    assert_true(result);
}

void
cmd_presence_shows_usage_when_bad_chat_setting(void** state)
{
    gchar* args[] = { "chat", "badsetting", NULL };

    expect_string(cons_bad_cmd_usage, cmd, CMD_PRESENCE);

    gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
    assert_true(result);
}

void
cmd_presence_shows_usage_when_bad_muc_setting(void** state)
{
    gchar* args[] = { "muc", "badsetting", NULL };

    expect_string(cons_bad_cmd_usage, cmd, CMD_PRESENCE);

    gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
    assert_true(result);
}

void
cmd_presence_console_sets_all(void** state)
{
    gchar* args[] = { "console", "all", NULL };

    expect_cons_show("All presence updates will appear in the console.");

    gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);

    char* setting = prefs_get_string(PREF_STATUSES_CONSOLE);
    assert_non_null(setting);
    assert_string_equal("all", setting);
    assert_true(result);
    g_free(setting);
}

void
cmd_presence_console_sets_online(void** state)
{
    gchar* args[] = { "console", "online", NULL };

    expect_cons_show("Only online/offline presence updates will appear in the console.");

    gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);

    char* setting = prefs_get_string(PREF_STATUSES_CONSOLE);
    assert_non_null(setting);
    assert_string_equal("online", setting);
    assert_true(result);
    g_free(setting);
}

void
cmd_presence_console_sets_none(void** state)
{
    gchar* args[] = { "console", "none", NULL };

    expect_cons_show("Presence updates will not appear in the console.");

    gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);

    char* setting = prefs_get_string(PREF_STATUSES_CONSOLE);
    assert_non_null(setting);
    assert_string_equal("none", setting);
    assert_true(result);
    g_free(setting);
}

void
cmd_presence_chat_sets_all(void** state)
{
    gchar* args[] = { "chat", "all", NULL };

    expect_cons_show("All presence updates will appear in chat windows.");

    gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);

    char* setting = prefs_get_string(PREF_STATUSES_CHAT);
    assert_non_null(setting);
    assert_string_equal("all", setting);
    assert_true(result);
    g_free(setting);
}

void
cmd_presence_chat_sets_online(void** state)
{
    gchar* args[] = { "chat", "online", NULL };

    expect_cons_show("Only online/offline presence updates will appear in chat windows.");

    gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);

    char* setting = prefs_get_string(PREF_STATUSES_CHAT);
    assert_non_null(setting);
    assert_string_equal("online", setting);
    assert_true(result);
    g_free(setting);
}

void
cmd_presence_chat_sets_none(void** state)
{
    gchar* args[] = { "chat", "none", NULL };

    expect_cons_show("Presence updates will not appear in chat windows.");

    gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);

    char* setting = prefs_get_string(PREF_STATUSES_CHAT);
    assert_non_null(setting);
    assert_string_equal("none", setting);
    assert_true(result);
    g_free(setting);
}

void
cmd_presence_room_sets_all(void** state)
{
    gchar* args[] = { "room", "all", NULL };

    expect_cons_show("All presence updates will appear in chat room windows.");

    gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);

    char* setting = prefs_get_string(PREF_STATUSES_MUC);
    assert_non_null(setting);
    assert_string_equal("all", setting);
    assert_true(result);
    g_free(setting);
}

void
cmd_presence_room_sets_online(void** state)
{
    gchar* args[] = { "room", "online", NULL };

    expect_cons_show("Only join/leave presence updates will appear in chat room windows.");

    gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);

    char* setting = prefs_get_string(PREF_STATUSES_MUC);
    assert_non_null(setting);
    assert_string_equal("online", setting);
    assert_true(result);
    g_free(setting);
}

void
cmd_presence_room_sets_none(void** state)
{
    gchar* args[] = { "room", "none", NULL };

    expect_cons_show("Presence updates will not appear in chat room windows.");

    gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);

    char* setting = prefs_get_string(PREF_STATUSES_MUC);
    assert_non_null(setting);
    assert_string_equal("none", setting);
    assert_true(result);
    g_free(setting);
}