std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscriptions()
{
  Communication::InputBuffer response;
  if (!CallEngine(Communication::PROC_AVAILABLE_SUBSCRIPTIONS, response)) 
    return std::vector<SubscriptionDescription>();
  return ReadSubscriptions(response);
}
std::vector<SubscriptionDescription> CAdblockPlusClient::GetListedSubscriptions()
{
  Communication::InputBuffer response;
  if (!CallEngine(Communication::PROC_LISTED_SUBSCRIPTIONS, response)) 
    return std::vector<SubscriptionDescription>();
  return ReadSubscriptions(response);
}
std::vector<std::wstring> CAdblockPlusClient::GetExceptionDomains()
{
  Communication::InputBuffer response;
  if (!CallEngine(Communication::PROC_GET_EXCEPTION_DOMAINS, response)) 
    return std::vector<std::wstring>();
  return ReadStrings(response);
}
bool CAdblockPlusClient::IsFirstRun()
{
  DEBUG_GENERAL("IsFirstRun");
  Communication::InputBuffer response;
  if (!CallEngine(Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED, response)) return false;
  bool res;
  response >> res;
  return res;
}
std::vector<std::wstring> CAdblockPlusClient::GetElementHidingSelectors(const std::wstring& domain)
{
  Communication::OutputBuffer request;
  request << Communication::PROC_GET_ELEMHIDE_SELECTORS << ToUtf8String(domain);

  Communication::InputBuffer response;
  if (!CallEngine(request, response)) 
    return std::vector<std::wstring>();
  return ReadStrings(response);
}
bool CAdblockPlusClient::Matches(const std::wstring& url, AdblockPlus::FilterEngine::ContentType contentType, const std::wstring& domain)
{
  Communication::OutputBuffer request;
  request << Communication::PROC_MATCHES << ToUtf8String(url) << static_cast<int32_t>(contentType) << ToUtf8String(domain);

  Communication::InputBuffer response;
  if (!CallEngine(request, response)) 
    return false;

  bool match;
  response >> match;
  return match;
}
bool CAdblockPlusClient::IsElemhideWhitelistedOnDomain(const std::wstring& url, const std::vector<std::string>& frameHierarchy)
{
  Communication::OutputBuffer request;
  request << Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL << ToUtf8String(url) << frameHierarchy;

  Communication::InputBuffer response;
  if (!CallEngine(request, response)) 
    return false;

  bool isWhitelisted;
  response >> isWhitelisted;
  return isWhitelisted;
}
std::string CAdblockPlusClient::GetWhitelistingFilter(const std::wstring& url, const std::vector<std::string>& frameHierarchy)
{
  DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" start").c_str());
  Communication::OutputBuffer request;
  request << Communication::PROC_GET_WHITELISTING_FITER << ToUtf8String(url) << frameHierarchy;

  Communication::InputBuffer response;
  if (!CallEngine(request, response)) 
    return "";

  std::string filterText;
  response >> filterText;

  DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" end").c_str());
  return filterText;
}
bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url)
{
  DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" start").c_str());
  Communication::OutputBuffer request;
  request << Communication::PROC_IS_WHITELISTED_URL << ToUtf8String(url);

  Communication::InputBuffer response;
  if (!CallEngine(request, response)) 
    return false;

  bool isWhitelisted;
  response >> isWhitelisted;

  DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" end").c_str());
  return isWhitelisted;
}
std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::wstring& defaultValue)
{
  DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str());
  Communication::OutputBuffer request;
  request << Communication::PROC_GET_PREF << ToUtf8String(name);

  Communication::InputBuffer response;
  if (!CallEngine(request, response)) 
    return defaultValue;
  bool success;
  response >> success;
  if (success)
  {
    std::string value;
    response >> value;
    DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
    return ToUtf16String(value);
  }
  else
  {
void CAdblockPlusClient::SetPref(const std::wstring& name, bool value)
{
  Communication::OutputBuffer request;
  request << Communication::PROC_SET_PREF << ToUtf8String(name) << value;
  CallEngine(request);
}
void CAdblockPlusClient::RemoveFilter(const std::string& text)
{
  Communication::OutputBuffer request;
  request << Communication::PROC_REMOVE_FILTER << text;
  CallEngine(request);
}
void CAdblockPlusClient::AddFilter(const std::wstring& text)
{
  Communication::OutputBuffer request;
  request << Communication::PROC_ADD_FILTER << ToUtf8String(text);
  CallEngine(request);
}
void CAdblockPlusClient::UpdateAllSubscriptions()
{
  CallEngine(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS);
}
void CAdblockPlusClient::RemoveSubscription(const std::wstring& url)
{
  Communication::OutputBuffer request;
  request << Communication::PROC_REMOVE_SUBSCRIPTION << ToUtf8String(url);
  CallEngine(request);
}
bool CAdblockPlusClient::CallEngine(Communication::ProcType proc, Communication::InputBuffer& inputBuffer)
{
  Communication::OutputBuffer message;
  message << proc;
  return CallEngine(message, inputBuffer);
}