#!/usr/bin/env python2.7
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#




"""Stubs for System service."""






from google.appengine.api import apiproxy_stub
from google.appengine.api.system import system_service_pb

class SystemServiceStub(apiproxy_stub.APIProxyStub):
  """Python stub for System service.

  This stub is very simple at the moment; it only returns fixed values.

  It also provides a place for the dev_appserver to record backend info.
  """

  def __init__(self, default_cpu=None, default_memory=None):
    """Constructor.

    Args:
      default_cpu: SystemStat; if set, value will be used for GetSystemStats.
      default_memory: SystemStat; if set, value will be used for GetSystemStats.
    """
    super(SystemServiceStub, self).__init__('system')
    self.default_cpu = default_cpu
    self.default_memory = default_memory


    self.num_calls = {}


    self._backend_info = None


  def _Dynamic_GetSystemStats(self, unused_request, response):
    """Mock version of System stats always returns fixed values."""

    cpu = response.mutable_cpu()
    if self.default_cpu:
      cpu.CopyFrom(self.default_cpu)

    memory = response.mutable_memory()
    if self.default_memory:
      memory.CopyFrom(self.default_memory)

    self.num_calls["GetSystemStats"] = (
        self.num_calls.get("GetSystemStats", 0) + 1)

  def _Dynamic_StartBackgroundRequest(self, unused_request, unused_response):
    """Not implemented."""
    self.num_calls["StartBackgroundRequest"] = (
        self.num_calls.get("StartBackgroundRequest", 0)  + 1)
    raise NotImplementedError

  def set_backend_info(self, backend_info):
    """Set backend info. Typically a list of BackendEntry objects."""
    self._backend_info = backend_info

  def get_backend_info(self):
    """Set backend info. Typically a list of BackendEntry objects."""
    return self._backend_info
