| 165 | } |
| 166 | |
| 167 | int InputManager::GetTicks(const Json::Value& sequences, Json::Value* ticks) { |
| 168 | for (size_t i = 0; i < sequences.size(); ++i) { |
| 169 | Json::UInt index = static_cast<Json::UInt>(i); |
| 170 | Json::Value device_sequence = sequences[index]; |
| 171 | if (!device_sequence.isMember("type") && !device_sequence["type"].isString()) { |
| 172 | return EINVALIDARGUMENT; |
| 173 | } |
| 174 | |
| 175 | std::string device_type = device_sequence["type"].asString(); |
| 176 | if (device_type != "key" && device_type != "pointer" && device_type != "none") { |
| 177 | return EINVALIDARGUMENT; |
| 178 | } |
| 179 | |
| 180 | if (!device_sequence.isMember("id") && !device_sequence["id"].isString()) { |
| 181 | return EINVALIDARGUMENT; |
| 182 | } |
| 183 | |
| 184 | std::string device_id = device_sequence["id"].asString(); |
| 185 | |
| 186 | if (!device_sequence.isMember("actions") && !device_sequence["actions"].isArray()) { |
| 187 | return EINVALIDARGUMENT; |
| 188 | } |
| 189 | |
| 190 | // TODO: Add guards against bad action structure. Assume correct input for now. |
| 191 | Json::Value actions = device_sequence["actions"]; |
| 192 | for (size_t j = 0; j < actions.size(); ++j) { |
| 193 | if (ticks->size() <= j) { |
| 194 | Json::Value tick(Json::arrayValue); |
| 195 | ticks->append(tick); |
| 196 | } |
| 197 | Json::UInt action_index = static_cast<Json::UInt>(j); |
| 198 | Json::Value action = actions[action_index]; |
| 199 | if (action.isMember("type") && |
| 200 | action["type"].isString() && |
| 201 | action["type"].asString() == "pause") { |
| 202 | if (action.isMember("duration") && |
| 203 | (action["duration"].type() != Json::ValueType::intValue || |
| 204 | action["duration"].asInt() < 0)) { |
| 205 | return EINVALIDARGUMENT; |
| 206 | } |
| 207 | if (device_type == "key") { |
| 208 | // HACK! Ignore the duration of pause events in keyboard action |
| 209 | // sequences. This is deliberately in violation of the W3C spec. |
| 210 | // This allows us to better synchronize mixed keyboard and mouse |
| 211 | // action sequences. |
| 212 | action["duration"] = 10; |
| 213 | } |
| 214 | } |
| 215 | (*ticks)[action_index].append(action); |
| 216 | } |
| 217 | } |
| 218 | return WD_SUCCESS; |
| 219 | } |
| 220 | |
| 221 | HANDLE InputManager::AcquireMutex() { |
| 222 | HANDLE mutex_handle = ::CreateMutex(NULL, FALSE, USER_INTERACTION_MUTEX_NAME); |
no test coverage detected