Pregunta

i'm working Android App use Alljoyn framework and i have some prolem

i have a custom object

public class Package implements BusObject {


    public static enum DataSendType {
        TEXT,IMAGE
    }

    public static enum PackageStatus {
        NONE, SENDING, DONE
    }

    @Signature("s")
    private String m_id;
    @Signature("a")
    private ArrayList<DataPackage> m_listPackage;
    @Signature("r")
    private PackageStatus m_status;
    @Signature("r")
    private DataSendType m_type;
    @Signature("s")
    private String m_packageName;
}

and interface

@BusInterface (name="xxxx.simpleinterface")
public interface SimpleInterface {

    @BusSignal (name="Chat", signature="o")
    public void Chat(Package message) throws BusException;
}

but i get this error cannot marshal class Package into 'o' when use Chat(Package)..

pls help me, because i can't get this error out for 2 weeks.

sorry because my English is too bad :)

¿Fue útil?

Solución

looking at your code it looks like what you are trying to send is a struct the signature for a struct should be "r" or the actual signature surrounded by parenthesizes ( and ). i.e. for Package the signature would be "(sayiis)"

  • With AllJoyn you can send an array but not an ArrayList and you must specify the type of data that is in the array.
  • Since your DataSendType specified TEXT or IMAGE I made the assumption that you want to send an array of bytes.
  • Most of the items I did not add a signature to because AllJoyn can figure out the signature using reflection. AllJoyn however does not know that enums will be transmitted as integers so I did have to specify the signature for the enums.
  • Package did not have to implement BusObject. In your code when you implement your SimpleInterface that should extend the SimpleInterface and `BusObject'
  • Anything sent using AllJoyn should be public so the interface can read the member variables.

    public class Package {
        public static enum DataSendType{
            TEXT,
            IMAGE
        }
    
        public static enum PackageStatus {
            NONE,
            SENDING,
            DONE
        }
    
        @Position(0)
        public String m_id;
        @Position(1)
        public byte[] m_listPackage;
        @Position(2)
        @Signature("i")
        public PackageStatus m_status;
        @Position(3)
        @Signature("i")
        public DataSendType m_type;
        @Position(4)
        public String m_packageName;
    }
    

for the interface the signature should be "r" for struct the signature "o" means object path. This is an AllJoyn object path which means it just a string with path data.

@BusInterface (name="xxxx.simpleinterface")
public interface SimpleInterface {

    @BusSignal (name="Chat", signature="r")
    public void Chat(Package message) throws BusException;
}

If you really need to use an ArrayList convert the ArrayList to an actual array before sending the Chat signal.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top