Ejemplo n.º 1
0
int  main(int argc, char ** argvFILE) {
	char  line[1024];             /* the input line                 */
	char  *argv[64];              /* the command line argument      */
	char * p;
	int tokens, foreground;
	int * ptokens =&tokens;
	int * pforeground =&foreground;

	int input_from_file = ftell(stdin);		/* check if input is coming from file */
	
	init_shell();	
	while (1) {                   /* repeat until done ....         */
		if(input_from_file < 0)		/*	stdin is coming from user not file */
			printf("sish:>");        /*   display a prompt             */   	             	
		memset (line, '\0', sizeof(line));		// zero line, (fills array with null terminator)
          memset (argv, '\0', sizeof(argv));
          if (!fgets(line, sizeof(line), stdin)) 	{printf("\n"); return 0;}	// Exit upon ctrl-D
     	if(strlen(line) == 1) {
     		continue;	//	 check for empty string aka 'enter' is pressed without input
          }	
          if ((p = strchr(line, '\n')) != NULL)	//	remove '\n' from the end of 'line'
			*p = '\0';
		parse (line, argv, ptokens);		// parse input to shell
		if (argv[0] == '\0')
			continue;
		else if (strcmp(argv[0], "exit") == 0)  /* is it an "exit"?     */      
			return 0;            /*   exit if it is                */        
		else if (strcmp(argv[0], "cd") == 0) 
			cd (argv[1]);	             	
		else {
			if ((first_job = job_initialize(argv, tokens, pforeground)) != NULL) {
				launch_job	(first_job, foreground);
				free_job(first_job);
			}
		}
	}
}
Ejemplo n.º 2
0
/**
 * gstreamill_job_start:
 * @job: (in): json type of job description.
 *
 * Returns: json type of job execution result. 
 */
