Ejemplo n.º 1
0
Call builtin_setBeat(Env parent_env, Args args) {
    Number n = (Number)args_get(args, 0);
    Closure k = (Closure)args_get(args, 1);
    tone(PIEZO_PIN, (int)n->value);
    delay(60000 / tempo);
    return create_call(k, create_args(0));
}
Ejemplo n.º 2
0
void start_echo(char *arg)
{
	struct timeval tv;
	gettimeofday(&tv,NULL);
	start = (uint64_t)tv.tv_sec;
	//while(!interrupt) 
	//{
		char *actionid = getActionid();
		zmsg_t *msg = create_call(actionid, "worker", "sleep", arg);
		if (msg) 
		{
			zmsg_send(&msg, dealer);
			counter ++;
			zmsg_destroy(&msg);
			zmsg_t *msg = zmsg_recv(dealer);
			zframe_t *payload = zmsg_pop(msg);
			zmsg_destroy(&msg);
			msgpack_unpacked object;
			msgpack_unpacked_init(&object);
		
			if (msgpack_unpack_next(&object, (char*)zframe_data(payload), zframe_size(payload) , NULL))
			{
				//zclock_log("message");
				//msgpack_object_print(stdout, object.data);
				char *command = (char*)m_lookup(object.data, "command");
				if (command) {
					//zclock_log("command: %s", command);
					if (streq(command, "exception")) {
						failed++;
						zclock_log("exception");
					}
					if (streq(command, "result")) {
						success++;
						zclock_log("result ok");
					}
					free(command);
				}
			}
			msgpack_unpacked_destroy(&object);
			zframe_destroy(&payload);
		}
		
		gettimeofday(&tv,NULL);
		uint64_t end = (uint64_t)tv.tv_sec;
		if ((end - start) == 1) 
		{
			float speed = counter/(end-start);
			zclock_log("speed %f m/s, failed %ld, success %ld", speed, failed, success);
			counter = 0;
			failed = 0;
			success = 0;
			start = end;
		} 
	//} //end while
}
Ejemplo n.º 3
0
static gboolean call_added(DBusConnection *conn,
				DBusMessage *msg, void *user_data)
{
	struct modem_data *modem = user_data;
	DBusMessageIter iter, dict;
	const char *path;

	if (dbus_message_iter_init(msg, &iter) == FALSE)
		return TRUE;

	dbus_message_iter_get_basic(&iter, &path);

	dbus_message_iter_next(&iter);
	dbus_message_iter_recurse(&iter, &dict);

	create_call(modem, path, &iter);

	return TRUE;
}
Ejemplo n.º 4
0
static void get_calls_reply(DBusPendingCall *call, void *user_data)
{
	struct modem_data *modem = user_data;
	DBusMessage *reply = dbus_pending_call_steal_reply(call);
	DBusMessageIter iter, list;
	DBusError err;

	dbus_error_init(&err);

	if (dbus_set_error_from_message(&err, reply) == TRUE) {
		g_printerr("%s: %s\n", err.name, err.message);
		dbus_error_free(&err);
		goto done;
	}

	if (dbus_message_has_signature(reply, "a(oa{sv})") == FALSE)
		goto done;

	if (dbus_message_iter_init(reply, &iter) == FALSE)
		goto done;

	dbus_message_iter_recurse(&iter, &list);

	while (dbus_message_iter_get_arg_type(&list) == DBUS_TYPE_STRUCT) {
		DBusMessageIter entry, dict;
		const char *path;

		dbus_message_iter_recurse(&list, &entry);
		dbus_message_iter_get_basic(&entry, &path);

		dbus_message_iter_next(&entry);
		dbus_message_iter_recurse(&entry, &dict);

		create_call(modem, path, &dict);

		dbus_message_iter_next(&list);
	}

done:
	dbus_message_unref(reply);
}
Ejemplo n.º 5
0
static int sleep_loop(zloop_t *loop, int item, void *arg)
{
	
	int *c = (int*)arg;
	int i;

	for (i = 0; i < *c; i++) 
	{
		if (interrupt)
			return -1;
		
		char *actionid = getActionid();
		zmsg_t *msg = create_call(actionid, "worker", "sleep", "echo");
		free(actionid);
		if (msg) {
			zmsg_send(&msg, dealer);
			counter ++;
		}
	}

	return 0;
}
Ejemplo n.º 6
0
Call builtin_setTempo(Env parent_env, Args args) {
    Number n = (Number)args_get(args, 0);
    Closure k = (Closure)args_get(args, 1);
    tempo = (int)n->value;
    return create_call(k, create_args(0));
}