Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can one element (in path 1) pass some parameters to another element (in path2)? #194

Open
chuanic opened this issue May 18, 2015 · 4 comments

Comments

@chuanic
Copy link

chuanic commented May 18, 2015

PATH1: FromDevice -> Element1 -> ToDevice;
PATH2: FromDevice -> Element2 -> ToDevice;

Can element1 pass an parameter to element2??

@pallas
Copy link
Contributor

pallas commented May 18, 2015

Element2 can take a pointer to Element1 and extract the value itself.

@bcronje
Copy link
Contributor

bcronje commented May 18, 2015

To add an example of what @pallas is saying, one way to get this pointer:

    int MyElement::configure(Vector<String> &conf, ErrorHandler *errh)
    {
        String ename;

        if (Args(conf, this, errh)
                .read_m("ELEMENT", ename)
                .complete() < 0)
            return -1;

        MyOtherElement *myelem;
        if (Element* e = router()->find(ename, this)) {
            if (!(myelem = dynamic_cast<MyOtherElement *>(e))) {
                return errh->error("%s is not a MyOtherElement element", ename.c_str());
            }
        } else {
            return errh->error("%s does not name an element", ename.c_str());

        // Here myelem is a valid pointer to the MyOtherElement instance.

        return 0;
    }

And then in your click config file have something like:

FromDevice(eth0) -> myotherelement::MyOtherElement -> Discard;
FromDevice(eth1) -> myelement::MyElement(ELEMENT myotherelement) -> Discard;

@chuanic
Copy link
Author

chuanic commented May 19, 2015

First, i really appreciate your guys.

@bcronje Your way is take parameters from myotherelement. I want to pass parameters from myotherelement to myelement.

Maybe i should explain more particularly.
our purpose: MyOtherElement configure some parameters such as spi and rpl, and now MyElement can directly use these two parameters without include MyOtherElement or even more modify this mudole.

@chuanic
Copy link
Author

chuanic commented May 19, 2015

Thanks for your answering.

Now i have done this: myotherelement can pass myelement parameters (myotherelement not take parameters from myotherelement)

The part of source code is as below:

------------------------this is config-----------------------
01

------------------------this is MyOtherElement-----------------------
02

------------------------this is MyElement-----------------------
03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants