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

Add C++ client #1

Merged
merged 1 commit into from
Feb 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ ERROR: API_EventTimeout
2020-02-14 23:48:36.249320 TEST/DEVICE2/1 ATTR1 IDL5_CHANGE [ATTR_VALID] 0.0
ERROR: API_EventTimeout
```

Alternatively build and run the C++ client:
1. `g++ client1.cpp -o client1 -I/usr/include/tango -ltango -lzmq -lomniORB4 -lomnithread -lCOS4 -lomniDynamic4 -g`
2. `./client1`
59 changes: 59 additions & 0 deletions client1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <tango.h>
#include <unistd.h>

using namespace Tango;

class EventCallBack: public Tango::CallBack {
public:
void push_event(Tango::EventData* event) {
if (event->err) {
Tango::Except::print_error_stack(event->errors);
} else {
std::cout << "event: " << event->attr_name << " " << event->event << std::endl;
}

};
};

class CB: public Tango::CallBack {
public:
CB(DeviceProxy* dev, int id):
dev(dev), id(id)
{};

void push_event(Tango::EventData* event) {
if (event->err) {
Tango::Except::print_error_stack(event->errors);
} else {
dev->unsubscribe_event(id);
std::cout << "unsubscribed " << id << std::endl;
}

};
int id;
Tango::DeviceProxy * dev;
};

int main(unsigned int argc, char **argv)
{

Tango::DeviceProxy *dev1 = new Tango::DeviceProxy("test/device1/1");
Tango::DeviceProxy *dev2 = new Tango::DeviceProxy("test/device2/1");

sleep(1);
int id = dev1->subscribe_event(
"attr1", Tango::EventType::ATTR_CONF_EVENT, new EventCallBack()
);
sleep(1);

dev2->subscribe_event(
"attr1", Tango::EventType::CHANGE_EVENT, new EventCallBack()
);

CB * cb = new CB(dev1, id);
dev2->subscribe_event(
"attr2", Tango::EventType::CHANGE_EVENT, cb
);

sleep(30);
};