Example #1
0
bool ClassInfo::derivesFromImpl(const char *name, bool considerInterface) const {
  if (strcasecmp(name, getParentClass()) == 0) {
    return true;
  }

  // We don't support redeclared parents anyway.
  const ClassInfo *parent = FindClass(getParentClass());
  if (parent && parent->derivesFromImpl(name, considerInterface)) {
    return true;
  }

  if (considerInterface) {
    const InterfaceMap &interfaces = getInterfaces();
    for (InterfaceMap::const_iterator iter = interfaces.begin();
         iter != interfaces.end(); ++iter) {
      if (strcasecmp(name, *iter) == 0) {
        return true;
      }
      const ClassInfo *parent = FindInterface(*iter);
      if (parent && parent->derivesFromImpl(name, considerInterface)) {
        return true;
      }
    }
  }
  return false;
}
Example #2
0
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);
      }
    }
  }
}
void HIDUniversal::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) 
{
	// If the first configuration satisfies, the others are not concidered.
	if (bNumEP > 1 && conf != bConfNum)
		return;

	ErrorMessage<uint8_t>(PSTR("\r\nConf.Val"), conf);
	ErrorMessage<uint8_t>(PSTR("Iface Num"), iface);
	ErrorMessage<uint8_t>(PSTR("Alt.Set"), alt);

	bConfNum = conf;

	uint8_t			index	= 0;
	HIDInterface	*piface = FindInterface(iface, alt, proto);
	
	// Fill in interface structure in case of new interface 
	if (!piface)
	{
		piface				= hidInterfaces + bNumIface;
		piface->bmInterface = iface;
		piface->bmAltSet	= alt;
		piface->bmProtocol	= proto;
		bNumIface ++;
	}

	if ((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80)
	{
		USBTRACE("I8\r\n");
		index = epInterruptInIndex;
	}
	else
	{
		USBTRACE("I0\r\n");
		index = epInterruptOutIndex;
	}

	if (index)
	{
		USBTRACE2("Ind:", index);

		// Fill in the endpoint info structure
		epInfo[bNumEP].epAddr		= (pep->bEndpointAddress & 0x0F);
		epInfo[bNumEP].maxPktSize	= (uint8_t)pep->wMaxPacketSize;
		epInfo[bNumEP].epAttribs	= 0;

		// Fill in the endpoint index list
		piface->epIndex[index] = bNumEP;			//(pep->bEndpointAddress & 0x0F);

		bNumEP ++;
	}
	PrintEndpointDescriptor(pep);
}
void CPVInterfaceProxy::CleanupPVThreadQueues()
//cleanup memory allocated in PV thread.
{
    //un-sent notifications
    iNotifierQueueCrit.Lock();
    while (!iNotificationQueue.empty())
    {
        CPVProxyMsg *msg = &iNotificationQueue[0];
        CPVProxyInterface *proxy = FindInterface(msg->iProxyId);
        if (proxy)
            proxy->iServer->CleanupNotification(msg->iMsgId, msg->iMsg);
        iNotificationQueue.erase(msg);
    }
    iNotificationQueue.clear();
    iNotificationQueue.destroy();
    iNotifierQueueCrit.Unlock();
}
void HIDUniversal::EndpointXtract(uint32_t conf, uint32_t iface, uint32_t alt, uint32_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) {
        // If the first configuration satisfies, the others are not concidered.
        if(bNumEP > 1 && conf != bConfNum)
                return;

        //ErrorMessage<uint8_t>(PSTR("\r\nConf.Val"), conf);
        //ErrorMessage<uint8_t>(PSTR("Iface Num"), iface);
        //ErrorMessage<uint8_t>(PSTR("Alt.Set"), alt);

        bConfNum = conf;

        uint8_t index = 0;
        HIDInterface *piface = FindInterface(iface, alt, proto);

        // Fill in interface structure in case of new interface
        if(!piface) {
                piface = hidInterfaces + bNumIface;
                piface->bmInterface = iface;
                piface->bmAltSet = alt;
                piface->bmProtocol = proto;
                bNumIface++;
        }

        if((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80)
                index = epInterruptInIndex;
        else
                index = epInterruptOutIndex;

        if(index) {
                // Fill in the endpoint info structure
                epInfo[bNumEP].epAddr = (pep->bEndpointAddress & 0x0F);
                epInfo[bNumEP].maxPktSize = (uint8_t)pep->wMaxPacketSize;
                epInfo[bNumEP].bmSndToggle = 0;
                epInfo[bNumEP].bmRcvToggle = 0;
                epInfo[bNumEP].bmNakPower = USB_NAK_NOWAIT;

                // Fill in the endpoint index list
                piface->epIndex[index] = bNumEP; //(pep->bEndpointAddress & 0x0F);

                if(pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints
                        pollInterval = pep->bInterval;

                bNumEP++;
        }
        //PrintEndpointDescriptor(pep);
}
AJ_Status AJ_LookupMessageId(AJ_Message* msg, uint8_t* secure)
{
    uint8_t oIndex = 0;

    for (oIndex = 0; oIndex < ArraySize(objectLists); ++oIndex) {
        uint8_t pIndex = 0;
        const AJ_Object* obj = objectLists[oIndex];
        if (!obj) {
            continue;
        }
        while (obj->path) {
            /*
             * Match the object path. The wildcard entry is for interfaces that are automatically
             * defined for all objects; specifically to support the introspection and ping methods.
             */
            if (!(obj->flags & AJ_OBJ_FLAG_DISABLED) && ((obj->path[0] == '*') || (strcmp(obj->path, msg->objPath) == 0))) {
                uint8_t iIndex;
                AJ_InterfaceDescription desc = FindInterface(obj->interfaces, msg->iface, &iIndex);
                if (desc) {
                    uint8_t mIndex = 0;
                    *secure = SecurityApplies(*desc, obj, objectLists[oIndex]);
                    /*
                     * Skip the interface name and iterate over the members of the interface
                     */
                    while (*(++desc)) {
                        if (MatchMember(*desc, msg)) {
                            msg->msgId = (oIndex << 24) | (pIndex << 16) | (iIndex << 8) | mIndex;
                            AJ_InfoPrintf(("Identified message %x\n", msg->msgId));
                            return CheckSignature(*desc, msg);
                        }
                        ++mIndex;
                    }
                }
            }
            ++pIndex;
            ++obj;
        }
    }
    AJ_ErrPrintf(("LookupMessageId(): AJ_ERR_NO_MATCH\n"));
    return AJ_ERR_NO_MATCH;
}
OSCL_EXPORT_REF void CPVInterfaceProxy::DeliverNotifications(int32 aTargetCount, int32& aNoticesPending)
//deliver notifications off the queue, from the app thread size
{
    //make sure this isn't called under PV thread...
    if (iPVThreadContext.IsSameThreadContext())
        OsclError::Leave(OsclErrThreadContextIncorrect);

    for (int32 count = 0; count < aTargetCount;)
    {
        //get next notification or cleanup message.
        iNotifierQueueCrit.Lock();
        CPVProxyMsg notice(0, 0, NULL);
        if (iNotificationQueue.size() > 0)
        {
            notice = iNotificationQueue[0];
            iNotificationQueue.erase(&iNotificationQueue[0]);
        }
        iNotifierQueueCrit.Unlock();

        if (notice.iMsg)
        {
            count++;
            CPVProxyInterface *ext = FindInterface(notice.iProxyId);
            if (ext)
                ext->iClient->HandleNotification(notice.iMsgId, notice.iMsg);
            else
            {   //since messages are cleaned up when interfaces
                //get unregistered, we should not get here.
                OSCL_ASSERT(0);//debug error.
            }
        }
        else
            break;//no more messages.
    }
    //return number of notices left after trying to process
    //the desired number.
    iNotifierQueueCrit.Lock();
    aNoticesPending = iNotificationQueue.size();
    iNotifierQueueCrit.Unlock();
}
void CPVInterfaceProxy::CleanupAppThreadQueues()
//cleanup memory allocated in App thread.
{
    //un-sent commands...
    iHandlerQueueCrit.Lock();
    while (!iCommandQueue.empty())
    {
        CPVProxyMsg *msg = &iCommandQueue[0];
        CPVProxyInterface *proxy = FindInterface(msg->iProxyId);
        if (proxy)
            proxy->iClient->CleanupCommand(msg->iMsgId, msg->iMsg);
        iCommandQueue.erase(msg);
    }
    iCommandQueue.clear();
    iCommandQueue.destroy();
    iHandlerQueueCrit.Unlock();

    //proxy list...
    iProxyListCrit.Lock();
    iProxyList.clear();
    iProxyList.destroy();
    iProxyListCrit.Unlock();
}
OSCL_EXPORT_REF void CPVInterfaceProxy::CancelAllNotifications(TPVProxyId aProxyId)
{
    CleanupNotifications(FindInterface(aProxyId), true);
}
OSCL_EXPORT_REF void CPVInterfaceProxy::CancelNotification(TPVProxyId aProxyId, TPVProxyMsgId aMsgId)
{
    CleanupNotifications(FindInterface(aProxyId), false, aMsgId);
}
OSCL_EXPORT_REF void CPVInterfaceProxy::CancelAllCommands(TPVProxyId aProxyId)
{
    CleanupCommands(FindInterface(aProxyId), true);
}
OSCL_EXPORT_REF void CPVInterfaceProxy::CancelCommand(TPVProxyId aProxyId, TPVProxyMsgId aMsgId)
{
    CleanupCommands(FindInterface(aProxyId), false, aMsgId);
}
SString
TypeToCPPType(const InterfaceRec* rec, const sptr<IDLType>& obj, bool asConst)
{
	// Convert IDLType into a C++ type name
	// rec can be NULL if we are writing the type inside the class, otherwise
	// it must point to the owning class (for typedefs)

	SString	cpptype = obj->GetName();

	if (cpptype==NULL) {
		bout << "<----- outpututil.cpp -----> invalid type when converting to CPP;"  << endl;
		_exit(1);
	}
	else {		
		// Binder Types
		// IClass* -> sptr<IClass>
		// [weak] IClass* -> wptr<IClass>
		// (both of these types have the name of "sptr")
		if (cpptype=="sptr") {
			if (obj->HasAttribute(kWeak) == true) {
				cpptype = "wptr";
			}
			InterfaceRec* iface=FindInterface(obj->GetIface());				
			cpptype.Append("<");
			if (iface->ID()== "Binder") { cpptype.Append("I"); }
			cpptype.Append(iface->ID());
			cpptype.Append(">");
			if (asConst) {
				cpptype.Prepend("const ");
				cpptype.Append("&");
			}

		} 
		else if ((cpptype=="SString") || (cpptype=="SValue") || (cpptype=="SMessage")) {
			if (asConst) {
				cpptype.Prepend("const ");
				cpptype.Append("&");
			}
		} 
		else if (cpptype=="char*") {
			if (asConst) {			
				// in the rare case this is a const char*
				cpptype.Prepend("const ");
			}
			else {
				cpptype="SString";
			}
		} 
		else if (cpptype=="void") {
			;	// cpptype is fine as is
		} 
		else {

			// deal with typedefs...
			// If the stored type is different than the object type, then
			// we have a user defined typedef... 
			// add in the class name as a qualifier, because they are defined
			// inside the IClass definition.
			sptr<IDLType> storedtype=FindType(obj);
			if (storedtype->GetName() != obj->GetName() && rec != kInsideClassScope) {
				SString classQualifier = rec->ID();
				classQualifier.Append("::");
				cpptype.Prepend(classQualifier);
			}
			if (asConst) {
				uint32_t code = storedtype->GetCode();
				if (code == B_WILD_TYPE || code == B_VARIABLE_ARRAY_TYPE) {
					// If B_WILD_TYPE then we have an exported type
					// that we really don't know about, or
					// if B_VARIABLE_ARRAY_TYPE, then we have a sequence
					// typedef.  Both of which want const references
					// for input parameters.
					cpptype.Prepend("const ");
					cpptype.Append("&");
				}
			}	
		}
	}

	return cpptype;
}
SString
FromSValueConversion(const sptr<IDLType>& type, const SString &variable, bool setError)
{
	SString s(variable);
	s.Append(".");

	SString tn=type->GetName();

	sptr<IDLType> storedtype=FindType(type);
	if (storedtype->CountMembers()>1) {	
		sptr<jmember> fromBV=storedtype->GetMemberAt(1);

		if ((tn=="SValue") || (tn=="SMessage")) {
			// simple assignment
			s = variable; 
			return s;
		}
		if (tn=="sptr") {		
			//bout << "interface id=" << type->GetIface() << endl;
			if (type->GetIface() == "IBinder") {
				s=variable;
				if (setError) {
					s.Append(".AsBinder(&_pidgen_err)");
				}
				else {
					s.Append(".AsBinder()");
				}
			}
			else {
				InterfaceRec*	validiface=FindInterface(type->GetIface());
				s.Truncate(0);
				/* if (validiface->InNamespace()) {
					s.Append(validiface->Namespace());
					s.Append(':', 2);
				} */
				s.Append(validiface->ID());
				s.Append("::AsInterface(");
				s.Append(variable);
				if (setError) {
					s.Append(", &_pidgen_err)");
				}
				else {
					s.Append(")");
				}
			}
			return s;	
		}
		else if ((tn!=NULL) && (storedtype->GetCode() == B_WILD_TYPE)) {		
			// custom types which have Code==B_WILD_TYPE
			// all custom types use explicit constructor
			//bout << "<----- outpututil.cpp -----> FromSValueConversion - " << tn << " is a custom type " << endl; 

			s=fromBV->ID();
			s.Append("(");
			s.Append(variable);
			if (setError) {
				s.Append(", &_pidgen_err)");
			}
			else {
				s.Append(")");
			}
			//s.Prepend(".");	
			return s;
		}
		else if ((tn!=NULL) && storedtype->GetCode() == B_VARIABLE_ARRAY_TYPE) {
			// custom types which are sequences
			// if we are dealing with an array type, then we need to
			// use the SVector SetFromValue function
			s = "SetFromValue(";
			s.Append(variable);
			if (setError) {
				s.Append(", &_pidgen_err)");
			}
			else {
				s.Append(")");
			}
			return s;
		}
		else {
			s.Append(fromBV->ID());
			if (setError) {
				s.Append("(&_pidgen_err)");
			}
			else {
				s.Append("()");
			}
	
			if ((tn=="size_t") ||
					(tn=="char") ||
					(tn=="wchar32_t") ||
					(tn=="int8_t") ||
					(tn=="int16_t") ||
					(tn=="uint8_t") ||
					(tn=="uint16_t") ||
					(tn=="uint32_t") ||
					(tn=="uint64_t")) { 
				s.Prepend(")");
				s.Prepend(tn);
				s.Prepend("("); 
			}
			return s;
		}
	}
	else {	
		bout << "<----- outpututil.cpp -----> there is no function to marshall type=" << tn << endl; 
		_exit(1);
	}
	return NULL;

}