gchar * gstreamill_job_start (Gstreamill *gstreamill, gchar *job_desc)
{
        gchar *p, *name;
        Job *job;

        if (!jobdesc_is_valid (job_desc)) {
                p = g_strdup_printf ("{\n    \"result\": \"failure\",\n    \"reason\": \"invalid job\"\n}");
                return p;
        }

        if (jobdesc_is_live (job_desc)) {
                GST_ERROR ("live job arrived:\n%s", job_desc);

        } else {
                GST_ERROR ("transcode job arrived:\n%s", job_desc);
        }

        /* create job object */
        name = jobdesc_get_name (job_desc);
        if (get_job (gstreamill, name) != NULL) {
                GST_ERROR ("start job failure, duplicated name %s.", name);
                p = g_strdup_printf ("{\n    \"result\": \"failure\",\n    \"reason\": \"duplicated name\"\n}");
                g_free (name);
                return p;
        }
        job = job_new ("job", job_desc, "name", name, "exe_path", gstreamill->exe_path, NULL);
        g_free (name);

        /* job initialize */
        job->log_dir = gstreamill->log_dir;
        g_mutex_init (&(job->access_mutex));
        job->is_live = jobdesc_is_live (job_desc);
        job->eos = FALSE;
        job->current_access = 0;
        job->age = 0;
        job->last_start_time = NULL;
        if (job_initialize (job, gstreamill->daemon) != 0) {
                p = g_strdup_printf ("{\n    \"result\": \"failure\",\n    \"reason\": \"initialize job failure\"\n}");
                g_object_unref (job);
                return p;
        }

        if (job->is_live && (job_output_initialize (job) != 0)) {
                p = g_strdup_printf ("{\n    \"result\": \"failure\",\n    \"reason\": \"initialize job output failure\"\n}");
                g_object_unref (job);
                return p;
        }

        /* reset and start job */
        job_reset (job);
        if (gstreamill->daemon) {
                guint64 stat;

                stat = create_job_process (job);
                if (stat == JOB_STATE_PLAYING) {
                        GST_ERROR ("Start job %s success", job->name);
                        g_mutex_lock (&(gstreamill->job_list_mutex));
                        gstreamill->job_list = g_slist_append (gstreamill->job_list, job);
                        g_mutex_unlock (&(gstreamill->job_list_mutex));
                        p = g_strdup_printf ("{\n    \"name\": \"%s\",\n\"result\": \"success\"\n}", job->name);

                } else {
                        GST_ERROR ("Start job %s failure, return stat: %s", job->name, job_state_get_name (stat));
                        g_object_unref (job);
                        p = g_strdup_printf ("{\n    \"result\": \"failure\",\n    \"reason\": \"create process failure\"\n}");
                }

        } else {
                job_encoders_output_initialize (job);
                if (job_start (job) == 0) {
                        g_mutex_lock (&(gstreamill->job_list_mutex));
                        gstreamill->job_list = g_slist_append (gstreamill->job_list, job);
                        g_mutex_unlock (&(gstreamill->job_list_mutex));
                        p = g_strdup ("{\n    \"result\": \"success\"\n}");

                } else {
                        p = g_strdup_printf ("{\n    \"result\": \"failure\",\n    \"reason\": \"unknown\"\n}");
                }
        }

        return p;
}
Ejemplo n.º 3
0
int main (int argc, char *argv[])
{
        HTTPMgmt *httpmgmt;
        HTTPStreaming *httpstreaming;
        GMainLoop *loop;
        GOptionContext *ctx;
        GError *err = NULL;
        gboolean foreground;
        struct rlimit rlim;
        GDateTime *datetime;
        gchar exe_path[512], *date;

        ctx = g_option_context_new (NULL);
        g_option_context_add_main_entries (ctx, options, NULL);
        g_option_context_add_group (ctx, gst_init_get_option_group ());
        if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
                g_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
                exit (1);
        }
        g_option_context_free (ctx);
        GST_DEBUG_CATEGORY_INIT (GSTREAMILL, "gstreamill", 0, "gstreamill log");

        if (version) {
                print_version_info ();
                exit (0);
        }

        /* stop gstreamill. */
        if (stop) {
                gchar *pid_str;
                gint pid;

                g_file_get_contents (PID_FILE, &pid_str, NULL, NULL);
                if (pid_str == NULL) {
                        g_print ("File %s not found, check if gstreamill is running.\n", PID_FILE);
                        exit (1);
                }
                pid = atoi (pid_str);
                g_free (pid_str);
                g_print ("stoping gstreamill with pid %d ...\n", pid);
                kill (pid, SIGTERM);
                exit (0);
        }

        /* readlink exe path before setuid, on CentOS, readlink exe path after setgid/setuid failure on permission denied */
        memset (exe_path, '\0', sizeof (exe_path));
        if (readlink ("/proc/self/exe", exe_path, sizeof (exe_path)) == -1) {
                g_print ("Read /proc/self/exe error: %s", g_strerror (errno));
                exit (2);
        }

        if (prepare_gstreamill_run_dir () != 0) {
                g_print ("Can't create gstreamill run directory\n");
                exit (3);
        }
