My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
main.c
Go to the documentation of this file.
1 /*
2 START OF LICENSE STUB
3  DeDOS: Declarative Dispersion-Oriented Software
4  Copyright (C) 2017 University of Pennsylvania, Georgetown University
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 END OF LICENSE STUB
19 */
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <getopt.h>
24 #include <pthread.h>
25 #include <string.h>
26 #include <libgen.h>
27 
28 #include "controller_stats.h"
29 #include "local_files.h"
30 #include "logging.h"
31 #include "controller_dfg.h"
32 #include "runtime_communication.h"
33 #include "cli.h"
34 #include "socket_interface.h"
35 #include "scheduling.h"
36 #include "dfg.h"
37 #include "dfg_reader.h"
38 #include "controller_mysql.h"
39 
40 #define FILENAME_LEN 32
41 
42 pthread_t cli_thread;
43 pthread_t sock_thread;
44 
45 static void print_usage() {
46  printf("Usage: global_controller -j /path/to/json [-o json_file] [-p dfg_out_port] [-c control_port]\n");
47 }
48 
49 int main(int argc, char *argv[]) {
50  set_local_directory(dirname(argv[0]));
51 
52  int option = 0;
53  char filename[FILENAME_LEN];
54  memset(filename, '\0', FILENAME_LEN);
55  char *output_filename = NULL;
56  int output_port = -1;
57  int control_port = -1;
58  bool db = false;
59  bool init_db = false;
60 
61  struct option longopts[] = {
62  {"db", no_argument, 0, 0 },
63  {"init-db", no_argument, 0, 0},
64  {NULL, 0, 0, 0}
65  };
66 
67  int opt_index;
68  while ((option = getopt_long(argc, argv,"j:o:p:c:", longopts, &opt_index)) != -1) {
69  switch (option) {
70  case 0:
71  if (strcmp(longopts[opt_index].name, "db") == 0) {
72  db = true;
73  } else if (strcmp(longopts[opt_index].name, "init-db") == 0) {
74  db = true;
75  init_db = true;
76  } else {
77  print_usage();
78  exit(EXIT_FAILURE);
79  }
80  break;
81  case 'j' : strcpy(filename, optarg);
82  break;
83  case 'o' : output_filename = optarg;
84  break;
85  case 'p' : output_port = atoi(optarg);
86  break;
87  case 'd' : init_db = true;
88  break;
89  case 'c' : control_port = atoi(optarg);
90  break;
91  default:
92  print_usage();
93  exit(EXIT_FAILURE);
94  }
95  }
96  if (strlen(filename) == 0) {
97  print_usage();
98  exit(EXIT_FAILURE);
99  }
100 
101  int rtn;
102 
103  rtn = init_dfg_lock();
104  if (rtn < 0) {
105  log_error("Error initializing DFG lock");
106  return -1;
107  }
108 
109  rtn = init_controller_dfg(filename);
110  if (rtn < 0) {
111  log_error("Error loading dfg!");
112  return -1;
113  }
114 
115  if (db) {
116  rtn = db_init(init_db);
117  if (rtn < 0) {
118  log_error("Error setting up mysql DB!");
119  return -1;
120  }
121  }
122 
123  rtn = init_statistics();
124 
125  if (rtn < 0) {
126  log_error("Error initializing statistics");
127  return -1;
128  }
129  int port = local_listen_port();
130 
131  //const char *policy = "greedy";
132  //init_scheduler(policy);
133 
136  runtime_communication_loop(port, output_filename, output_port);
137  //start_communication(tcp_control_listen_port, output_filename);
138 
139  pthread_join(cli_thread, NULL);
140 
141 
142  return 0;
143 }
int main(int argc, char **argv)
Entry point to start the runtime.
Definition: main.c:49
int init_dfg_lock()
int runtime_communication_loop(int listen_port, char *output_file, int output_port)
Logging of status messages to the terminal.
Access local files within the repo.
const char * name
Definition: http_parser.c:485
int local_listen_port()
pthread_t sock_thread
Definition: main.c:43
#define log_error(fmt,...)
Definition: logging.h:101
Declares function for converting JSON to dedos_dfg.
int set_local_directory(char *dir)
Sets the directory of the executable so we can get relaitve paths.
Definition: local_files.c:33
int init_statistics()
Initializes the entire stats module.
Definition: rt_stats.c:783
int db_init(int clear)
Initialize the MySQL client library, and connect to the server Also init tables for running system...
int start_cli_thread(pthread_t *cli_thread)
Definition: cli.c:568
void init_db(char *ip, int port, int n_files)
Definition: dbops.c:79
static void print_usage()
Definition: main.c:45
int init_controller_dfg(char *filename)
Interfaces for the creation and modification of the data-flow-graph and and general description of th...
pthread_t cli_thread
Definition: main.c:42
#define FILENAME_LEN
Definition: main.c:40
int start_socket_interface_thread(pthread_t *thread, int port)