/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2012 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: Yingdi Yu <yingdi@cs.ucla.edu>
 */

#ifndef SYNC_SOCKET_H
#define SYNC_SOCKET_H

#include "sync-logic.h"
#include <boost/function.hpp>
#include <boost/unordered_map.hpp>
#include "sync-seq-no.h"
#include <ndn-cpp-dev/face.hpp>
#include <ndn-cpp-dev/security/verifier.hpp>
#include <ndn-cpp-dev/security/key-chain.hpp>
#include <utility>
#include <map>
#include <vector>
#include <sstream>

namespace Sync {

/**
 * \ingroup sync
 * @brief A simple interface to interact with client code
 */
class SyncSocket
{
public:
  typedef boost::function< void (const std::vector<MissingDataInfo> &, SyncSocket * ) > NewDataCallback;
  typedef boost::function< void ( const std::string &/*prefix*/ ) > RemoveCallback;
  /**
   * @brief the constructor for SyncAppSocket; the parameter syncPrefix
   * should be passed to the constructor of m_syncAppWrapper; the other
   * parameter should be passed to the constructor of m_fetcher; furthermore,
   * the fetch function of m_fetcher should be a second paramter passed to
   * the constructor of m_syncAppWrapper, so that m_syncAppWrapper can tell
   * m_fetcher to fetch the actual app data after it learns the names
   *
   * @param syncPrefix the name prefix for Sync Interest
   * @param dataCallback the callback to process data
   */
  SyncSocket (const std::string &syncPrefix, 
              ndn::ptr_lib::shared_ptr<SecPolicySync> policy,
              ndn::ptr_lib::shared_ptr<ndn::Face> face,
              NewDataCallback dataCallback, 
              RemoveCallback rmCallback);

  ~SyncSocket ();

  bool 
  publishData(const std::string &prefix, uint32_t session, const char *buf, size_t len, int freshness);

  void 
  remove (const std::string &prefix) 
  { m_syncLogic.remove(prefix); }

  void 
  fetchData(const std::string &prefix, const SeqNo &seq, const ndn::OnVerified& onVerified, int retry = 0);

  std::string 
  getRootDigest() 
  { return m_syncLogic.getRootDigest(); }

  uint32_t
  getNextSeq (const std::string &prefix, uint32_t session);

  SyncLogic &
  getLogic () 
  { return m_syncLogic; }

  // make this a static function so we don't have to create socket instance without
  // knowing the local prefix. it's a wrong place for this function anyway
  static std::string
  GetLocalPrefix (); 
  
private:
  void 
  passCallback(const std::vector<MissingDataInfo> &v) 
  { m_newDataCallback(v, this); }

  void
  onChatData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
             const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
             const ndn::OnVerified& onVerified,
             const ndn::OnVerifyFailed& onVerifyFailed);

  void
  onChatDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
                    int retry,
                    const ndn::OnVerified& onVerified,
                    const ndn::OnVerifyFailed& onVerifyFailed);

  void
  onChatDataVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data);

private:
  typedef boost::unordered_map<std::string, SeqNo> SequenceLog;
  NewDataCallback m_newDataCallback;
  SequenceLog m_sequenceLog;
  ndn::ptr_lib::shared_ptr<SecPolicySync> m_policy;
  ndn::ptr_lib::shared_ptr<ndn::Verifier> m_verifier;
  ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
  ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
  SyncLogic      m_syncLogic;
};

} // Sync

#endif // SYNC_SOCKET_H
