Example #1
0
/*!
 * \internal
 * \brief Peek at channel before it is pushed into bridge
 * \since 13.2.0
 *
 * \param self Bridge to operate upon.
 * \param bridge_channel Bridge channel to push.
 * \param swap Bridge channel to swap places with if not NULL.
 *
 * \note On entry, self is already locked.
 *
 * \retval 0 on success.
 * \retval -1 on failure.  The channel should not be pushed.
 */
static int bridge_stasis_push_peek(struct ast_bridge *self, struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap)
{
    struct stasis_app_control *swap_control;
    struct ast_channel_snapshot *to_be_replaced;

    if (!swap) {
        goto done;
    }

    swap_control = stasis_app_control_find_by_channel(swap->chan);
    if (!swap_control) {
        ast_log(LOG_ERROR,"Failed to find stasis app control for swapped channel %s\n", ast_channel_name(swap->chan));
        return -1;
    }
    to_be_replaced = ast_channel_snapshot_get_latest(ast_channel_uniqueid(swap->chan));

    ast_debug(3, "Copying stasis app name %s from %s to %s\n", app_name(control_app(swap_control)),
              ast_channel_name(swap->chan), ast_channel_name(bridge_channel->chan));

    ast_channel_lock(bridge_channel->chan);

    /* copy the app name from the swap channel */
    app_set_replace_channel_app(bridge_channel->chan, app_name(control_app(swap_control)));

    /* set the replace channel snapshot */
    app_set_replace_channel_snapshot(bridge_channel->chan, to_be_replaced);

    ast_channel_unlock(bridge_channel->chan);

    ao2_ref(swap_control, -1);
    ao2_cleanup(to_be_replaced);

done:
    return ast_bridge_base_v_table.push_peek(self, bridge_channel, swap);
}
Example #2
0
static int is_list_tests(int argc, char *argv[], unit_test_t *tests)
{
	int i, size = tests->size;
	char *list_comment = tests->list_comment;
	test_t *arr = tests->arr;

	if (argc != 2 || strcmp(argv[1], "list"))
		return 0;

	p_colour(C_HIGHLIGHT, "%s unit tests%s%s%s\n", app_name(argv[0]),
		list_comment ? " (" : "", list_comment ? list_comment : "",
		list_comment ? ")" : "");
	for (i = 0; i < size - 1; i++) {
		test_t *t = &arr[i];
		int is_disabled = UT_DISABLED(tests, t);

		printf("%i. ", i + 1);
		p_colour(is_disabled ? C_GREY : C_NORMAL, "%s",
				t->description);
		if (is_disabled) {
			p_colour(C_CYAN, " (disabled)");
		}
		else if (t->known_issue) {
			p_colour(C_BLUE, " (known issue: ");
			p_colour(C_GREY, t->known_issue);
			p_colour(C_BLUE, ")");
		}
		printf("\n");
	}

	return 1;
}
Example #3
0
void do_scene_detection(GtkWidget *w, GtkFileSelection *fs)
{
	char *lav2yuv_command[256];
	char temp1[256], temp2[256];
	int n=0,i;

	lav2yuv_command[n] = app_name(LAV2YUV_S); n++;
	lav2yuv_command[n] = "-v2"; n++;
	lav2yuv_command[n] = "-D"; n++;
	sprintf(temp1, "%d", scene_detection_width_decimation);
	lav2yuv_command[n] = temp1; n++;
	lav2yuv_command[n] = "-T"; n++;
	sprintf(temp2, "%d", scene_detection_treshold);
	lav2yuv_command[n] = temp2; n++;
	lav2yuv_command[n] = "-S"; n++;
	sprintf(eli_file,
		gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)));
	lav2yuv_command[n] = eli_file; n++;

	for(i=0;i<current_file;i++)
	{
		lav2yuv_command[n] = files_recorded[i]; n++;
	}

	lav2yuv_command[n] = NULL;

	create_scene_detection_window();
	start_pipe_command(lav2yuv_command, LAV2YUV_S); /* lav2yuv */
}
Example #4
0
int main(int /* argc */, char *argv[])
{
  std::string app_name(argv[0]);
  unsigned short port_number(via::comms::tcp_adaptor::DEFAULT_HTTP_PORT);
  std::cout << app_name << ": " << port_number << std::endl;

  try
  {
    // The asio io_service.
    ASIO::io_service io_service;

    // Create the HTTP server, attach the request handler
    http_server_type http_server(io_service);
    http_server.request_received_event(request_handler);

    // Accept IPV4 connections on the default port (80)
    ASIO_ERROR_CODE error(http_server.accept_connections());
    if (error)
    {
      std::cerr << "Error: "  << error.message() << std::endl;
      return 1;
    }

    // Start the server
    io_service.run();
  }
  catch (std::exception& e)
  {
    std::cerr << "Exception:"  << e.what() << std::endl;
    return 1;
  }

  return 0;
}
int main(int argc, char *argv[])
{
  std::string app_name(argv[0]);

  // Get a hostname and uri from the user (assume default http port)
  if (argc != 3)
  {
    std::cout << "Usage: " << app_name << " [host] [uri]\n"
              << "E.g. "   << app_name << " localhost /hello"
              << std::endl;
    return 1;
  }

  std::string host_name(argv[1]);
  uri = argv[2];
  std::cout << app_name <<" host: " << host_name
            << " uri: " << uri << std::endl;
  try
  {
    // The asio io_service.
    boost::asio::io_service io_service;

    // Create an http_client and attach the response & chunk handlers
    http_client =
        https_client_type::create(io_service, response_handler, chunk_handler);

    // attach optional handlers
    http_client->connected_event(connected_handler);
    http_client->disconnected_event(disconnected_handler);

    // Set up SSL
    std::string certificate_file = "cacert.pem";
    boost::asio::ssl::context& ssl_context
       (https_client_type::connection_type::ssl_context());
    ssl_context.load_verify_file(certificate_file);

    // attempt to connect to the host on the standard https port (443)
    if (!http_client->connect(host_name, "https"))
    {
      std::cout << "Error, could not resolve host: " << host_name << std::endl;
      return 1;
    }

    // run the io_service to start communications
    io_service.run();

    std::cout << "io_service.run complete, shutdown successful" << std::endl;
  }
  catch (std::exception& e)
  {
    std::cerr << "Exception:"  << e.what() << std::endl;
  }

  return 0;
}
Example #6
0
std::string
MooseApp::libNameToAppName(const std::string & library_name) const
{
  std::string app_name(library_name);

  // Strip off the leading "lib" and trailing ".la"
  if (pcrecpp::RE("lib(.+?)(?:-\\w+)?\\.la").Replace("\\1", &app_name) == 0)
    mooseError("Invalid library name: " << app_name);

  return MooseUtils::underscoreToCamelCase(app_name, true);
}
Example #7
0
error_code replication_service_app::start(int argc, char** argv)
{
    replication_options opts;
    std::string app_name(argv[0]); 
    
    opts.initialize();    
    opts.working_dir = utils::filesystem::path_combine(opts.working_dir, app_name);

    _stub = new replica_stub();
    _stub->initialize(opts);
    _stub->open_service();
    return ERR_OK;
}
Example #8
0
static void test_usage(char *path)
{
	char *app = app_name(path);

	printf("usage:\n"
		"%s               - run all tests\n"
		"  or\n"
		"%s <test>        - run a specific test\n"
		"  or\n"
		"%s <from> <to>   - run a range of tests\n"
		"  or\n"
		"%s list          - list all tests\n",
		app, app, app, app);
}
void CTableFieldChooser::setCaption(const QString &s)
{
  if (QDockWindow::caption() == s)
    return;

  if (myApp()->isMDI())
    QDockWindow::setCaption(s);
  else
  {
    QString app_name(SHORT_NAME);
    app_name += " - ";
    if (s.startsWith(app_name))
      QDockWindow::setCaption(s);
    else
      QDockWindow::setCaption(app_name + s);
  }
}
Example #10
0
int main(int argc, char *argv[])
{
  std::string app_name(argv[0]);
  unsigned short port_number(via::comms::tcp_adaptor::DEFAULT_HTTP_PORT);

  // Get a port number from the user (the default is 80)
  if (argc > 2)
  {
    std::cerr << "Usage: " << app_name << " [port number]\n"
              << "E.g. "   << app_name << " " << port_number
              << std::endl;
    return 1;
  }
  else if (argc == 2)
  {
    std::string port(argv[1]);
    port_number = atoi(port.c_str());
  }

  std::cout << app_name << ": " << port_number << std::endl;

  try
  {
    // create an io_service for the server
    ASIO::io_service io_service;

    // create an http_server and connect the request handler
    http_server_type http_server(io_service);
    http_server.request_received_event(request_handler);

    // connect the optional handler callback functions
    http_server.chunk_received_event(chunk_handler);
    http_server.request_expect_continue_event(expect_continue_handler);
    http_server.invalid_request_event(invalid_request_handler);
    http_server.socket_connected_event(connected_handler);
    http_server.socket_disconnected_event(disconnected_handler);
    http_server.message_sent_event(message_sent_handler);

    // set the connection timeout (10 seconds)
    http_server.set_timeout(10000);

    // set the connection buffer sizes
    http_server.set_rx_buffer_size(16384);
    http_server.tcp_server()->set_receive_buffer_size(16384);
    http_server.tcp_server()->set_send_buffer_size(16384);

    // start accepting http connections on the port
    ASIO_ERROR_CODE error(http_server.accept_connections(port_number));
    if (error)
    {
      std::cerr << "Error: "  << error.message() << std::endl;
      return 1;
    }

    // The signal set is used to register termination notifications
    ASIO::signal_set signals_(io_service);
    signals_.add(SIGINT);
    signals_.add(SIGTERM);
#if defined(SIGQUIT)
    signals_.add(SIGQUIT);
#endif // #if defined(SIGQUIT)

    // register the handle_stop callback
    signals_.async_wait([&http_server]
      (ASIO_ERROR_CODE const& error, int signal_number)
    { handle_stop(error, signal_number, http_server); });

    // run the io_service to start communications
    io_service.run();

    std::cout << "io_service.run complete, shutdown successful" << std::endl;
  }
  catch (std::exception& e)
  {
    std::cerr << "Exception:"  << e.what() << std::endl;
  }

  return 0;
}
Example #11
0
void write_pipe(int number, char *message) {
   if (active[number]) {
      write(pipe_out[number], message, strlen(message));
   }
   if (verbose) printf("  TO %10.10s: %s", app_name(number), message);
}
Example #12
0
void LLDir_Solaris::initAppDirs(const std::string &app_name_in)
{
  	// Fix solaris invocation when the "*Portable*" hack is being used.
	std::string app_name(app_name_in);	// Make copy to minimize patch size.
	if (app_name == "*Portable*")
	{
		app_name = "Meta7";
	}

	mAppName = app_name;

	std::string upper_app_name(app_name);
	LLStringUtil::toUpper(upper_app_name);

	char* app_home_env = getenv((upper_app_name + "_USER_DIR").c_str());	/* Flawfinder: ignore */ 
	if (app_home_env)
	{
		// user has specified own userappdir i.e. $SECONDLIFE_USER_DIR
		mOSUserAppDir = app_home_env;
	}
	else
	{
		// traditionally on unixoids, MyApp gets ~/.myapp dir for data
		mOSUserAppDir = mOSUserDir;
		mOSUserAppDir += "/";
		mOSUserAppDir += ".";
		std::string lower_app_name(app_name);
		LLStringUtil::toLower(lower_app_name);
		mOSUserAppDir += lower_app_name;
	}

	// create any directories we expect to write to.

	int res = LLFile::mkdir(mOSUserAppDir);
	if (res == -1)
	{
		if (errno != EEXIST)
		{
			llwarns << "Couldn't create app user dir " << mOSUserAppDir << llendl;
			llwarns << "Default to base dir" << mOSUserDir << llendl;
			mOSUserAppDir = mOSUserDir;
		}
	}

	res = LLFile::mkdir(getExpandedFilename(LL_PATH_LOGS,""));
	if (res == -1)
	{
		if (errno != EEXIST)
		{
			llwarns << "Couldn't create LL_PATH_LOGS dir " << getExpandedFilename(LL_PATH_LOGS,"") << llendl;
		}
	}
	
	res = LLFile::mkdir(getExpandedFilename(LL_PATH_USER_SETTINGS,""));
	if (res == -1)
	{
		if (errno != EEXIST)
		{
			llwarns << "Couldn't create LL_PATH_USER_SETTINGS dir " << getExpandedFilename(LL_PATH_USER_SETTINGS,"") << llendl;
		}
	}
	
	res = LLFile::mkdir(getExpandedFilename(LL_PATH_CACHE,""));
	if (res == -1)
	{
		if (errno != EEXIST)
		{
			llwarns << "Couldn't create LL_PATH_CACHE dir " << getExpandedFilename(LL_PATH_CACHE,"") << llendl;
		}
	}
	
	res = LLFile::mkdir(getExpandedFilename(LL_PATH_MOZILLA_PROFILE,""));
	if (res == -1)
	{
		if (errno != EEXIST)
		{
			llwarns << "Couldn't create LL_PATH_MOZILLA_PROFILE dir " << getExpandedFilename(LL_PATH_MOZILLA_PROFILE,"") << llendl;
		}
	}

	mCAFile = getExpandedFilename(LL_PATH_APP_SETTINGS, "CA.pem");
}
Example #13
0
void create_child()
{
	char lavrec_i[4], lavrec_f[4], lavrec_d[4], lavrec_q[6], lavrec_a[5], lavrec_r[8];
	char lavrec_R[4], lavrec_c[4], lavrec_t[11], lavrec_T[4], lavrec_n[6], lavrec_b[8];
	char lavrec_g[20], lavrec_ff[6], lavrec_mfs[10];
	int n;
	char *lavrec_command[256];
	char command[256];

	/* create command in lavrec_command */
	n=0;
	lavrec_command[n] = app_name(LAVREC); n++;
	lavrec_command[n] = "-i"; n++; sprintf(lavrec_i, "%c", input_source); lavrec_command[n] = lavrec_i; n++;
	lavrec_command[n] = single_frame ? "-S" : "-w"; n++;
	lavrec_command[n] = "-f"; n++; sprintf(lavrec_f, "%c", video_format); lavrec_command[n] = lavrec_f; n++;
	if (!software_encoding)
	{
		lavrec_command[n] = "-d"; n++;
		sprintf(lavrec_d, "%i", hordcm);
		lavrec_command[n] = lavrec_d; n++;
	}
	lavrec_command[n] = "-q"; n++; sprintf(lavrec_q, "%i", quality); lavrec_command[n] = lavrec_q; n++;
	lavrec_command[n] = "-a"; n++; sprintf(lavrec_a, "%i", audio_size); lavrec_command[n] = lavrec_a; n++;
	lavrec_command[n] = "-r"; n++; sprintf(lavrec_r, "%i", audio_rate); lavrec_command[n] = lavrec_r; n++;
	lavrec_command[n] = "-l"; n++; lavrec_command[n] = "-1"; n++;
	lavrec_command[n] = "-R"; n++; sprintf(lavrec_R, "%c", (char)audio_recsrc); lavrec_command[n]=lavrec_R;n++;
	lavrec_command[n] = "-c"; n++; sprintf(lavrec_c, "%i", sync_corr); lavrec_command[n] = lavrec_c; n++;
	lavrec_command[n] = "-t"; n++; sprintf(lavrec_t, "%i", record_time); lavrec_command[n] = lavrec_t; n++;
	lavrec_command[n] = "-T"; n++; sprintf(lavrec_T, "%i", time_lapse); lavrec_command[n] = lavrec_T; n++;
	lavrec_command[n] = "-n"; n++; sprintf(lavrec_n, "%i", MJPG_nbufs); lavrec_command[n] = lavrec_n; n++;
	lavrec_command[n] = "-b"; n++; sprintf(lavrec_b, "%i", MJPG_bufsize); lavrec_command[n] = lavrec_b; n++;
	if (audio_mute) { lavrec_command[n] = "-m"; n++; }
	if (stereo) { lavrec_command[n] = "-s"; n++; }
	if (software_encoding)
	{ lavrec_command[n] = "--software-encoding"; n++; }
	if (use_read)
	{ lavrec_command[n] = "--use-read"; n++; }
	if (file_flush > 0)
	{
		lavrec_command[n] = "--file-flush"; n++;
		sprintf(lavrec_ff, "%d", file_flush);
		lavrec_command[n] = lavrec_ff; n++;
	}
	if (max_file_size > 0)
	{
		lavrec_command[n] = "--max-file-size"; n++;
		sprintf(lavrec_mfs, "%d", max_file_size);
		lavrec_command[n] = lavrec_mfs; n++;
	}
	if ((geom_width!=0 && geom_height!=0) && !software_encoding)
	{
		lavrec_command[n] = "-g"; n++;
		sprintf(lavrec_g, "%ix%i+%i+%i", geom_width, geom_height, geom_x, geom_y);
		lavrec_command[n] = lavrec_g; n++;
	}
	else if (software_encoding)
	{
		lavrec_command[n] = "-g"; n++;
		sprintf(lavrec_g, "%ix%i", software_recwidth, software_recheight);
		lavrec_command[n] = lavrec_g; n++;
	}
	lavrec_command[n] = (char*)gtk_entry_get_text(GTK_ENTRY(textfield));n++;
	lavrec_command[n] = NULL;

	if (verbose)
	{
	        command_2string(lavrec_command, command);
		printf("Executing: %s\n",command);
	}

	start_pipe_command(lavrec_command, LAVREC);
}
Example #14
0
void start_pipe_command(char *command[], int number)
{
   if (!app_location(number) || app_location(number)[0]!='/')
   {
      gtk_show_text_window(STUDIO_ERROR,
         "No valid application location found for %s. "
         "Please install and specify the correct path "
         "in the options screen in order to use it",
         app_name(number));
      return;
   }

   if (!active[number])
   {
      int ipipe[2], opipe[2], spipe[2];
      int n;

      if(pipe(ipipe) || pipe(opipe))
      {
         gtk_show_text_window(STUDIO_ERROR, "pipe() failed");
         return;
      }

      if (number == LAV2YUV)
      {
         if (pipe(spipe))
         {
            gtk_show_text_window(STUDIO_ERROR, "pipe() failed");
            return;
         }
      }

      pid[number] = fork();
      if(pid[number]<0)
      {
         gtk_show_text_window(STUDIO_ERROR, "fork() failed");
         return;
      }

      active[number] = 1;

      if (pid[number]) /* This is the parent process (i.e. LVS) */
      {
         /* parent */
         pipe_in[number] = opipe[0];
         close(opipe[1]);
         fcntl (pipe_in[number], F_SETFL, O_NONBLOCK);
         reader[number] = gdk_input_add (pipe_in[number],
            GDK_INPUT_READ, callback_pipes, (gpointer)number);

         if (number == LAV2YUV)
         {
            active[LAV2YUV_DATA] = 0;
            pipe_in[LAV2YUV_DATA] = spipe[0];
            close(spipe[1]);
            pthread_create(&lav2yuv_reading_thread, NULL,
               lav2yuv_read_thread, (void *) pipe_in[LAV2YUV_DATA]);
         }

         pipe_out[number] = ipipe[1]; /* don't O_NONBLOCK it! */
         close(ipipe[0]);
      }
      else /* This is the child process (i.e. lav2wav/mp2enc) */
      {
         extern int use_yuvscaler_pipe;
         /*extern int use_yuvdenoise_pipe;*/
         extern int preview_or_render;

         /* child */
         close(ipipe[1]);
         close(opipe[0]);

         n = dup2(ipipe[0],0);
         if(n!=0) exit(1);
         close(ipipe[0]);

         if (number == LAV2WAV) {
            n = dup2(pipe_out[MP2ENC],1); /* writes lav2wav directly to mp2enc */
         }
         else if (number == LAV2YUV) {
            close(spipe[0]);
            n = dup2(spipe[1],1);
            close(spipe[1]);
         }
         else if (number == YUVSCALER) {
            extern int studio_enc_format;
            switch (studio_enc_format)
            {
               case STUDIO_ENC_FORMAT_MPEG:
                  n = dup2(pipe_out[MPEG2ENC],1); /* writes yuvscaler directly to mpeg2enc */
                  break;
               case STUDIO_ENC_FORMAT_DIVX:
                  n = dup2(pipe_out[YUV2DIVX],1); /* writes yuvscaler directly to yuv2divx */
                  break;
               case STUDIO_ENC_FORMAT_MJPEG:
                  n = dup2(pipe_out[YUV2LAV_E],1); /* writes yuvscaler directly to yuv2lav */
                  break;
            }
         }
         else if (number == YUVDENOISE) {
           if (use_yuvscaler_pipe)
              n = dup2(pipe_out[YUVSCALER],1); /* writes yuvdenoise directly to yuvscaler */
           else
           {
              extern int studio_enc_format;
              switch (studio_enc_format)
              {
                 case STUDIO_ENC_FORMAT_MPEG:
                    n = dup2(pipe_out[MPEG2ENC],1); /* writes yuvdenoise directly to mpeg2enc */
                    break;
                 case STUDIO_ENC_FORMAT_DIVX:
                    n = dup2(pipe_out[YUV2DIVX],1); /* writes yuvdenoise directly to yuv2divx */
                    break;
                 case STUDIO_ENC_FORMAT_MJPEG:
                    n = dup2(pipe_out[YUV2LAV_E],1); /* writes yuvdenoise directly to yuv2lav */
                    break;
              }
           }
         }
         else if (number == LAVPIPE) {
            if (preview_or_render)
               n = dup2(pipe_out[YUV2LAV],1); /* writes lavpipe directly to yuv2lav */
            else
               n = dup2(pipe_out[YUVPLAY_E],1); /* writes lavpipe directly to yuvplay */
         }
         else {
            n = dup2(opipe[1],1);
         }
         if(n!=1) exit(1);

         n = dup2(opipe[1],2);
         if(n!=2) exit(1);
         close(opipe[1]);

         execvp(app_location(number), command);

         /* uh oh, app does not exist */
         fprintf(stderr, "**ERROR: %s (\'%s\') could not be started: %s\n",
            app_name(number), app_location(number), strerror(errno));

         _exit(1);
      }
   }
   else
   {
      printf("**ERROR: %s is already active\n", app_name(number));
   }
}
Example #15
0
static void callback_pipes(gpointer data, gint source,
   GdkInputCondition condition)
{
   char input[4096];
   int n, i, number;
   char *app;

   number = (int)data;

   app = app_name(number);

   n = read(source, input, 4095);
   if (n<=0)
   {
      gdk_input_remove(reader[number]);
   }
   if (n==0)
   {
      extern int use_yuvdenoise_pipe;
      extern int use_yuvscaler_pipe;
      extern int use_yuvplay_pipe;
      extern int preview_or_render;

      /* program finished */
      if (verbose) printf("%s finished\n", app);

      /* close pipes/app */
      close(pipe_in[number]);
      if (number != MP2ENC && number != MPEG2ENC && number != YUVSCALER && number != YUVPLAY &&
         number != YUVPLAY_E && number != YUV2LAV && number != YUVDENOISE && number != YUV2DIVX &&
         number != YUV2LAV_E) {
         close(pipe_out[number]);
      }
      close_pipe(number);

      if (number == LAV2WAV) {
         close(pipe_out[MP2ENC]);
      }
      if (number == LAV2YUV) {
         if (use_yuvdenoise_pipe)
            close(pipe_out[YUVDENOISE]);
         else if (use_yuvscaler_pipe)
            close(pipe_out[YUVSCALER]);
         else
         {
            extern int studio_enc_format;
            switch (studio_enc_format)
            {
               case STUDIO_ENC_FORMAT_MPEG:
                  close(pipe_out[MPEG2ENC]);
                  break;
               case STUDIO_ENC_FORMAT_DIVX:
                  close(pipe_out[YUV2DIVX]);
                  break;
               case STUDIO_ENC_FORMAT_MJPEG:
                  close(pipe_out[YUV2LAV_E]);
                  break;
            }
         }

         if (use_yuvplay_pipe)
            close(pipe_out[YUVPLAY]);
      }
      if (number == YUVDENOISE) {
         if (use_yuvscaler_pipe)
            close(pipe_out[YUVSCALER]);
         else
         {
            extern int studio_enc_format;
            switch (studio_enc_format)
            {
               case STUDIO_ENC_FORMAT_MPEG:
                  close(pipe_out[MPEG2ENC]);
                  break;
               case STUDIO_ENC_FORMAT_DIVX:
                  close(pipe_out[YUV2DIVX]);
                  break;
               case STUDIO_ENC_FORMAT_MJPEG:
                  close(pipe_out[YUV2LAV_E]);
                  break;
            }
         }
      }
      if (number == YUVSCALER) {
         extern int studio_enc_format;
         switch (studio_enc_format)
         {
            case STUDIO_ENC_FORMAT_MPEG:
               close(pipe_out[MPEG2ENC]);
               break;
            case STUDIO_ENC_FORMAT_DIVX:
               close(pipe_out[YUV2DIVX]);
               break;
            case STUDIO_ENC_FORMAT_MJPEG:
               close(pipe_out[YUV2LAV_E]);
               break;
         }
      }
      if (number == LAVPIPE) {
         if (preview_or_render)
            close(pipe_out[YUV2LAV]);
         else
            close(pipe_out[YUVPLAY_E]);
      }

      /* trigger callback function for each specific app */
      if (number == MPEG2ENC || number == MP2ENC || number == MPLEX || number == YUV2DIVX ||
          number == YUV2LAV_E) {
         continue_encoding();
      }
      else if (number == LAV2YUV_S) {
         scene_detection_finished();
      }
      else if (number == LAVPLAY_E) {
         lavplay_edit_stopped();
      }
      else if (number == LAVPLAY_T) {
         quit_trimming(NULL,NULL);
      }
      else if (number == LAVREC) {
         lavrec_quit();
      }
      else if (number == LAVPLAY) {
         lavplay_stopped();
      }
      else if (number == YUV2LAV || number == YUVPLAY_E) {
         effects_finished();
      }

      /* officially, we should detach the gdk_input here */
      gdk_input_remove(reader[number]);
   }
   else
   {
      int x = 0;
      char temp[256], endsign;

      for(i=0;i<n;i++)
      {
         if(input[i]=='\n' || input[i]=='\r' || i==n-1)
         {
            strncpy(temp, input+x, i-x);
            if (i-x<255) {
               if (i==n-1 && input[i]!='\r' && input[i]!='\n') {
                  temp[i-x] = input[i];
                  if (i-x<254)
                     temp[i-x+1] = '\0';
               }
               else
                  temp[i-x] = '\0';
            }
            endsign = '\n';
            if (input[i] == '\n' || input[i] == '\r')
               endsign = input[i];
            if (input[x] == '@')
               endsign = '\r';
            if (number == LAV2YUV_S && strncmp(temp, "--DEBUG: frame", 14)==0)
               endsign = '\r';
            if (number == MPEG2ENC && strncmp(temp, "   INFO: Frame", 14)==0)
               endsign = '\r';
            if (number == MP2ENC && strncmp(temp, "--DEBUG: ", 9)==0)
               endsign = '\r';

            if(!(number == LAVPLAY && strncmp(temp, "--DEBUG: frame=", 15)==0)) {
               if (verbose) {
                  fprintf(stdout, "FROM %10.10s: %s%c", app, temp, endsign);
                  fflush(stdout);
               }
            }

            switch(number) {
               case MPEG2ENC:
               case LAV2YUV:
               case LAV2WAV:
               case MP2ENC:
               case MPLEX:
               case YUVSCALER:
               case YUVPLAY:
               case YUV2DIVX:
               case YUV2LAV_E:
                  lavencode_callback(number, temp);
                  break;
               case LAV2YUV_S:
                  scene_detection_input_cb(temp);
                  break;
               case LAVPLAY_E:
                  process_lavplay_edit_input(temp);
                  break;
               case LAVPLAY:
                  process_lavplay_input(temp);
                  break;
               case LAVPLAY_T:
                  lavplay_trimming_callback(temp);
                  break;
               case LAVREC:
                  dispatch_input(temp);
                  break;
               case YUV2LAV:
               case YUVPLAY_E:
               case LAVPIPE:
                  effects_callback(number, temp);
                  break;
            }

            x = i+1;
         }
      }
   }
}
Example #16
0
int main(int argc, char *argv[])
{
	int index;
	int c;

	std::string ptp_dev("tun0");
	std::string app_name("tunnel");
	std::string endpoint("dtn:none");
	unsigned int lifetime = 60;
	bool daemonize = false;
	bool stop_daemon = false;
	std::string pidfile;
	bool throughput = false;

#ifdef HAVE_LIBDAEMON
	while ((c = getopt (argc, argv, "td:s:l:hDkp:")) != -1)
#else
	while ((c = getopt (argc, argv, "td:s:l:h")) != -1)
#endif
	switch (c)
	{
#ifdef HAVE_LIBDAEMON
		case 'D':
			daemonize = true;
			break;

		case 'k':
			daemonize = true;
			stop_daemon = true;
			break;

		case 'p':
			pidfile = optarg;
			break;
#endif
		case 'd':
			ptp_dev = optarg;
			break;

		case 't':
			throughput = true;
			break;

		case 's':
			app_name = optarg;
			break;

		case 'l':
			lifetime = atoi(optarg);
			break;

		default:
			print_help(argv[0]);
			return 1;
	}

	int optindex = 0;
	for (index = optind; index < argc; ++index)
	{
		switch (optindex)
		{
		case 0:
			endpoint = std::string(argv[index]);
			break;
		}

		optindex++;
	}

	// print help if not enough parameters are set
	if (!stop_daemon && (optindex < 1)) { print_help(argv[0]); exit(0); }

	// catch process signals
	ibrcommon::SignalHandler sighandler(term);
	sighandler.handle(SIGINT);
	sighandler.handle(SIGTERM);
	sighandler.handle(SIGQUIT);

	//initialize sighandler after possible exit call
	sighandler.initialize();

	// logging options
	//const unsigned char logopts = ibrcommon::Logger::LOG_DATETIME | ibrcommon::Logger::LOG_LEVEL;
	const unsigned char logopts = 0;

	// error filter
	const unsigned char logerr = ibrcommon::Logger::LOGGER_ERR | ibrcommon::Logger::LOGGER_CRIT;

	// logging filter, everything but debug, err and crit
	const unsigned char logstd = ibrcommon::Logger::LOGGER_ALL ^ (ibrcommon::Logger::LOGGER_DEBUG | logerr);

	// syslog filter, everything but DEBUG and NOTICE
	const unsigned char logsys = ibrcommon::Logger::LOGGER_ALL ^ (ibrcommon::Logger::LOGGER_DEBUG | ibrcommon::Logger::LOGGER_NOTICE);

#ifdef HAVE_LIBDAEMON
	if (daemonize) {
		// enable syslog logging
		ibrcommon::Logger::enableSyslog(argv[0], LOG_PID, LOG_DAEMON, logsys);
	} else
#endif
	{
		// add logging to the cout
		ibrcommon::Logger::addStream(std::cout, logstd, logopts);

		// add logging to the cerr
		ibrcommon::Logger::addStream(std::cerr, logerr, logopts);
	}

#ifdef HAVE_LIBDAEMON
	if (daemonize)
	{
#ifdef HAVE_DAEMON_RESET_SIGS
		/* Reset signal handlers */
		if (daemon_reset_sigs(-1) < 0) {
			IBRCOMMON_LOGGER_TAG("Core", error) << "Failed to reset all signal handlers: " << strerror(errno) << IBRCOMMON_LOGGER_ENDL;
			return 1;
		}

		/* Unblock signals */
		if (daemon_unblock_sigs(-1) < 0) {
			IBRCOMMON_LOGGER_TAG("Core", error) << "Failed to unblock all signals: " << strerror(errno) << IBRCOMMON_LOGGER_ENDL;
			return 1;
		}
#endif
		pid_t pid;

		/* Set identification string for the daemon for both syslog and PID file */
		daemon_pid_file_ident = daemon_log_ident = daemon_ident_from_argv0(argv[0]);

		/* set the pid file path */
		if (pidfile.length() > 0) {
			__daemon_pidfile__ = new char[pidfile.length() + 1];
			::strcpy(__daemon_pidfile__, pidfile.c_str());
			daemon_pid_file_proc = __daemon_pid_file_proc__;
		}

		/* Check if we are called with -k parameter */
		if (stop_daemon)
		{
			int ret;

			/* Kill daemon with SIGTERM */

			/* Check if the new function daemon_pid_file_kill_wait() is available, if it is, use it. */
			if ((ret = daemon_pid_file_kill_wait(SIGTERM, 5)) < 0)
				IBRCOMMON_LOGGER_TAG("Core", warning) << "Failed to kill daemon: " << strerror(errno) << IBRCOMMON_LOGGER_ENDL;

			return ret < 0 ? 1 : 0;
		}

		/* Check that the daemon is not rung twice a the same time */
		if ((pid = daemon_pid_file_is_running()) >= 0) {
			IBRCOMMON_LOGGER_TAG("Core", error) << "Daemon already running on PID file " << pid << IBRCOMMON_LOGGER_ENDL;
			return 1;
		}

		/* Prepare for return value passing from the initialization procedure of the daemon process */
		if (daemon_retval_init() < 0) {
			IBRCOMMON_LOGGER_TAG("Core", error) << "Failed to create pipe." << IBRCOMMON_LOGGER_ENDL;
			return 1;
		}

		/* Do the fork */
		if ((pid = daemon_fork()) < 0) {

			/* Exit on error */
			daemon_retval_done();
			return 1;

		} else if (pid) { /* The parent */
			int ret;

			/* Wait for 20 seconds for the return value passed from the daemon process */
			if ((ret = daemon_retval_wait(20)) < 0) {
				IBRCOMMON_LOGGER_TAG("Core", error) << "Could not recieve return value from daemon process: " << strerror(errno) << IBRCOMMON_LOGGER_ENDL;
				return 255;
			}

			return ret;

		} else { /* The daemon */
			/* Close FDs */
			if (daemon_close_all(-1) < 0) {
				IBRCOMMON_LOGGER_TAG("Core", error) << "Failed to close all file descriptors: " << strerror(errno) << IBRCOMMON_LOGGER_ENDL;

				/* Send the error condition to the parent process */
				daemon_retval_send(1);

				/* Do a cleanup */
				daemon_retval_send(255);
				daemon_signal_done();
				daemon_pid_file_remove();

				return -1;
			}

			/* Create the PID file */
			if (daemon_pid_file_create() < 0) {
				IBRCOMMON_LOGGER_TAG("Core", error) << "Could not create PID file ( " << strerror(errno) << ")." << IBRCOMMON_LOGGER_ENDL;
				daemon_retval_send(2);

				/* Do a cleanup */
				daemon_retval_send(255);
				daemon_signal_done();
				daemon_pid_file_remove();

				return -1;
			}

			/* Send OK to parent process */
			daemon_retval_send(0);
		}
	}
#endif

	IBRCOMMON_LOGGER_TAG("Core", info) << "IBR-DTN IP <-> Bundle Tunnel" << IBRCOMMON_LOGGER_ENDL;

	// create a connection to the dtn daemon
	ibrcommon::vaddress addr("localhost", 4550);
	ibrcommon::socketstream conn(new ibrcommon::tcpsocket(addr));

	try {
		// set-up tun2bundle gateway
		TUN2BundleGateway gateway(app_name, conn, ptp_dev);
		_gateway = &gateway;

		IBRCOMMON_LOGGER_TAG("Core", info) << "Local:  " << app_name << IBRCOMMON_LOGGER_ENDL;
		IBRCOMMON_LOGGER_TAG("Core", info) << "Peer:   " << endpoint << IBRCOMMON_LOGGER_ENDL;
		IBRCOMMON_LOGGER_TAG("Core", info) << "Device: " << gateway.getDeviceName() << IBRCOMMON_LOGGER_ENDL;
		IBRCOMMON_LOGGER_TAG("Core", notice) << IBRCOMMON_LOGGER_ENDL;
		IBRCOMMON_LOGGER_TAG("Core", notice) << "Now you need to set-up the ip tunnel. You can use commands like this:" << IBRCOMMON_LOGGER_ENDL;
		IBRCOMMON_LOGGER_TAG("Core", notice) << "# sudo ip link set " << gateway.getDeviceName() << " up mtu 65535" << IBRCOMMON_LOGGER_ENDL;
		IBRCOMMON_LOGGER_TAG("Core", notice) << "# sudo ip addr add 10.0.0.1/24 dev " << gateway.getDeviceName() << IBRCOMMON_LOGGER_ENDL;
		IBRCOMMON_LOGGER_TAG("Core", notice) << IBRCOMMON_LOGGER_ENDL;

		timer_t timerid;
		struct sigevent sev;

		if (!daemonize && throughput) {
			// enable throughput timer
			signal(SIGRTMIN, timer_display_throughput);

			sev.sigev_notify = SIGEV_SIGNAL;
			sev.sigev_signo = SIGRTMIN;
			sev.sigev_value.sival_ptr = &timerid;

			// create a timer
			timer_create(CLOCK_MONOTONIC, &sev, &timerid);

			// arm the timer
			struct itimerspec its;
			size_t freq_nanosecs = 200000000;
			its.it_value.tv_sec = freq_nanosecs / 1000000000;;
			its.it_value.tv_nsec = freq_nanosecs % 1000000000;
			its.it_interval.tv_sec = its.it_value.tv_sec;
			its.it_interval.tv_nsec = its.it_value.tv_nsec;

			if (timer_settime(timerid, 0, &its, NULL) == -1) {
				IBRCOMMON_LOGGER_TAG("Core", error) << "Timer set failed." << IBRCOMMON_LOGGER_ENDL;
			}
		}

		// destination
		dtn::data::EID eid(endpoint);

		while (m_running)
		{
			gateway.process(eid, lifetime);
		}

		gateway.shutdown();
	} catch (const ibrcommon::Exception &ex) {
		if (m_running) {
			IBRCOMMON_LOGGER_TAG("Core", error) << ex.what() << IBRCOMMON_LOGGER_ENDL;
			return -1;
		}
	}

#ifdef HAVE_LIBDAEMON
	if (daemonize) {
		/* Do a cleanup */
		IBRCOMMON_LOGGER_TAG("Core", info) << "Stopped " << app_name << IBRCOMMON_LOGGER_ENDL;
		daemon_retval_send(255);
		daemon_signal_done();
		daemon_pid_file_remove();
	} else
#endif
	{
		std::cout << std::endl;
	}

	return 0;
}
int main(int argc, char *argv[])
{
  std::string app_name(argv[0]);
  unsigned short port_number(via::comms::tcp_adaptor::DEFAULT_HTTP_PORT);

  // Get a port number from the user (the default is 80)
  if (argc > 2)
  {
    std::cerr << "Usage: " << app_name << " [port number]\n"
              << "E.g. "   << app_name << " " << port_number
              << std::endl;
    return 1;
  }
  else if (argc == 2)
  {
    std::string port(argv[1]);
    port_number = atoi(port.c_str());
  }

  std::cout << app_name << ": " << port_number << std::endl;

  try
  {
    // create an io_service for the server
    boost::asio::io_service io_service;

    // create an http_server and connect the request handler
    http_server_type http_server(io_service);
    http_server.request_received_event(request_handler);

    // connect the handler callback functions
    http_server.chunk_received_event(chunk_handler);
    http_server.request_expect_continue_event(expect_continue_handler);
    http_server.invalid_request_event(invalid_request_handler);
    http_server.socket_connected_event(connected_handler);
    http_server.socket_disconnected_event(disconnected_handler);
    http_server.message_sent_event(message_sent_handler);

    // start accepting http connections on the given port
    boost::system::error_code error(http_server.accept_connections(port_number));
    if (error)
    {
      std::cerr << "Error: "  << error.message() << std::endl;
      return 1;
    }

    // The signal set is used to register for termination notifications
    boost::asio::signal_set signals_(io_service);
    signals_.add(SIGINT);
    signals_.add(SIGTERM);
#if defined(SIGQUIT)
    signals_.add(SIGQUIT);
#endif // #if defined(SIGQUIT)

    // register the handle_stop callback
    signals_.async_wait([&http_server]
      (boost::system::error_code const& error, int signal_number)
    { handle_stop(error, signal_number, http_server); });

    // Determine the number of concurrent threads supported
    size_t no_of_threads(std::thread::hardware_concurrency());
    std::cout << "No of threads: " << no_of_threads << std::endl;

    if (no_of_threads > 0)
    {
      // Create a thread pool for the threads and run the asio io_service
      // in each of the threads.
      std::vector<std::shared_ptr<std::thread> > threads;
      for (std::size_t i = 0; i < no_of_threads; ++i)
      {
        std::shared_ptr<std::thread> thread(std::make_shared<std::thread>
                             ([&io_service](){ io_service.run(); }));
        threads.push_back(thread);
      }

      // Wait for all threads in the pool to exit.
      for (std::size_t i(0); i < threads.size(); ++i)
        threads[i]->join();
    }
    else
      io_service.run();

    std::cout << "io_service.run, all work has finished" << std::endl;
  }
  catch (std::exception& e)
  {
    std::cerr << "Exception:"  << e.what() << std::endl;
  }

  return 0;
}