This file is indexed.

/usr/include/faust/gui/RosUI.h is in faust-common 0.9.95~repack1-2.

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
/**********************************************
* 			ROS User Interface
*
* This interface  creates default callbacks 
*	with default messages types
* It also returns parameters for specific ROS
*  callbacks, defined in the RosCallbacks class
*	thanks to the RosCI.h and ros-callbacks.cpp
* 	architecture files
**********************************************/
#ifndef FAUST_RosUI_H
#define FAUST_RosUI_H

#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif

#include "faust/gui/UI.h"
#include "ros/ros.h"
#include "std_msgs/Bool.h"
#include "std_msgs/Float32.h"

#include <algorithm>
#include <vector>

class RosUI : public UI
{
    
    public:
    
	RosUI(ros::NodeHandle nh, std::string nspace) : nh_(nh), queue_(10), count_(0), meta_(false), box_names_(0), zones_(0) 
	{
	   // Get the namespace's name for default topics
	   box_names_.push_back(nspace);
	};
	
	virtual ~RosUI() {}
	
	// String processing function for topics names
	std::string strProcess(std::string label)
    {
        int count = label.size();
        bool ok = false;
        int FORWARD_SLASH = 47;
        int TILDE = 126;
        int UNDERSCORE = 95;
        int SPACE = 32;
        int LEFT_BRACKET = 40;
        int RIGHT_BRACKET = 41;
        
        do
        {
            if ((label[0] < 65)  // before "A" in ASCII
                || (label[0] <= 96 && label[0] >= 91) // After "Z" and before "a" in ASCII
                || (label[0] > 122) // After "z" in ASCII
                && (label[0] != FORWARD_SLASH) // not "/"
                && (label[0] != TILDE) // not "~"
              )
            {
                label.erase(0,1);
                count = label.size();
            }
            else if(count <= 1)
            {
                label = "/topic";
                count = label.size();
                ok=true;
            }
            else
            {
                ok=true;
            }
        }
        while (!ok);

        for (int i=0; i < count; i++)
        {
            if ((label[i] <= 90 && label[i] >= 65) // A-Z
                    || (label[i] <= 122 && label[i] >= 97) // a-z
                    || (label[i] <= 57 && label[i] >= 47) // 0-9
                    || label[i] == UNDERSCORE 
               )
            {
            }
            else if (label[i] == SPACE) 
            {
                if(label[i-1] == UNDERSCORE)
                {
                    label.erase(i,1);
                    i=i-1;
                    count = label.size();
                }
                else
                    label[i] = '_';
            }

            else if(label[i] == LEFT_BRACKET) // in case of '('
            {
                if(label[i-1] == 95) 
                {
                    label.erase(i,1);
                    i=i-1;
                    count = label.size();
                }
                else		   
                    label[i] = '_';
            }
            else if (label[i] == RIGHT_BRACKET) // in case of ')'
            {
                label.erase(i,1);
                i=i-1;
                count = label.size();
            }
            else
            {
                label.erase(i, 1);
                i=i-1;
                count = label.size();
            }

        }
        return (label);
    }
	
	// -- default callbacks
	
	// Default Callbacks :
		// Buttons widgets use the std_msgs/Bool message type
		// Sliders and Numerical entries use the std_msgs/Float32 message type
	
	void buttonCallback(const std_msgs::BoolConstPtr& msg, FAUSTFLOAT* zone)
	{
	    *zone = msg->data;
	}
	
	void cButtonCallback(const std_msgs::BoolConstPtr& msg, FAUSTFLOAT* zone)
	{
	    *zone = msg->data;
	}
	
	void sliderCallback(const std_msgs::Float32ConstPtr& msg, FAUSTFLOAT* zone)
	{
	    *zone = msg->data;
	}
	
	void numEntryCallback(const std_msgs::Float32ConstPtr& msg, FAUSTFLOAT* zone)
	{
	    *zone = msg->data;
	}	
	
	// -- widget's layouts
		// Boxes names are stored in a vector so that the default topics names
		// fit to the graphic interface

	void openTabBox(const char* label)
	{
		std::string L = (std::string)label;
		if (L == "0x00") // no box name
		{
			L = "";
		}
	    
		box_names_.push_back(L);	    
	}
	
