| 130 | } |
| 131 | |
| 132 | inline engine_config_ptr argumentsToEngineConfig(const Napi::CallbackInfo &args) |
| 133 | { |
| 134 | Napi::HandleScope scope(args.Env()); |
| 135 | auto engine_config = std::make_unique<osrm::EngineConfig>(); |
| 136 | |
| 137 | if (args.Length() == 0) |
| 138 | { |
| 139 | return engine_config; |
| 140 | } |
| 141 | else if (args.Length() > 1) |
| 142 | { |
| 143 | ThrowError(args.Env(), "Only accepts one parameter"); |
| 144 | return engine_config_ptr(); |
| 145 | } |
| 146 | |
| 147 | BOOST_ASSERT(args.Length() == 1); |
| 148 | |
| 149 | if (args[0].IsString()) |
| 150 | { |
| 151 | engine_config->storage_config = osrm::StorageConfig(args[0].ToString().Utf8Value()); |
| 152 | engine_config->use_shared_memory = false; |
| 153 | return engine_config; |
| 154 | } |
| 155 | else if (!args[0].IsObject()) |
| 156 | { |
| 157 | ThrowError(args.Env(), "Parameter must be a path or options object"); |
| 158 | return engine_config_ptr(); |
| 159 | } |
| 160 | |
| 161 | BOOST_ASSERT(args[0].IsObject()); |
| 162 | auto params = args[0].As<Napi::Object>(); |
| 163 | |
| 164 | auto path = params.Get("path"); |
| 165 | if (path.IsEmpty()) |
| 166 | return engine_config_ptr(); |
| 167 | |
| 168 | auto memory_file = params.Get("memory_file"); |
| 169 | if (memory_file.IsEmpty()) |
| 170 | return engine_config_ptr(); |
| 171 | |
| 172 | auto shared_memory = params.Get("shared_memory"); |
| 173 | if (shared_memory.IsEmpty()) |
| 174 | return engine_config_ptr(); |
| 175 | |
| 176 | auto mmap_memory = params.Get("mmap_memory"); |
| 177 | if (mmap_memory.IsEmpty()) |
| 178 | return engine_config_ptr(); |
| 179 | |
| 180 | if (!memory_file.IsUndefined()) |
| 181 | { |
| 182 | if (path.IsUndefined()) |
| 183 | { |
| 184 | ThrowError(args.Env(), "memory_file option requires a path to a file."); |
| 185 | return engine_config_ptr(); |
| 186 | } |
| 187 | |
| 188 | engine_config->memory_file = memory_file.ToString().Utf8Value(); |
| 189 | } |
no test coverage detected