| 1689 | } |
| 1690 | |
| 1691 | int Server::RemoveService(google::protobuf::Service* service) { |
| 1692 | if (NULL == service) { |
| 1693 | LOG(ERROR) << "Parameter[service] is NULL"; |
| 1694 | return -1; |
| 1695 | } |
| 1696 | if (status() != READY) { |
| 1697 | LOG(ERROR) << "Can't remove service=" |
| 1698 | << service->GetDescriptor()->full_name() << " from Server[" |
| 1699 | << version() << "] which is " << status_str(status()); |
| 1700 | return -1; |
| 1701 | } |
| 1702 | |
| 1703 | const google::protobuf::ServiceDescriptor* sd = service->GetDescriptor(); |
| 1704 | ServiceProperty* ss = _fullname_service_map.seek(butil::EnsureString(sd->full_name())); |
| 1705 | if (ss == NULL) { |
| 1706 | RPC_VLOG << "Fail to find service=" << sd->full_name(); |
| 1707 | return -1; |
| 1708 | } |
| 1709 | RemoveMethodsOf(service); |
| 1710 | if (ss->ownership == SERVER_OWNS_SERVICE) { |
| 1711 | delete ss->service; |
| 1712 | } |
| 1713 | const bool is_builtin_service = ss->is_builtin_service; |
| 1714 | _fullname_service_map.erase(sd->full_name()); |
| 1715 | _service_map.erase(sd->name()); |
| 1716 | |
| 1717 | // Note: ss is invalidated. |
| 1718 | if (is_builtin_service) { |
| 1719 | --_builtin_service_count; |
| 1720 | } else { |
| 1721 | if (_first_service == service) { |
| 1722 | _first_service = NULL; |
| 1723 | } |
| 1724 | } |
| 1725 | return 0; |
| 1726 | } |
| 1727 | |
| 1728 | void Server::ClearServices() { |
| 1729 | if (status() != READY) { |