#include "cca.h" #include "PiFunction_CCA.h" #include "macros_CCA.h" namespace functions { namespace ccaimpl { /** * Default constructor */ PiFunction::PiFunction () { frameworkServices = 0; } PiFunction::~PiFunction () { } /** * A function to approximate Pi */ double PiFunction::evaluate (double x) { return 4.0 / (1.0 + 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 PiFunction::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; } } } }