#include "cca.h"
#include "LinearFunction_CCA.h"

#include "macros_CCA.h"

namespace functions
{
  namespace ccaimpl
  {

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

    LinearFunction::~LinearFunction ()
    {
    }

    /**
     * A simple linear function.
     */

    double LinearFunction::evaluate (double x)
    {
      return 2 * 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 LinearFunction::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)
            frameworkServices->removeProvidesPort ("FunctionPort");
          frameworkServices = 0;
        }
    }

  }
}