MojErr MojLunaService::addCategory(const MojChar* name, CategoryHandler* handler) { LOG_TRACE("Entering function %s", __FUNCTION__); MojAssert(name && handler); MojAssertMutexUnlocked(m_mutex); MojThreadGuard guard(m_mutex); // create array of LSMethods MethodVec pubMethods; MethodVec privMethods; const CategoryHandler::CallbackMap& callbacks = handler->callbacks(); for (CategoryHandler::CallbackMap::ConstIterator i = callbacks.begin(); i != callbacks.end(); i++) { LSMethod m = {i.key(), &handleRequest}; MethodVec& methods = i->m_pub ? pubMethods : privMethods; MojErr err = methods.push(m); MojErrCheck(err); } LSMethod nullMethod = {NULL, NULL}; MojErr err = pubMethods.push(nullMethod); MojErrCheck(err); err = privMethods.push(nullMethod); MojErrCheck(err); // create category object to hang on to method array MojRefCountedPtr<LunaCategory> cat(new LunaCategory(this, handler, pubMethods, privMethods)); MojAllocCheck(cat.get()); LSMethod* pubLsMethods = const_cast<LSMethod*>(cat->m_pubMethods.begin()); LSMethod* privLsMethods = const_cast<LSMethod*>(cat->m_privMethods.begin()); MojLunaErr lserr; bool retVal; if (m_service) { retVal = LSPalmServiceRegisterCategory(m_service, name, pubLsMethods, privLsMethods, NULL, cat.get(), lserr); MojLsErrCheck(retVal, lserr); } else { MojAssert(m_handle); retVal = LSRegisterCategory(m_handle, name, privLsMethods, NULL, NULL, lserr); MojLsErrCheck(retVal, lserr); retVal = LSCategorySetData(m_handle, name, cat.get(), lserr); MojLsErrCheck(retVal, lserr); } MojString categoryStr; err = categoryStr.assign(name); MojErrCheck(err); err = m_categories.put(categoryStr, cat); MojErrCheck(err); return MojErrNone; }
bool ClassInfo::GetClassMethods(MethodVec &ret, const ClassInfo *classInfo) { const ClassInfo::MethodVec &methods = classInfo->getMethodsVec(); ret.insert(ret.end(), methods.begin(), methods.end()); if (!(classInfo->getAttribute() & (IsInterface|IsTrait))) { const String& parentClass = classInfo->getParentClass(); if (!parentClass.empty()) { if (!GetClassMethods(ret, parentClass, 1)) return false; } } const ClassInfo::InterfaceVec &interfaces = classInfo->getInterfacesVec(); for (unsigned int i = 0; i < interfaces.size(); i++) { if (!GetClassMethods(ret, interfaces[i], 2)) return false; } return true; }
void ClassInfo::GetClassMethods(MethodVec &ret, const char *classname, int type /* = 0 */) { if (classname && *classname) { const ClassInfo *classInfo = NULL; switch (type) { case 0: classInfo = FindClass(classname); if (classInfo == NULL) { classInfo = FindInterface(classname); type = 2; } break; case 1: classInfo = FindClass(classname); break; case 2: classInfo = FindInterface(classname); break; default: ASSERT(false); } if (classInfo) { const ClassInfo::MethodVec &methods = classInfo->getMethodsVec(); ret.insert(ret.end(), methods.begin(), methods.end()); if (type != 2) { const char *parentClass = classInfo->getParentClass(); if (parentClass && *parentClass) { GetClassMethods(ret, parentClass, 1); } } const ClassInfo::InterfaceVec &interfaces = classInfo->getInterfacesVec(); for (unsigned int i = 0; i < interfaces.size(); i++) { GetClassMethods(ret, interfaces[i], 2); } } } }