#include "cca.h"
#include "NonlinearFunction_CCA.h"
#include "macros_CCA.h"

namespace functions
{
  namespace ccaimpl
  {

    /** 
     * Default constructor
     */
    NonlinearFunction::NonlinearFunction ()
    {
      frameworkServices = 0;
    }

    NonlinearFunction::~NonlinearFunction ()
    {
    }

    /**
     * A simple nonlinear function.
     */
    double NonlinearFunction::evaluate (double x)
    {
      return x * x;
    }

    /**
     * The framework passes a pointer to the Services object
     * via this method, which is called by the framework as soon
     * as the component is instantiated.
     */
    void NonlinearFunction::setServices (gov::cca::Services * services)
    {
      if (services != 0)
        {
          frameworkServices = services;

          // Provide a Function port
          gov::cca::PortInfo * portInfo =
            frameworkServices->createPortInfo ("FunctionPort",
                                               "functions.ccaports.Function",
                                               0);
          if (portInfo != 0)
            frameworkServices->addProvidesPort (this, portInfo);
        }
      else
        {
          // Close down if not closed already
          if (frameworkServices != 0)
            frameworkServices->removeProvidesPort ("FunctionPort");
          frameworkServices = 0;
        }
    }

  }
}