forked from Swarm-IITKgp/SimpleSwarmSimulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Simulator.cpp
66 lines (58 loc) · 1.32 KB
/
Simulator.cpp
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
#include <bits/stdc++.h>
#include <pthread.h>
#include <cstring>
#include "SwarmBot.h"
using namespace std;
#define NUM_THREADS 100
int botCount=0;
void* display(void *data){
system("./Output");
pthread_exit(NULL);
}
void* algo(void *data){
string param=*((string *)data);
system(param.c_str());
pthread_exit(NULL);
}
int main(int argc, char** argv){
system("./Start");
if(argc>=2){
string s = argv[2];
if(!s.compare("dest-screen"))
system("./dest");
else if(!s.compare("circle")){
cout<<"INSIDE\n";
system("./circle");
}
}
pthread_t disp_thread;
int rc=pthread_create(&disp_thread,NULL,display,NULL);
if (rc){
cout << "Error:unable to create thread," << rc << endl;
exit(-1);
}
string exec="./";
string s=exec+argv[1];
pthread_t threads[NUM_THREADS];
string ar[NUM_THREADS];
FILE *fp;
SwarmBot v;
int i=0;
fp=fopen("POSE.txt","rb");
if(fp){
while(fread(&v,sizeof(SwarmBot),1,fp) != 0){
string temp_s;
string int_string=to_string(v.BotID);
temp_s=s+" "+int_string;
ar[i]=temp_s;
rc=pthread_create(&threads[i],NULL,algo,(void *)&(ar[i]));
if (rc){
cout << "Error:unable to create thread," << rc << " for Bot ID "<<v.BotID<<endl;
}
i++;
}
fclose(fp);
}
pthread_exit(NULL);
return 0;
}