| 1353 | } |
| 1354 | |
| 1355 | int Server::AddServiceInternal(google::protobuf::Service* service, |
| 1356 | bool is_builtin_service, |
| 1357 | const ServiceOptions& svc_opt) { |
| 1358 | if (NULL == service) { |
| 1359 | LOG(ERROR) << "Parameter[service] is NULL!"; |
| 1360 | return -1; |
| 1361 | } |
| 1362 | const google::protobuf::ServiceDescriptor* sd = service->GetDescriptor(); |
| 1363 | if (sd->method_count() == 0) { |
| 1364 | LOG(ERROR) << "service=" << sd->full_name() |
| 1365 | << " does not have any method."; |
| 1366 | return -1; |
| 1367 | } |
| 1368 | |
| 1369 | if (InitializeOnce() != 0) { |
| 1370 | LOG(ERROR) << "Fail to initialize Server[" << version() << ']'; |
| 1371 | return -1; |
| 1372 | } |
| 1373 | if (status() != READY) { |
| 1374 | LOG(ERROR) << "Can't add service=" << sd->full_name() << " to Server[" |
| 1375 | << version() << "] which is " << status_str(status()); |
| 1376 | return -1; |
| 1377 | } |
| 1378 | |
| 1379 | if (_fullname_service_map.seek(sd->full_name()) != NULL) { |
| 1380 | LOG(ERROR) << "service=" << sd->full_name() << " already exists"; |
| 1381 | return -1; |
| 1382 | } |
| 1383 | ServiceProperty* old_ss = _service_map.seek(sd->name()); |
| 1384 | if (old_ss != NULL) { |
| 1385 | // names conflict. |
| 1386 | LOG(ERROR) << "Conflict service name between " |
| 1387 | << sd->full_name() << " and " |
| 1388 | << old_ss->service_name(); |
| 1389 | return -1; |
| 1390 | } |
| 1391 | |
| 1392 | // defined `option (idl_support) = true' or not. |
| 1393 | const bool is_idl_support = sd->file()->options().GetExtension(idl_support); |
| 1394 | |
| 1395 | Tabbed* tabbed = dynamic_cast<Tabbed*>(service); |
| 1396 | for (int i = 0; i < sd->method_count(); ++i) { |
| 1397 | const google::protobuf::MethodDescriptor* md = sd->method(i); |
| 1398 | MethodProperty mp; |
| 1399 | mp.is_builtin_service = is_builtin_service; |
| 1400 | mp.own_method_status = true; |
| 1401 | mp.params.is_tabbed = !!tabbed; |
| 1402 | mp.params.allow_default_url = svc_opt.allow_default_url; |
| 1403 | mp.params.allow_http_body_to_pb = svc_opt.allow_http_body_to_pb; |
| 1404 | mp.params.pb_bytes_to_base64 = svc_opt.pb_bytes_to_base64; |
| 1405 | mp.params.pb_single_repeated_to_array = svc_opt.pb_single_repeated_to_array; |
| 1406 | mp.params.enable_progressive_read = svc_opt.enable_progressive_read; |
| 1407 | if (mp.params.enable_progressive_read) { |
| 1408 | _has_progressive_read_method = true; |
| 1409 | } |
| 1410 | mp.service = service; |
| 1411 | mp.method = md; |
| 1412 | mp.status = new MethodStatus; |