This file is indexed.

/usr/include/comedilib.hpp is in libcomedi-dev 0.10.1-1ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
/*
	A C++ binding for comedilib.  Requires the Boost C++ libraries.
	Copyright (C) 2006-2007  Frank Mori Hess <fmhess@users.sourceforge.net>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef _COMEDILIB_WRAPPER_HPP
#define _COMEDILIB_WRAPPER_HPP

#include <boost/shared_ptr.hpp>
#include <comedilib.h>
#include <cstring>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>

namespace comedi
{
	class subdevice;

	// wrapper for comedi_to_physical()
	class to_physical
	{
	public:
		to_physical()
		{
			memset(&_polynomial, 0, sizeof(_polynomial));
		}
		to_physical(const comedi_polynomial_t &polynomial):
			_polynomial(polynomial)
		{}
		double operator()(lsampl_t data) const
		{
			return comedi_to_physical(data, &_polynomial);
		}
	private:
		comedi_polynomial_t _polynomial;
	};

	// wrapper for comedi_from_physical()
	class from_physical
	{
	public:
		from_physical()
		{
			memset(&_polynomial, 0, sizeof(_polynomial));
		}
		from_physical(const comedi_polynomial_t &polynomial):
			_polynomial(polynomial)
		{}
		lsampl_t operator()(double physical_value) const
		{
			return comedi_from_physical(physical_value, &_polynomial);
		}
	private:
		comedi_polynomial_t _polynomial;
	};

	class device	{
	public:
		device() {}
		device(const std::string &device_file)
		{
			this->open(device_file);
		}
		std::string board_name() const
		{
			const char *name = comedi_get_board_name(comedi_handle());
			if(name == 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_board_name() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_board_name");
				throw std::runtime_error(message.str());
			}
			return name;
		}
		int command_test(comedi_cmd *cmd) const
		{
			int retval = comedi_command_test(comedi_handle(), cmd);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_command_test() returned error.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_command_test");
				throw std::runtime_error(message.str());
			}
			return retval;
		}
		void command(comedi_cmd *cmd) const
		{
			int retval = comedi_command(comedi_handle(), cmd);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_command() failed, return value=" << retval << " .";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_command");
				throw std::runtime_error(message.str());
			}
		}
		std::string default_calibration_path() const
		{
			char *c_string_file_path = comedi_get_default_calibration_path(comedi_handle());
			if(c_string_file_path == NULL)
			{
				comedi_perror("comedi_get_default_calibration_path");
				throw std::runtime_error(__PRETTY_FUNCTION__);
			}
			std::string file_path = c_string_file_path;
			free(c_string_file_path);
			return file_path;
		}
		void do_insn(comedi_insn *instruction) const
		{
			int retval = comedi_do_insn(comedi_handle(), instruction);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_do_insn() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_do_insn");
				throw std::runtime_error(message.str());
			}
		}
		std::string driver_name() const
		{
			const char *name = comedi_get_driver_name(comedi_handle());
			if(name == 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_driver_name() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_driver_name");
				throw std::runtime_error(message.str());
			}
			return name;
		}
		inline subdevice find_subdevice_by_type(int type, const subdevice *start_subdevice = 0) const;
		int fileno() const
		{
			int fd = comedi_fileno(comedi_handle());
			if(fd < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_fileno() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_fileno");
				throw std::runtime_error(message.str());
			}
			return fd;
		}
		unsigned n_subdevices() const
		{
			int retval = comedi_get_n_subdevices(comedi_handle());
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_n_subdevices() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_n_subdevices");
				throw std::runtime_error(message.str());
			}
			return retval;
		}
		void open(const std::string &device_file)
		{
			comedi_t *dev = comedi_open(device_file.c_str());
			if(dev == 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_open() failed, with device file name: \"" << device_file << "\".";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_open");
				throw std::runtime_error(message.str().c_str());
			}
			_comedi_handle.reset(dev, &comedi_close);
		}
	private:
		friend class subdevice;

		comedi_t* comedi_handle() const
		{
			if(_comedi_handle == 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": device not open.";
				std::cerr << message.str() << std::endl;
				throw std::invalid_argument(message.str());
			}
			return _comedi_handle.get();
		}

		boost::shared_ptr<comedi_t> _comedi_handle;
	};

	class calibration
	{
	public:
		calibration() {}
		calibration(const device &dev)
		{
			init(dev.default_calibration_path());
		}
		calibration(const std::string &file_path)
		{
			init(file_path);
		}
		const comedi_calibration_t* c_calibration() const
		{
			return _c_calibration.get();
		}
	private:
		void init(const std::string &file_path)
		{
			comedi_calibration_t *cal = comedi_parse_calibration_file(file_path.c_str());
			if(cal == NULL)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_parse_calibration_file() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_parse_calibration_file");
				throw std::runtime_error(message.str());
			}
			_c_calibration.reset(cal, &comedi_cleanup_calibration);
		}
		boost::shared_ptr<comedi_calibration_t> _c_calibration;
	};

	class subdevice
	{
	public:
		subdevice(): _index(-1)
		{}
		subdevice(const device &dev, unsigned subdevice_index):
			_device(dev), _index(subdevice_index)
		{
			if(_index >= _device.n_subdevices())
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": invalid subdevice index.";
				std::cerr << message.str() << std::endl;
				throw std::invalid_argument(message.str());
			}
		}
		void apply_hard_calibration(unsigned channel, unsigned range, unsigned aref, const calibration &cal)
		{
			if(cal.c_calibration() == 0) throw std::invalid_argument(__PRETTY_FUNCTION__);
			int retval = comedi_apply_parsed_calibration(comedi_handle(), index(),
				channel, range, aref, cal.c_calibration());
			if(retval < 0)
			{
				comedi_perror("comedi_apply_parsed_calibration");
				throw std::runtime_error(__PRETTY_FUNCTION__);
			}
		}
		void apply_hard_calibration(unsigned channel, unsigned range, unsigned aref)
		{
			apply_hard_calibration(channel, range, aref, calibration(dev()));
		}
		unsigned buffer_size() const
		{
			int retval = comedi_get_buffer_size(comedi_handle(), index());
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_buffer_size() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_buffer_size");
				throw std::runtime_error(message.str());
			}
			return retval;
		}
		void cancel()
		{
			int retval = comedi_cancel(comedi_handle(), index());
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_cancel() failed, return value=" << retval << " .";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_cancel");
				throw std::runtime_error(message.str());
			}
		}
		lsampl_t data_read(unsigned channel, unsigned range, unsigned aref) const
		{
			lsampl_t value;
			int retval = comedi_data_read(comedi_handle(), index(), channel, range, aref, &value);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_data_read() failed, return value=" << retval << " .";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_data_read");
				throw std::runtime_error(message.str());
			}
			return value;
		}
		std::vector<lsampl_t> data_read_n(unsigned channel, unsigned range, unsigned aref, unsigned num_samples) const
		{
			std::vector<lsampl_t> values(num_samples);
			int retval = comedi_data_read_n(comedi_handle(), index(), channel, range, aref, &values.at(0), values.size());
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_data_read_n() failed, return value=" << retval << " .";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_data_read_n");
				throw std::runtime_error(message.str());
			}
			return values;
		}
		void data_read_hint(unsigned channel, unsigned range, unsigned aref) const
		{
			int ret = comedi_data_read_hint(comedi_handle(), index(), channel, range, aref);
			if(ret < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_data_read_hint() failed, return value = " << ret << " .";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_data_read_hint");
				throw std::runtime_error(message.str());
			}
		}
		void data_write(unsigned channel, unsigned range, unsigned aref, lsampl_t data) const
		{
			int retval = comedi_data_write(comedi_handle(), index(), channel, range, aref, data);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_data_write() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_data_write");
				throw std::runtime_error(message.str());
			}
		}
		device dev() const {return _device;}
		void dio_bitfield2(unsigned write_mask, unsigned *bits, unsigned base_channel)
		{
			int retval = comedi_dio_bitfield2(comedi_handle(), index(),
				write_mask, bits, base_channel);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_dio_bitfield2() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_dio_bitfield2");
				throw std::runtime_error(message.str());
			}
		}
		void dio_config(unsigned channel, enum comedi_io_direction direction)
		{
			int retval = comedi_dio_config(comedi_handle(), index(), channel, direction);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_dio_config() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_dio_config");
				throw std::runtime_error(message.str());
			}
		}
		unsigned find_range(unsigned channel, unsigned unit, double min, double max)
		{
			int retval = comedi_find_range(comedi_handle(), index(), channel,
				unit, min, max);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_find_range() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_find_range");
				throw std::runtime_error(message.str());
			}
			return retval;
		}
		unsigned flags() const
		{
			int retval = comedi_get_subdevice_flags(comedi_handle(), index());
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_subdevice_flags() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_subdevice_flags");
				throw std::runtime_error(message.str());
			}
			return retval;
		}
		unsigned get_buffer_contents() const
		{
			int retval = comedi_get_buffer_contents(comedi_handle(), index());
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_buffer_contents() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_buffer_contents");
				throw std::runtime_error(message.str());
			}
			return retval;
		}
		void get_clock_source(unsigned channel, unsigned *clock, unsigned *period_ns) const
		{
			int retval = comedi_get_clock_source(comedi_handle(), index(), channel, clock, period_ns);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_clock_source() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_clock_source");
				throw std::runtime_error(message.str());
			}
		}
		void get_gate_source(unsigned channel, unsigned gate_index, unsigned *gate_source)
		{
			int retval = comedi_get_gate_source(comedi_handle(), index(), channel, gate_index, gate_source);
			if (retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_gate_source() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_gate_source");
				throw std::runtime_error(message.str());
			}
		}
		unsigned get_routing(unsigned channel) const
		{
			unsigned routing = 0;
			int retval = comedi_get_routing(comedi_handle(), index(), channel, &routing);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_routing() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_routing");
				throw std::runtime_error(message.str());
			}
			return routing;
		}
		comedi_polynomial_t hardcal_converter(unsigned channel, unsigned range,
			enum comedi_conversion_direction direction) const
		{
			comedi_polynomial_t result;
			int retval = comedi_get_hardcal_converter(comedi_handle(), index(),
				channel, range, direction, &result);
			if(retval < 0)
			{
				comedi_perror("comedi_get_hardcal_converter");
				throw std::runtime_error(__PRETTY_FUNCTION__);
			}
			return result;
		}
		unsigned hardware_buffer_size(enum comedi_io_direction direction) const
		{
			int retval = comedi_get_hardware_buffer_size(comedi_handle(), index(), direction);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_hardware_buffer_size() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_hardware_buffer_size");
				throw std::runtime_error(message.str());
			}
			return retval;
		}
		unsigned index() const {return _index;};
		void internal_trigger(unsigned trig_num) const
		{
			int retval = comedi_internal_trigger(comedi_handle(), index(), trig_num);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_internal_trigger() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_internal_trigger");
				throw std::runtime_error(message.str());
			}
		}
		unsigned max_buffer_size() const
		{
			int retval = comedi_get_max_buffer_size(comedi_handle(), index());
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_max_buffer_size() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_max_buffer_size");
				throw std::runtime_error(message.str());
			}
			return retval;
		}
		unsigned n_channels() const
		{
			int retval = comedi_get_n_channels(comedi_handle(), index());
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_n_channels() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_n_channels");
				throw std::runtime_error(message.str());
			}
			return retval;
		}
		unsigned n_ranges(unsigned channel = 0) const
		{
			int retval = comedi_get_n_ranges(comedi_handle(), index(), channel);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_n_ranges() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_n_ranges");
				throw std::runtime_error(message.str());
			}
			return retval;
		}
		lsampl_t max_data(unsigned channel = 0) const
		{
			lsampl_t value = comedi_get_maxdata(comedi_handle(), index(), channel);
			if(value == 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_maxdata() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_maxdata");
				throw std::runtime_error(message.str());
			}
			return value;
		}
		const comedi_range* range(unsigned channel, unsigned range_index) const
		{
			comedi_range *cRange = comedi_get_range(comedi_handle(), index(), channel, range_index);
			if(cRange == 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_range() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_range");
				throw std::runtime_error(message.str());
			}
			return cRange;
		}
		void reset() const
		{
			int retval = comedi_reset(comedi_handle(), index());
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_reset() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_reset");
				throw std::runtime_error(message.str());
			}
		}
		void set_buffer_size(unsigned num_bytes) const
		{
			int retval = comedi_set_buffer_size(comedi_handle(), index(), num_bytes);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_set_buffer_size() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_set_buffer_size");
				throw std::runtime_error(message.str());
			}
		}
		void set_clock_source(unsigned channel, unsigned clock, unsigned period_ns)
		{
			int retval = comedi_set_clock_source(comedi_handle(), index(), channel, clock, period_ns);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_set_clock_source() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_set_clock_source");
				throw std::runtime_error(message.str());
			}
		}
		void set_counter_mode(unsigned channel, unsigned mode_bits)
		{
			int retval = comedi_set_counter_mode(comedi_handle(), index(), channel, mode_bits);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_set_counter_mode() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_set_counter_mode");
				throw std::runtime_error(message.str());
			}
		}
		void set_gate_source(unsigned channel, unsigned gate_index, unsigned gate_source)
		{
			int retval = comedi_set_gate_source(comedi_handle(), index(), channel, gate_index, gate_source);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_set_gate_source() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_set_gate_source");
				throw std::runtime_error(message.str());
			}
		}
		void set_max_buffer_size(unsigned num_bytes) const
		{
			int retval = comedi_set_max_buffer_size(comedi_handle(), index(), num_bytes);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_set_max_buffer_size() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_set_max_buffer_size");
				throw std::runtime_error(message.str());
			}
		}
		void set_routing(unsigned channel, unsigned routing)
		{
			int retval = comedi_set_routing(comedi_handle(), index(), channel, routing);
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_set_routing() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_set_routing");
				throw std::runtime_error(message.str());
			}
		}
		comedi_polynomial_t softcal_converter(unsigned channel, unsigned range,
			enum comedi_conversion_direction direction, const calibration &cal) const
		{
			if(cal.c_calibration() == 0) throw std::invalid_argument(__PRETTY_FUNCTION__);
			comedi_polynomial_t result;
			int retval = comedi_get_softcal_converter(index(),
				channel, range, direction, cal.c_calibration(), &result);
			if(retval < 0)
			{
				comedi_perror("comedi_get_softcal_converter");
				throw std::runtime_error(__PRETTY_FUNCTION__);
			}
			return result;
		}
		comedi_subdevice_type subdevice_type() const
		{
			int retval = comedi_get_subdevice_type(comedi_handle(), index());
			if(retval < 0)
			{
				std::ostringstream message;
				message << __PRETTY_FUNCTION__ << ": comedi_get_subdevice_type() failed.";
				std::cerr << message.str() << std::endl;
				comedi_perror("comedi_get_subdevice_type");
				throw std::runtime_error(message.str());
			}
			return comedi_subdevice_type(retval);
		}
	private:
		comedi_t* comedi_handle() const {return dev().comedi_handle();}

		device _device;
		unsigned _index;
	};

	subdevice device::find_subdevice_by_type(int type, const subdevice *start_subdevice) const
	{
		unsigned start_index;
		if(start_subdevice) start_index = start_subdevice->index() + 1;
		else start_index = 0;
		int subdev = comedi_find_subdevice_by_type(comedi_handle(), type, start_index);
		if(subdev < 0)
		{
			std::ostringstream message;
			message << __PRETTY_FUNCTION__ << ": failed to find subdevice of type " << type << " .";
			std::cerr << message.str() << std::endl;
			comedi_perror("comedi_find_subdevice_by_type");
			throw std::runtime_error(message.str());
		}
		return subdevice(*this, subdev);
	}
};

#endif	// _COMEDILIB_WRAPPER_HPP