	void openHorizontalBox(const char* label)
	{
		std::string L = (std::string)label;
		if (L == "0x00") // no box name
		{
			L = "";
		}
	    
		box_names_.push_back(L);	    
	}
	
	void openVerticalBox(const char* label)
	{
		std::string L = (std::string)label;
		if (L == "0x00") // no box name
		{
			L = "";
		}
	    
		box_names_.push_back(L);	    
	}
	
	void closeBox()
	{
	    box_names_.pop_back();
	}

	// -- active widgets
    // Adding a widget is translated into subscribing to a topic
    // For each widget, we use default messages types
    // Buttons							: std_msgs/Bool
    // Sliders and Numerical Entries	: std_msgs/Float32

	void addButton(const char* label, FAUSTFLOAT* zone)
	{
	    // Gets the button name and processes it to fit to ROS naming conventions
	    std::string str = (std::string)label;
	    std::string my_string = strProcess(str);
	    
	    // Builds the topic name from boxes and button names
	    if (! box_names_.empty())
	    {
            std::string my_name = "";
		
			for (int i = 0; i<box_names_.size(); i++)
			{
			    if (box_names_[i] != "")
			    {
					my_name += "/" + strProcess(box_names_[i]); 
		    	}   
		    	else 
		    	{
					box_names_.erase(box_names_.begin()+i);
		    	}
			}
			
			my_string = my_name + "/" + my_string;
        }
	    else
	    {
	    	ROS_ERROR("RosUI.h - function addButton : No box name to use ! ");
	    	ROS_INFO("Button's callback will not be subscribed");
	    	return;
	    }
  		
  		// Subscription to buttons callback
	    ros::Subscriber* button_sub = new ros::Subscriber();
	    
	    *button_sub = nh_.subscribe<std_msgs::Bool>(my_string, queue_, 
	    boost::bind(&RosUI::buttonCallback, this, _1, zone));
	    
	    count_++;
	}
	void addCheckButton(const char* label, FAUSTFLOAT* zone)
	{
	    // Gets the check button name and processes it to fit to ROS naming conventions
	    std::string str = (std::string)label;
	    
	    std::string my_string = strProcess(str);
	    
	    // Builds the topic name from boxes and check button names
	    if (! box_names_.empty())
	    {
			std::string my_name = "";
		
			for (int i = 0; i<box_names_.size(); i++)
			{
			    if (box_names_[i] != "")
			    {
					my_name += "/" + strProcess(box_names_[i]); 
		    	}   
		    	else 
		    	{
					box_names_.erase(box_names_.begin()+i);
		    	}
			}
			
			my_string = my_name + "/" + my_string;
        }
	    else
	    {
	    	ROS_ERROR("RosUI.h - function addCheckButton : No box name to use ! ");
	    	ROS_INFO("Check button's callback will not be subscribed");
	    	return;
	    }
	    
	    // Subscription to check buttons callback
	    ros::Subscriber* c_button_sub = new ros::Subscriber();
	    
	    *c_button_sub = nh_.subscribe<std_msgs::Bool>(my_string, queue_, 
	    boost::bind(&RosUI::cButtonCallback, this, _1, zone));
	    
	    count_++;
	}
	void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min,
	FAUSTFLOAT max, FAUSTFLOAT step)
	{
	     // Gets the vertical slider name and processes it to fit to ROS naming conventions
	    std::string str = (std::string)label;
	    
	    std::string my_string = strProcess(str);
	    
	    // Builds the topic name from boxes and vertical slider names

	    if (! box_names_.empty())
	    {
			std::string my_name = "";
		
			for (int i = 0; i<box_names_.size(); i++)
			{
			    if (box_names_[i] != "")
			    {
					my_name += "/" + strProcess(box_names_[i]); 
			    }   
			    else 
			    {
					box_names_.erase(box_names_.begin()+i);
				}
			}
			
			my_string = my_name + "/" + my_string;
	    }
	    else
	    {
	    	ROS_ERROR("RosUI.h - function addVerticalSlider : No box name to use ! ");
	    	ROS_INFO("Vertical slider's callback will not be subscribed");
	    	return;
	    }
	    
	    // Subscription to sliders callback
	    ros::Subscriber* v_slider = new ros::Subscriber();
	    
	    *v_slider = nh_.subscribe<std_msgs::Float32>(my_string, queue_, 
	    boost::bind(&RosUI::sliderCallback, this, _1, zone));
	    
	    count_++;
	}
	void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, 
	FAUSTFLOAT max, FAUSTFLOAT step)
	{
	    // Gets the horizontal slider name and processes it to fit to ROS naming conventions
	    std::string str = (std::string)label;
	    std::string my_string = strProcess(str);
	    
	    // Builds the topic name from boxes and horizontal slider names	    
	    if (!box_names_.empty())
	    {
			std::string my_name = "";
		
			for (int i = 0 ; i<box_names_.size() ; i++)
			{
			    if (box_names_[i] != "")
			    {
					my_name += "/" + strProcess(box_names_[i]); 
		    	}   
		    	else 
		    	{
					box_names_.erase(box_names_.begin()+i);
		    	}
			}
			
			my_string = my_name + "/" + my_string;
	    }
	    else
	    {
	    	ROS_ERROR("RosUI.h - function addVerticalSlider : No box name to use ! ");
	    	ROS_INFO("Vertical slider's callback will not be subscribed");
	    	return;
	    }
	    
	    // Subscription to sliders callback
	    ros::Subscriber* h_slider = new ros::Subscriber();
	    
	    *h_slider = nh_.subscribe<std_msgs::Float32>
	    (my_string, queue_, boost::bind(&RosUI::sliderCallback, this, _1, zone));
	    
	    count_++;
	}
	void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, 
	FAUSTFLOAT max, FAUSTFLOAT step)
	{
	    // Gets the numerical entry name and processes it to fit to ROS naming conventions
	    std::string str = (std::string)label;
	    std::string my_string = strProcess(str);
	    
	    // Builds the topic name from boxes and numerical entry names
	    
	    if (! box_names_.empty())
	    {
			std::string my_name = "";
		
			for (int i = 0; i<box_names_.size(); i++)
			{
			    if (box_names_[i] != "")
		    	{
					my_name += "/" + strProcess(box_names_[i]); 
		    	}   
		    	else 
		    	{
					box_names_.erase(box_names_.begin()+i);
				}
			}
		
			my_string = my_name + "/" + my_string;
	    }
	    else
	    {
		    ROS_ERROR("RosUI.h - function addVerticalSlider : No box name to use ! ");
	    	ROS_INFO("Vertical slider's callback will not be subscribed");
	    	return;
	    }
	    
	    // Subscription to numerical entries callback
	    ros::Subscriber* num_entry = new ros::Subscriber();
	    *num_entry = nh_.subscribe<std_msgs::Float32>(my_string, queue_, 
	    boost::bind(&RosUI::numEntryCallback, this, _1, zone));
	    
		count_++;
 	}
	
	// -- passive widgets
    // Nothing to say - not used

	void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
	{}
	void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
	{}

	// -- metadata declarations

	void declare(FAUSTFLOAT* zone, const char* key, const char* val) 
	{
		if (key=="ros") // We do not care if key is not "ros" here
		{
			// Adds the Faust parameter's address (zone) to a zone vector
	    		// if a ros metadata has been declared
			zones_.push_back(zone);
		}
	}
    
    // Function returning the number of widgets added
	int getParamsCount()
	{
		return count_;
	}
	
	// Function saying if, yes or no, there is any ROS metadata declared
	bool isTrue()
    {
    	if (!zones_.empty())
    	{
    		return true; // yes
    	}
    	else
    	{
    		return false; // no
    	}
    }
	
	// Function returning the Faust parameters addresses (zones)
		// if these zones correspond to metadata declared topics
	std::vector<FAUSTFLOAT*> getZones()
	{
		return zones_;
	}
    
    private:
    
	ros::NodeHandle nh_;
	int queue_;
	int count_;
	bool meta_;
	
	std::vector<std::string> box_names_;
	std::vector<FAUSTFLOAT*> zones_;
};

#endif