Writing a plugin framework for Nios II

Hi all,

I would like to develop an application for a Nios II core that will allow me to dynamically load and link to a variety of plugin modules. The host application will have no knowledge of what plugins it will have access to until run-time. The plugins will however share a simple common interface allowing the plugin to be called through its interface, passing it a pointer, and perhaps returning a pointer. The ability to implement some kind of call-back would be a bonus!

I have done this kind of thing in C#, where it is quite a bit easier!! But I am a bit out of my depth here.

At the core of it I want to load a compiled class into memory, and create a pointer to it, kowing that it has the same interface as a virtual class in my application. My application will provide an XML postal service to all the plugins loaded.

I don't know quite where to start, and am missing some key points of c++ and how it is compiled:

What does a pointer to a class actually point to?
How do I compile a simgle class in the NIOS IDE that I can dynamically load?
Do I need a third party RTOS?
Can what I am trying to do, be done?

Thanks

James

Comments

  • :
    : What does a pointer to a class actually point to?
    :

    I'm affraid this is the only question I can answer.

    The pointer to a class points to a structure in memory, starting with a vtable (virtual table - an array of function pointers to the appropriate virtual function for the instance), and then the member data in a certain order (base classes first, derived class members last).

    For a bit of extra information on virtual pointers, here's an example (Visual C++ .NET):
    [code]
    class A
    {
    private:
    int mNumber;

    public:
    A(int number)
    { mNumber = number; }

    virtual void printNumber()
    {
    Console::WriteLine( mNumber );
    }
    };

    class B : public A
    {
    private:
    int mBNumber;

    public:
    B(int number) : A(number + 1)
    {
    mBNumber = number;
    }

    virtual void printNumber()
    {
    Console::WriteLine(mBNumber);
    }
    };


    int main(array ^args)
    {
    A a(0);
    B b(0);
    A* pA; B* pB;

    a.printNumber();
    (pA = &a)->printNumber();

    b.printNumber();
    (pB = &b)->printNumber();
    (pA = &b)->printNumber();
    pA->A::printNumber();

    Console::Read();
    return 0;
    }
    [/code]
    The output result is:
    [code]
    0
    0
    0
    0
    0
    1
    [/code]
    So while you have that [italic]b[/italic]'s A::mNumber is 1, pA->printNumber() will look up the entry in the vtable, and find an address that points to B::printNumber().

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion