summaryrefslogtreecommitdiff
path: root/devices/simple_dev/simple_dev.cpp
blob: 01f62c23484eb525a5f8d4e9c609a511cc9d5db5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <distrio_helper.h>
#include <distrio_error.h>

#include <distrio_ioI.h>

#include <iostream>

class My_device : public Distrio_Device_i {
	public:
		My_device (std::string name) { dev_name = name; }
		~My_device () { }

		::CORBA::Long id (void) {
			return dev_id;
		}
		void id (::CORBA::Long id) {
			dev_id = id;
		}
		::Distrio::Error *name (::CORBA::String_out _name) {
			_name = ::CORBA::string_dup (dev_name.c_str ());
			return distrio_success ();
		}
		::Distrio::Digital_list_var digitals;
	private:
		std::string dev_name;
		::CORBA::Long dev_id;
};

ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
	int ret = 0;
	My_device *dev;
	Distrio::Digital_ptr digital_io;

	if (init_corba (argc, argv))
		return -EINVAL;

	if (run_orb ())
		return -EINVAL;

	dev = new My_device ("simple_dev");

	if (register_device (dev)) {
		ret = -EINVAL;
		goto out;
	}

	std::cout << "registered id: " << dev->id () << std::endl;

	get_digital_list (&dev->digitals);
	lookup_digital ("pin huhu", dev->digitals, &digital_io);

	while (1)
	{
		try {
			digital_io->set ();
			sleep (1);
			digital_io->reset ();
			sleep (1);
		} catch (::CORBA::Exception *ex) {
			std::cerr << "sth went wrong " << ex << std::endl;
		}
	}

out:
	free (dev);
	return ret;
}