/*
        if (set_user_and_group () != 0) {
                g_print ("set user and group failure\n");
                exit (4);
        }
*/
        if (job_file != NULL) {
                /* gstreamill command with job, run in foreground */
                foreground = TRUE;

        } else {
                /* gstreamill command without job, run in background */
                foreground = FALSE;
        }

        if (gst_debug_get_default_threshold () < GST_LEVEL_WARNING) {
                gst_debug_set_default_threshold (GST_LEVEL_WARNING);
        }

        /* initialize ts segment static plugin */
        if (!gst_plugin_register_static (GST_VERSION_MAJOR,
                                         GST_VERSION_MINOR,
                                         "tssegment",
                                         "ts segment plugin",
                                         ts_segment_plugin_init,
                                         "0.1.0",
                                         "GPL",
                                         "GStreamer",
                                         "GStreamer",
                                         "http://gstreamer.net/")) {
                GST_ERROR ("registe tssegment error");
                exit (17);
        }

        /* subprocess, create_job_process */
        if (shm_name != NULL) {
                gint fd;
                gchar *job_desc, *p;
                Job *job;
                gchar *log_path, *name;
                gint ret;

                /* set subprocess maximum of core file */
                rlim.rlim_cur = 0;
                rlim.rlim_max = 0;
                if (setrlimit (RLIMIT_CORE, &rlim) == -1) {
                        GST_ERROR ("setrlimit error: %s", g_strerror (errno));
                }

                /* read job description from share memory */
                job_desc = NULL;
                fd = shm_open (shm_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
                if (ftruncate (fd, job_length) == -1) {
                        exit (5);
                }
                p = mmap (NULL, job_length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
                job_desc = g_strdup (p);

                if ((job_desc != NULL) && (!jobdesc_is_valid (job_desc))) {
                        exit (6);
                }

                /* initialize log */
                name = (gchar *)jobdesc_get_name (job_desc);
                if (!jobdesc_is_live (job_desc)) {
                        gchar *p;

                        p = jobdesc_get_log_path (job_desc);
                        log_path = g_build_filename (p, "gstreamill.log", NULL);
                        g_free (p);

                } else {
                        log_path = g_build_filename (log_dir, name, "gstreamill.log", NULL);
                }
                ret = init_log (log_path);
                g_free (log_path);
                if (ret != 0) {
                        exit (7);
                }

                /* launch a job. */
                datetime = g_date_time_new_now_local ();
                date = g_date_time_format (datetime, "%b %d %H:%M:%S");
                fprintf (_log->log_hd, "\n*** %s : job %s starting ***\n\n", date, name);
                g_date_time_unref (datetime);
                g_free (date);
                job = job_new ("name", name, "job", job_desc, NULL);
                job->is_live = jobdesc_is_live (job_desc);
                job->eos = FALSE;
                loop = g_main_loop_new (NULL, FALSE);

                GST_INFO ("Initializing job ...");
                if (job_initialize (job, TRUE) != 0) {
                        GST_ERROR ("initialize job failure, exit");
                        exit (8);
                }
                GST_INFO ("Initializing job done");

                GST_INFO ("Initializing job's encoders output ...");
                if (job_encoders_output_initialize (job) != 0) {
                        GST_ERROR ("initialize job encoders' output failure, exit");
                        exit (8);
                }
                GST_INFO ("Initializing job's encoders output done");

                GST_INFO ("Starting job ...");
                if (job_start (job) != 0) {
                        GST_ERROR ("start livejob failure, exit");
                        exit (9);
                }
                datetime = g_date_time_new_now_local ();
                date = g_date_time_format (datetime, "%b %d %H:%M:%S");
                fprintf (_log->log_hd, "\n*** %s : job %s started ***\n\n", date, name);
                g_date_time_unref (datetime);
                g_free (date);
                g_free (name);
                g_free (job_desc);

                signal (SIGPIPE, SIG_IGN);
                signal (SIGUSR1, sighandler);
                signal (SIGTERM, stop_job);

                g_main_loop_run (loop);

        } else {
                /* set parent process maximum of core file */
                rlim.rlim_cur = RLIM_INFINITY;
                rlim.rlim_max = RLIM_INFINITY;
                if (setrlimit (RLIMIT_CORE, &rlim) == -1) {
                        GST_ERROR ("setrlimit error: %s", g_strerror (errno));
                }
        }

        /* run in background? */
        if (!foreground) {
                gchar *path;
                gint ret;

                /* pid file exist? */
                if (g_file_test (PID_FILE, G_FILE_TEST_EXISTS)) {
                        g_print ("file %s found, gstreamill already running !!!\n", PID_FILE);
                        exit (10);
                }

                /* media directory */
                path = g_strdup_printf ("%s/dvr", MEDIA_LOCATION);
                if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
                        g_printf ("Create DVR directory: %s", path);
                        if (g_mkdir_with_parents (path, 0755) != 0) {
                                g_printf ("Create DVR directory failure: %s", path);
                        }
                }
                g_free (path);
                path = g_strdup_printf ("%s/transcode/in", MEDIA_LOCATION);
                if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
                        g_printf ("Create transcode directory: %s", path);
                        if (g_mkdir_with_parents (path, 0755) != 0) {
                                g_printf ("Create transcode directory failure: %s", path);
                        }
                }
                g_free (path);
                path = g_strdup_printf ("%s/transcode/out", MEDIA_LOCATION);
                if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
                        g_printf ("Create transcode directory: %s", path);
                        if (g_mkdir_with_parents (path, 0755) != 0) {
                                g_printf ("Create transcode directory failure: %s", path);
                        }
                }
                g_free (path);

                /* log to file */
                path = g_build_filename (log_dir, "gstreamill.log", NULL);
                ret = init_log (path);
                g_free (path);
                if (ret != 0) {
                        g_print ("Init log error, ret %d.\n", ret);
                        exit (11);
                }

                /* daemonize */
                if (daemon (0, 0) != 0) {
                        fprintf (_log->log_hd, "Failed to daemonize");
                        remove_pid_file ();
                        exit (1);
                }

                /* create pid file */
                if (create_pid_file () != 0) {
                        exit (1);
                }

                /* customize signal */
                signal (SIGUSR1, sighandler);
                signal (SIGTERM, stop_gstreamill);

                datetime = g_date_time_new_now_local ();
                date = g_date_time_format (datetime, "%b %d %H:%M:%S");
                fprintf (_log->log_hd, "\n*** %s : gstreamill started ***\n\n", date);
                g_free (date);
                g_date_time_unref (datetime);
        }

        /* ignore SIGPIPE */
        signal (SIGPIPE, SIG_IGN);

        loop = g_main_loop_new (NULL, FALSE);

        /* gstreamill */
        gstreamill = gstreamill_new ("daemon", !foreground, "log_dir", log_dir, "exe_path", exe_path, NULL);
        if (gstreamill_start (gstreamill) != 0) {
                GST_ERROR ("start gstreamill error, exit.");
                remove_pid_file ();
                exit (12);
        }

        /* httpstreaming, pull */
        httpstreaming = httpstreaming_new ("gstreamill", gstreamill, "address", http_streaming, NULL);
        if (httpstreaming_start (httpstreaming, 10) != 0) {
                GST_ERROR ("start httpstreaming error, exit.");
                remove_pid_file ();
                exit (13);
        }

        if (!foreground) {
                /* run in background, management via http */
                httpmgmt = httpmgmt_new ("gstreamill", gstreamill, "address", http_mgmt, NULL);
                if (httpmgmt_start (httpmgmt) != 0) {
                        GST_ERROR ("start http mangment error, exit.");
                        remove_pid_file ();
                        exit (14);
                }

        } else {
                /* run in foreground, start job */
                gchar *job, *p, *result;
                JSON_Value *val;
                JSON_Object *obj;

                /* ctrl-c, stop gstreamill */
                signal (SIGINT, stop_gstreamill);

                /* ctrl-\, stop gstreamill */
                signal (SIGQUIT, stop_gstreamill);

                if (!g_file_get_contents (job_file, &job, NULL, NULL)) {
                        GST_ERROR ("Read job file %s error.", job_file);
                        exit (15);
                }
                p = gstreamill_job_start (gstreamill, job);
                val = json_parse_string (p);
                obj = json_value_get_object (val);
                result = (gchar *)json_object_get_string (obj, "result");
                GST_INFO ("start job result: %s.", result);
                if (g_strcmp0 (result, "success") != 0) {
                        exit (16);
                }
                json_value_free (val);
                g_free (p);
        }

        g_main_loop_run (loop);

        return 0;
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{

    int ret = -1;
    struct request_foo* req = NULL;
    struct ack_foo* ack = NULL;
    PVFS_BMI_addr_t server_addr;
    job_status_s status1;
    job_id_t tmp_id;
    job_context_id context;

    /* set debugging level */
    gossip_enable_stderr();
    gossip_set_debug_mask(0, 0);

    /* start the BMI interface */
    ret = BMI_initialize("bmi_tcp", NULL, 0);
    if(ret < 0)
    {
        fprintf(stderr, "BMI_initialize failure.\n");
        return(-1);
    }

    ret = trove_initialize(
              TROVE_METHOD_DBPF, NULL, "/tmp/pvfs2-test-space", 0);
    if(ret < 0)
    {
        fprintf(stderr, "trove_initialize failure.\n");
        return(-1);
    }

    /* start the job interface */
    ret = job_initialize(0);
    if(ret < 0)
    {
        fprintf(stderr, "job_initialize failure.\n");
        return(-1);
    }

    ret = job_open_context(&context);
    if(ret < 0)
    {
        fprintf(stderr, "job_open_context() failure.\n");
        return(-1);
    }

    /* lookup the server to get a BMI style address for it */
    ret = BMI_addr_lookup(&server_addr, "tcp://localhost:3414");
    if(ret < 0)
    {
        fprintf(stderr, "BMI_addr_lookup failure.\n");
        return(-1);
    }

    /* allocate some buffers for the req and ack */
    req = BMI_memalloc(server_addr, sizeof(struct request_foo),
                       BMI_SEND);
    ack = BMI_memalloc(server_addr, sizeof(struct ack_foo),
                       BMI_RECV);
    if(!ack || ! req)
    {
        fprintf(stderr, "BMI_memalloc failure.\n");
        return(-1);
    }

    /* send a message */
    ret = job_bmi_send(server_addr, req, sizeof(struct request_foo),
                       0, BMI_PRE_ALLOC, 1, NULL, 0, &status1, &tmp_id, context,
                       JOB_TIMEOUT_INF, NULL);
    if(ret < 0)
    {
        fprintf(stderr, "job_bmi_send() failure.\n");
        return(-1);
    }
    if(ret == 0)
    {
        int count = 0;
        ret = job_test(tmp_id, &count, NULL, &status1, -1, context);
        if(ret < 0)
        {
            fprintf(stderr, "job_test() failure.\n");
            return(-1);
        }
    }

    /* check status */
    if(status1.error_code != 0)
    {
        fprintf(stderr, "job failure.\n");
        return(-1);
    }

    /* receive a message */
    ret = job_bmi_recv(server_addr, ack, sizeof(struct ack_foo),
                       0, BMI_PRE_ALLOC, NULL, 0, &status1, &tmp_id, context,
                       JOB_TIMEOUT_INF, NULL);
    if(ret < 0)
    {
        fprintf(stderr, "job_bmi_recv() failure.\n");
        return(-1);
    }
    if(ret == 0)
    {
        int count = 0;
        ret = job_test(tmp_id, &count, NULL, &status1, -1, context);
        if(ret < 0)
        {
            fprintf(stderr, "job_test() failure.\n");
            return(-1);
        }
    }

    /* check status */
    if(status1.error_code != 0)
    {
        fprintf(stderr, "job failure.\n");
        return(-1);
    }

    /* check the size */
    if(status1.actual_size != sizeof(struct ack_foo))
    {
        fprintf(stderr, "short recv.\n");
        return(-1);
    }

    /* free memory buffers */
    BMI_memfree(server_addr, req, sizeof(struct request_foo),
                BMI_SEND);
    BMI_memfree(server_addr, ack, sizeof(struct ack_foo),
                BMI_RECV);

    /* shut down the interfaces */
    job_close_context(context);
    job_finalize();
    BMI_finalize();
    trove_finalize(TROVE_METHOD_DBPF);

    return(0);
}
Ejemplo n.º 5
0
int main(int argc, char **argv)
{
    int ret = 1;
    struct PINT_dev_unexp_info info;
    char buf1[] = "Hello ";
    char buf2[] = "World.";
    void* buffer_list[2];
    int size_list[2];
    job_context_id context;
    job_status_s jstat;
    job_id_t tmp_id;

    ret = PINT_dev_initialize("/dev/pvfs2-req", 0);
    if(ret < 0)
    {
        PVFS_perror("PINT_dev_initialize", ret);
        return(-1);
    }

    /* start the BMI interface */
    ret = BMI_initialize("bmi_tcp", NULL, 0);
    if(ret < 0)
    {
        fprintf(stderr, "BMI_initialize failure.\n");
        return(-1);
    }

    /* start the flow interface */
    ret = PINT_flow_initialize("flowproto_bmi_trove", 0);
    if(ret < 0)
    {
        fprintf(stderr, "flow init failure.\n");
        return(-1);
    }

    ret = job_initialize(0);
    if(ret < 0)
    {
        PVFS_perror("job_initialize", ret);
        return(-1);
    }

    ret = job_open_context(&context);
    if(ret < 0)
    {
        PVFS_perror("job_open_context", ret);
        return(-1);
    }

    /* post job for unexpected device messages */
    ret = job_dev_unexp(&info, NULL, 0, &jstat, &tmp_id, 0, context);
    if(ret < 0)
    {
        PVFS_perror("job_dev_unexp()", ret);
        return(-1);
    }
    if(ret == 0)
    {
        printf("no immed completion.\n");
        ret = block_on_job(tmp_id, NULL, &jstat, context);
        if(ret < 0)
        {
            PVFS_perror("block_on_job()", ret);
            return(-1);
        }
    }
    else
    {
        printf("immed completion.\n");
    }

    if(jstat.error_code != 0)
    {
        PVFS_perror("job_bmi_unexp() error code", jstat.error_code);
        return(-1);
    }

    printf("Got message: size: %d, tag: %d, payload: %s\n",
           info.size, (int)info.tag, (char*)info.buffer);

    PINT_dev_release_unexpected(&info);

    /* try writing a list message */
    buffer_list[0] = buf1;
    buffer_list[1] = buf2;
    size_list[0] = strlen(buf1);
    size_list[1] = strlen(buf1) + 1;

    ret = job_dev_write_list(buffer_list, size_list, 2, (strlen(buf1) +
                             strlen(buf2) + 1), 7, PINT_DEV_EXT_ALLOC, NULL, 0, &jstat, &tmp_id,
                             context);
    if(ret < 0)
    {
        PVFS_perror("job_dev_write_list()", ret);
        return(-1);
    }
    if(ret == 0)
    {
        printf("no immed completion.\n");
        ret = block_on_job(tmp_id, NULL, &jstat, context);
        if(ret < 0)
        {
            PVFS_perror("block_on_job()", ret);
            return(-1);
        }
    }
    else
    {
        printf("immed completion.\n");
    }

    if(jstat.error_code != 0)
    {
        PVFS_perror("job_bmi_write_list() error code", jstat.error_code);
        return(-1);
    }

    job_close_context(context);
    job_finalize();
    PINT_dev_finalize();
    PINT_flow_finalize();
    BMI_finalize();

    return(0);
}
Ejemplo n.º 6
0
int main(int argc, char **argv)	
{

	int ret = -1;
	struct ack_foo* ack = NULL;
	job_status_s status1;
	struct BMI_unexpected_info req_info;
	job_id_t job_id;
	int outcount;
	job_id_t tmp_id;
	job_context_id context;

	/* set debugging level */
	gossip_enable_stderr();
	gossip_set_debug_mask(0, 0);


	/* start the BMI interface */
	ret = BMI_initialize("bmi_tcp", "tcp://NULL:3414", BMI_INIT_SERVER);
	if(ret < 0)
	{
		fprintf(stderr, "BMI_initialize failure.\n");
		return(-1);
	}

	ret = trove_initialize(
	    TROVE_METHOD_DBPF, NULL, "/tmp/pvfs2-test-space", 0);
	if(ret < 0)
	{
		fprintf(stderr, "trove_initialize failure.\n");
		return(-1);
	}

	/* start the flow interface */
	ret = PINT_flow_initialize("flowproto_multiqueue", 0);
	if(ret < 0)
	{
		fprintf(stderr, "flow_init failure.\n");
		return(-1);
	}

	/* start the job interface */
	ret = job_initialize(0);
	if(ret < 0)
	{
		fprintf(stderr, "job_initialize failure.\n");
		return(-1);
	}

	ret = job_open_context(&context);
	if(ret < 0)
	{
		fprintf(stderr, "job_open_context() failure.\n");
		return(-1);
	}



	/* post a job for unexpected receive */
	ret = job_bmi_unexp(&req_info, NULL, 0, &status1, &job_id, 0, context);
	if(ret < 0)
	{
		fprintf(stderr, "job_bmi_unexp() failure.\n");
		return(-1);
	}
	if(ret != 1)
	{
#if 0
		/* exercise testworld() interface, block indefinitely */
		outcount = 1;
		ret = job_testworld(&job_id, &outcount, NULL, &status1, -1);
		if(ret < 0 || outcount == 0)
		{	
			fprintf(stderr, "job_testworld() failure.\n");
			return(-1);
		}

		/* alternatively, try out the testsome interface */
		outcount = 1;
		ret = job_testsome(&job_id, &outcount, &foo, NULL, &status1, -1);
		if(ret < 0 || outcount == 0)
		{
			fprintf(stderr, "job_testsome() failure.\n");
			return(-1);
		}
#else

		/* ... or maybe even give job_test() a whirl */
		ret = job_test(job_id, &outcount, NULL, &status1, 5000, context);
		if(ret < 0 || outcount == 0)
		{
			fprintf(stderr, "job_test() failure.\n");
			return(-1);
		}

#endif
	}

	/* check status */
	if(status1.error_code != 0)
	{
		fprintf(stderr, "Bad status in unexp recv.\n");
		return(-1);
	}

	/* allocate a buffer for the ack */
	ack = BMI_memalloc(req_info.addr, sizeof(struct ack_foo),
		BMI_SEND);
	if(!ack)
	{
		fprintf(stderr, "BMI_memalloc failure.\n");
		return(-1);
	}

	/* send a message */
	ret = job_bmi_send(req_info.addr, ack, sizeof(struct ack_foo),
		0, BMI_PRE_ALLOC, 0, NULL, 0, &status1, &tmp_id, context,
		JOB_TIMEOUT_INF, NULL);
	if(ret < 0)
	{
		fprintf(stderr, "job_bmi_send() failure.\n");
		return(-1);
	}
	if(ret == 0)
	{
		int count = 0;
		ret = job_test(tmp_id, &count, NULL, &status1, -1, context);
		if(ret < 0)
		{
			fprintf(stderr, "job_test() failure.\n");
			return(-1);
		}
	}


	/* check status */
	if(status1.error_code != 0)
	{
		fprintf(stderr, "job failure.\n");
		return(-1);
	}

	BMI_memfree(req_info.addr, ack, sizeof(struct ack_foo), BMI_RECV);
	BMI_unexpected_free(req_info.addr, req_info.buffer);

	/* shut down the interfaces */
	job_close_context(context);
	job_finalize();
	PINT_flow_finalize();
	BMI_finalize();
	trove_finalize(TROVE_METHOD_DBPF);

	return(0);
}
Ejemplo n.º 7
0
/**
 * gstreamill_job_start:
 * @job: (in): json type of job description.
 *
 * Returns: json type of job execution result. 
 */
