コード例 #1
0
ファイル: qilog.cpp プロジェクト: soshiant1992/libqi
static void setFilter(const std::string& rules, qi::AnyObject listener)
{
  // See doc in header for format
  size_t pos = 0;
  while (true)
  {
    if (pos >= rules.length())
      break;
    size_t next = rules.find(':', pos);
    std::string token;
    if (next == rules.npos)
      token = rules.substr(pos);
    else
      token = rules.substr(pos, next-pos);
    if (token.empty())
    {
      pos = next + 1;
      continue;
    }
    if (token[0] == '+')
      token = token.substr(1);
    size_t sep = token.find('=');
    if (sep != token.npos)
    {
      std::string sLevel = token.substr(sep+1);
      std::string cat = token.substr(0, sep);
      int level = qi::log::stringToLogLevel(sLevel.c_str());
      qiLogFatal() << cat << level;
      listener.call<void>("addFilter", cat, level);
    }
    else
    {
      if (token[0] == '-')
      {
        qiLogFatal() << token.substr(1) << 0;
        listener.call<void>("addFilter", token.substr(1), 0);
      }
      else
      {
        qiLogFatal() << token << 6;
        listener.call<void>("addFilter", token, 6);
      }
    }
    if (next == rules.npos)
      break;
    pos = next+1;
  }
}
コード例 #2
0
ファイル: test_qilog_async.cpp プロジェクト: bsautron/libqi
TEST(log, logasync)
{
  qi::log::init(qi::LogLevel_Info, 0, false);
  atexit(qi::log::destroy);

   for (int i = 0; i < 1000; i++)
     qiLogFatal("core.log.test1", "%d\n", i);
}
コード例 #3
0
ファイル: jnitools.cpp プロジェクト: RevanthK/libqi-java
static void emergency()
{
  qiLogFatal() << "Emergency, aborting";
#ifdef unix
  kill(getpid(), SIGQUIT);
#else
  abort();
#endif
}
コード例 #4
0
ファイル: map_jni.cpp プロジェクト: RevanthK/libqi-java
jobject JNIHashTable::at(jobject key)
{
  jmethodID mid = _env->GetMethodID(_cls, "get", "(Ljava/lang/Object;)Ljava/lang/Object;");

  if (!key)
  {
    qiLogFatal() << "JNIHashTable::at() : Given key is null";
    return 0;
  }

  if (!mid)
  {
    qiLogFatal() << "JNIHashTable::at() : Cannot call method get";
    throw std::runtime_error("JNIHashTable::at() : Cannot call method get");
  }

  return _env->CallObjectMethod(_obj, mid, key);
}
コード例 #5
0
ファイル: map_jni.cpp プロジェクト: RevanthK/libqi-java
bool JNIHashTable::setItem(jobject key, jobject value)
{
  jmethodID mid = _env->GetMethodID(_cls, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");

  if (!key || !value)
  {
    qiLogFatal() << "JNIHashTable::setItem() : Given key/value pair is null";
    return false;
  }

  if (!mid)
  {
    qiLogFatal() << "JNIHashTable::setItem() : Cannot call put";
    throw std::runtime_error("JNIHashTable::setItem() : Cannot call put");
  }

  _env->CallObjectMethod(_obj, mid, key, value);
  return true;
}
コード例 #6
0
int JNIList::size()
{
  jmethodID mid = _env->GetMethodID(_cls, "size", "()I");

  if (!mid)
  {
    qiLogFatal("qimessaging.jni") << "JNIList::size() : Cannot call size()";
    throw std::runtime_error("JNIList::size() : Cannot call size()");
  }

  return _env->CallIntMethod(_obj, mid);
}
コード例 #7
0
bool JNIEnumeration::hasNextElement()
{
  jmethodID mid = _env->GetMethodID(_cls, "hasMoreElements", "()Z");

  if (!mid)
  {
    qiLogFatal() << "JNIEnumeration : Cannot call method hasMoreElements";
    throw std::runtime_error("JNIEnumeration : Cannot call method hasMoreElements");
  }

  return _env->CallBooleanMethod(_obj, mid);
}
コード例 #8
0
bool JNIList::push_back(jobject current)
{
  jmethodID mid = _env->GetMethodID(_cls, "add", "(Ljava/lang/Object;)Z");

  if (!mid)
  {
    qiLogFatal("qimessaging.jni") << "JNIList::push_back() : Cannot call add()";
    throw std::runtime_error("JNIList::push_back() : Cannot call add()");
  }

  return _env->CallBooleanMethod(_obj, mid, current);
}
コード例 #9
0
jobject JNIList::get(int index)
{
  jmethodID mid = _env->GetMethodID(_cls, "get", "(I)Ljava/lang/Object;");

  if (!mid)
  {
    qiLogFatal("qimessaging.jni") << "JNIList::get() : Cannot call get()";
    throw std::runtime_error("JNIList::get() : Cannot call get()");
  }

  return _env->CallObjectMethod(_obj, mid, index);
}
コード例 #10
0
jobject JNIEnumeration::nextElement()
{
  jmethodID mid = _env->GetMethodID(_cls, "nextElement", "()Ljava/lang/Object;");

  if (!mid)
  {
    qiLogFatal() << "JNIEnumeration : Cannot call method nextElement";
    throw std::runtime_error("JNIEnumeration : Cannot call method nextElement");
  }

  return _env->CallObjectMethod(_obj, mid);
}
コード例 #11
0
ファイル: map_jni.cpp プロジェクト: RevanthK/libqi-java
JNIEnumeration JNIHashTable::keys()
{
  jmethodID mid = _env->GetMethodID(_cls, "keys", "()Ljava/util/Enumeration;");

  if (!mid)
  {
    qiLogFatal() << "JNIHashTable : Cannot call method keys";
    throw std::runtime_error("JNIHashTable : Cannot call method keys");
  }

  return JNIEnumeration(_env->CallObjectMethod(_obj, mid));
}
コード例 #12
0
JNIList::JNIList()
{
  JVM()->GetEnv((void**) &_env, QI_JNI_MIN_VERSION);
 _cls = qi::jni::clazz("List");

 jmethodID mid = _env->GetMethodID(_cls, "<init>", "()V");
 if (!mid)
 {
   qiLogFatal("qimessaging.jni") << "JNIList::JNIList: Cannot call constructor";
   throw std::runtime_error("JNIList::JNIList: Cannot call constructor");
 }

 _obj = _env->NewObject(_cls, mid);
}
コード例 #13
0
ファイル: map_jni.cpp プロジェクト: RevanthK/libqi-java
JNIHashTable::JNIHashTable()
{
   JVM()->GetEnv((void**) &_env, QI_JNI_MIN_VERSION);
  _cls = _env->FindClass("java/util/Hashtable");

  jmethodID mid = _env->GetMethodID(_cls, "<init>", "()V");
  if (!mid)
  {
    qiLogFatal() << "JNIHashTable::JNIHashTable : Cannot call constructor";
    throw std::runtime_error("JNIHashTable::JNIHashTable : Cannot call constructor");
  }

  _obj = _env->NewObject(_cls, mid);
}
コード例 #14
0
ファイル: jnitools.cpp プロジェクト: RevanthK/libqi-java
/**
 * @brief throwJavaError Helper function to throw generic Java exception from C++
 * @param env JNI environment
 * @param message content of exception
 * @return 0 on success, a positive number otherwise
 */
jint throwJavaError(JNIEnv *env, const char *message)
{
  jclass		 exClass;
  const char*    className = "java/lang/Exception" ;

  exClass = env->FindClass(className);
  if (exClass == NULL)
  {
    qiLogFatal() << "Cannot throw any exceptions";
    return 1;
  }

  return env->ThrowNew(exClass, message);
}
コード例 #15
0
TEST(log, logasync)
{
  qiLogCategory("core.log.test1");

  qi::log::init(qi::LogLevel_Info, 0, false);
  atexit(qi::log::destroy);

  BlockyHandler bh;
  qi::log::addHandler("BlockyHandler",
      boost::bind(&BlockyHandler::log, &bh,
                  _1, _2, _3, _4, _5, _6, _7, _8));

  for (int i = 0; i < MAX; i++)
    qiLogFatal() << i;

  bh.start.setValue(0);

  bh.finished.future().wait();

  qi::log::removeHandler("BlockyHandler");
}
コード例 #16
0
ファイル: jnitools.cpp プロジェクト: RevanthK/libqi-java
/*
 * To work correctly, QiMessaging<->java type system needs to compare type class template.
 * Unfortunately, call template cannot be retrieve on native android thread, that is why
 * type instance are stored in supportedTypes map.
 */
void Java_com_aldebaran_qi_EmbeddedTools_initTypeSystem(JNIEnv* env, jobject QI_UNUSED(jobj), jobject str, jobject i, jobject f, jobject d, jobject l, jobject m, jobject al, jobject tuple, jobject obj, jobject b, jobject fut)
{
  JVM(env);

  supportedTypes["String"] = env->NewGlobalRef(str);
  supportedTypes["Integer"] = env->NewGlobalRef(i);
  supportedTypes["Float"] = env->NewGlobalRef(f);
  supportedTypes["Double"] = env->NewGlobalRef(d);
  supportedTypes["Long"] = env->NewGlobalRef(l);
  supportedTypes["Map"] = env->NewGlobalRef(m);
  supportedTypes["List"] = env->NewGlobalRef(al);
  supportedTypes["Tuple"] = env->NewGlobalRef(tuple);
  supportedTypes["Object"] = env->NewGlobalRef(obj);
  supportedTypes["Boolean"] = env->NewGlobalRef(b);
  supportedTypes["Future"] = env->NewGlobalRef(fut);

  for (std::map<std::string, jobject>::iterator it = supportedTypes.begin(); it != supportedTypes.end(); ++it)
  {
    if (it->second == 0)
      qiLogFatal() << it->first << ": Initialization failed.";
  }
}
コード例 #17
0
ファイル: jnitools.cpp プロジェクト: RevanthK/libqi-java
/**
 * @brief getJavaSignature Convert qitype-like signature into Java-like signature.
 * @param sig Java signature to be.
 * @param sigInfo qitype signature.
 *
 * Do not call this function, use toJavaSignature instead
 * @see toJavaSignature
 */
void getJavaSignature(std::string &sig, const std::string& sigInfo)
{
  unsigned int i = 0;

  while (i < sigInfo.size())
  {
    switch (sigInfo[i])
    {
    case qi::Signature::Type_Bool:
      sig.append("Ljava/lang/Boolean;");
      break;
    case qi::Signature::Type_Int8:
      sig.append("Ljava/lang/Character;");
      break;
    case qi::Signature::Type_Float:
      sig.append("Ljava/lang/Float;");
      break;
    case qi::Signature::Type_Double:
      sig.append("Ljava/lang/Double;");
      break;
    case qi::Signature::Type_Int32:
      sig.append("Ljava/lang/Integer;");
      break;
    case qi::Signature::Type_String:
      sig.append("Ljava/lang/String;");
      break;
    case qi::Signature::Type_Void:
      sig.append("V");
      break;
    case qi::Signature::Type_Dynamic:
      sig.append("Ljava/lang/Object;");
      break;
    case qi::Signature::Type_Map:
    {
      sig.append("Ljava/util/Map;");
      while (i < sigInfo.size() && sigInfo[i] != qi::Signature::Type_Map_End)
        i++;
      break;
    }
    case qi::Signature::Type_Tuple:
    {
      sig.append("Lcom/aldebaran/qi/Tuple;");
      while (i < sigInfo.size() && sigInfo[i] != qi::Signature::Type_Tuple_End)
        i++;
      break;
    }
    case qi::Signature::Type_List:
    {
      sig.append("Ljava/util/ArrayList;");
      while (i < sigInfo.size() && sigInfo[i] != qi::Signature::Type_List_End)
        i++;
      break;
    }
    case qi::Signature::Type_Object:
    {
      sig.append("L");
      sig.append(QI_OBJECT_CLASS);
      sig.append(";");
      break;
    }
    default:
      qiLogFatal() << "Unknown conversion for [" << sigInfo[i] << "]";
      break;
    }

    i++;
  }
}