/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2013 University of California, Los Angeles
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
 *         Alexander Afanasyev <alexander.afanasyev@ucla.edu>
 */

#include "ccnx-closure.h"

namespace Ccnx {

Closure::Closure(const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback)
  : m_timeoutCallback (timeoutCallback)
  , m_dataCallback (dataCallback)
{
}

Closure::~Closure ()
{
}

Closure::TimeoutCallbackReturnValue
Closure::runTimeoutCallback(Name interest)
{
  if (m_timeoutCallback.empty ())
    {
      return RESULT_OK;
    }

  return m_timeoutCallback (interest);
}


void
Closure::runDataCallback(Name name, PcoPtr content)
{
  if (!m_dataCallback.empty ())
    {
      m_dataCallback (name, content);
    }
}

ExecutorClosure::ExecutorClosure(const Closure &closure, ExecutorPtr executor)
                : Closure(closure)
                , m_executor(executor)
{
}

ExecutorClosure::~ExecutorClosure()
{
}

void
ExecutorClosure::runDataCallback(Name name, PcoPtr content)
{
  m_executor->execute(boost::bind(&ExecutorClosure::execute, this, name, content));
}

void
ExecutorClosure::execute(Name name, PcoPtr content)
{
  Closure::runDataCallback(name, content);
}

ExecutorInterestClosure::ExecutorInterestClosure(const InterestCallback &callback, ExecutorPtr executor)
                        : m_callback(callback)
                        , m_executor(executor)
{
}

void
ExecutorInterestClosure::runInterestCallback(Name interest)
{
  m_executor->execute(boost::bind(&ExecutorInterestClosure::execute, this, interest));
}

void
ExecutorInterestClosure::execute(Name interest)
{
  if (!m_callback.empty())
  {
    m_callback(interest);
  }
}

} // Ccnx