gchar * gstreamill_job_start (Gstreamill *gstreamill, gchar *job_desc)
{
        gchar *p, *name;
        Job *job;

        if (!jobdesc_is_valid (job_desc)) {
                p = g_strdup ("Invalid job");
                return p;
        }

        if (jobdesc_is_live (job_desc)) {
                GST_ERROR ("live job arrived");

        } else {
                GST_ERROR ("transcode job arrived");
        }

        /* create job object */
        name = jobdesc_get_name (job_desc);
        if (get_job (gstreamill, name) != NULL) {
                GST_ERROR ("start live job failure, duplicated name %s.", name);
                p = g_strdup_printf ("start live job failure, duplicated name %s.", name);
                g_free (name);
                return p;
        }
        job = job_new ("job", job_desc, "name", name, NULL);
        g_free (name);

        /* job initialize */
        job->log_dir = gstreamill->log_dir;
        g_mutex_init (&(job->access_mutex));
        job->is_live = jobdesc_is_live (job_desc);
        job->eos = FALSE;
        job->current_access = 0;
        job->age = 0;
        job->last_start_time = NULL;
        if (job_initialize (job, gstreamill->daemon) != 0) {
                p = g_strdup ("initialize job failure");
                g_object_unref (job);
                return p;
        }

        /* reset and start job */
        job_reset (job);
        if (gstreamill->daemon) {
                p = create_job_process (job);
                GST_ERROR ("%s: %s", p, job->name);
                if (g_str_has_suffix (p, "success")) {
                        g_mutex_lock (&(gstreamill->job_list_mutex));
                        gstreamill->job_list = g_slist_append (gstreamill->job_list, job);
                        g_mutex_unlock (&(gstreamill->job_list_mutex));

                } else {
                        g_object_unref (job);
                }

        } else {
                if (job_start (job) == 0) {
                        g_mutex_lock (&(gstreamill->job_list_mutex));
                        gstreamill->job_list = g_slist_append (gstreamill->job_list, job);
                        g_mutex_unlock (&(gstreamill->job_list_mutex));
                        p = g_strdup ("success");

                } else {
                        p = g_strdup ("failure");
                }
        }

        return p;
}