//------------------------------------------------------------------------------
// Main function to generate module files in current directory
//------------------------------------------------------------------------------
int main(int argc, char* argv[]){

   // Strings for command line options
   std::string namespace_name="";
   std::string author="";
   std::string email="";

   // determine namespace name, author and email from command line
   process_command_line(argc, argv, namespace_name, author, email);

   // create file header
   std::string file_header = create_file_header(author, email);

   // Generate data.cpp
   create_data(file_header, namespace_name);

   // Generate interface.cpp
   create_interface(file_header, namespace_name);

   // Generate initialise.cpp
   create_initialise(file_header, namespace_name);

   // Generate internal.hpp
   create_internal(file_header, namespace_name);

   // Generate internal.hpp
   create_module(file_header, namespace_name);

   // Generate makefile
   create_makefile(file_header, namespace_name);

   return EXIT_SUCCESS;

}
static jint create(JNIEnv *env, jobject thiz, jint mtu)
{
    int tun = create_interface(mtu);
    if (tun < 0) {
        throwException(env, tun, "Cannot create interface");
        return -1;
    }
    return tun;
}
/** Open interface for writing.
 * This will create a new interface instance of the given type. The result can be
 * casted to the appropriate type. This will only succeed if there is not already
 * a writer for the given interface type/id!
 * @param type type of the interface
 * @param identifier identifier of the interface
 * @return new fully initialized interface instance of requested type
 * @exception OutOfMemoryException thrown if there is not enough free space for
 * the requested interface.
 * @exception BlackBoardWriterActiveException thrown if there is already a writing
 * instance with the same type/id
 */
Interface *
BlackBoardInterfaceManager::open_for_writing(const char *type, const char *identifier)
{
  mutex->lock();
  memmgr->lock();

  Interface *iface = NULL;
  void *ptr = NULL;
  interface_header_t *ih;
  bool created = false;

  try {
    ptr = find_interface_in_memory(type, identifier);

    if ( ptr != NULL ) {
      // found, check if there is already a writer
      //instantiate new interface for given memory chunk
      ih  = (interface_header_t *)ptr;
      if ( ih->flag_writer_active ) {
	throw BlackBoardWriterActiveException(identifier, type);
      }
      iface = new_interface_instance(type, identifier);
      if ( (iface->hash_size() != __INTERFACE_HASH_SIZE ) ||
	   (memcmp(iface->hash(), ih->hash, __INTERFACE_HASH_SIZE) != 0) ) {
	throw BlackBoardInterfaceVersionMismatchException();
      }
      iface->set_memory(ih->serial, ptr, (char *)ptr + sizeof(interface_header_t));
      rwlocks[ih->serial]->ref();
    } else {
      created = true;
      create_interface(type, identifier, iface, ptr);
      ih = (interface_header_t *)ptr;
    }

    iface->set_readwrite(true, rwlocks[ih->serial]);
    ih->flag_writer_active = 1;
    ih->refcount++;

    memmgr->unlock();
    writer_interfaces[ih->serial] = iface;

    mutex->unlock();

    if ( created ) {
      notifier->notify_of_interface_created(type, identifier);
    }
    notifier->notify_of_writer_added(iface, iface->serial());
  } catch (Exception &e) {
    if (iface)  delete_interface_instance(iface);
    memmgr->unlock();
    mutex->unlock();
    throw;
  }

  return iface;
}
Exemplo n.º 4
0
/*!
	Creates a new interface.
*/
long Patch::create_interface(ElementInfo::Type type)
{
	long id;
	if (m_unusedInterfaceIds.empty()) {
		id = m_interfaces.size();
	} else {
		id = m_unusedInterfaceIds.front();
		m_unusedInterfaceIds.pop_front();
	}

	return create_interface(id, type);
}
Exemplo n.º 5
0
int supplicant_start(struct connman_device *device)
{
	struct supplicant_task *task;
	int err;

	_DBG_SUPPLICANT("device %p", device);

	task = g_try_new0(struct supplicant_task, 1);
	if (task == NULL)
		return -ENOMEM;

	task->ifindex = connman_device_get_index(device);
	task->ifname = connman_inet_ifname(task->ifindex);

	if (task->ifname == NULL) {
		err = -ENOMEM;
		goto failed;
	}

	task->mac80211 = connman_inet_is_mac80211(task->ifindex);
	if (task->mac80211 == FALSE)
		connman_warn("Enabling quirks for unsupported driver");

	task->range = g_try_malloc0(sizeof(struct iw_range));
	if (task->range == NULL) {
		err = -ENOMEM;
		goto failed;
	}

	err = get_range(task);
	if (err < 0)
		goto failed;

	task->device = connman_device_ref(device);

	task->created = FALSE;
	task->scanning = FALSE;
	task->state = WPA_INVALID;
	task->disconnecting = FALSE;
	task->pending_network = NULL;

	task_list = g_slist_append(task_list, task);

	return create_interface(task);

failed:
	g_free(task->range);
	g_free(task->ifname);
	g_free(task);

	return err;
}
Exemplo n.º 6
0
status_t
add_interface_to_domain(net_domain* _domain,
	struct ifreq& request)
{
	net_domain_private* domain = (net_domain_private*)_domain;

	const char* deviceName = request.ifr_parameter.device[0]
		? request.ifr_parameter.device : request.ifr_name;
	const char* baseName = request.ifr_parameter.base_name[0]
		? request.ifr_parameter.base_name : request.ifr_name;

	net_device_interface* deviceInterface = get_device_interface(deviceName);
	if (deviceInterface == NULL)
		return ENODEV;

	RecursiveLocker locker(domain->lock);

	net_interface_private* interface = NULL;
	status_t status;

	if (find_interface(domain, request.ifr_name) == NULL) {
		// We must not hold the domain's link when creating the interface:
		// this will call get_module() which might want to access a network
		// device when booting from network.
		locker.Unlock();
		status = create_interface(domain, request.ifr_name,
			baseName, deviceInterface, &interface);
		locker.Lock();

		if (find_interface(domain, request.ifr_name) != NULL) {
			delete_interface(interface);
			status = B_NAME_IN_USE;
		}
	} else
		status = B_NAME_IN_USE;

	put_device_interface(deviceInterface);

	if (status == B_OK) {
		list_add_item(&domain->interfaces, interface);
		notify_interface_added(interface);
	}

	return status;
}
Exemplo n.º 7
0
int		run()
{
    fd_set	fds;
    int		max_fd;

    create_interface(&interface);
    running = true;
    accueil = NULL;
    accueil = create_channel("Accueil", 1, NULL);
    set_current_channel(accueil);
    while (running)
    {
        max_fd = init_fd(&fds);
        if (select(max_fd + 1, &fds, NULL, NULL, NULL) > 0)
            process_fd(&fds);
    }
    destroy_interface(&interface);
    return (0);
}
Exemplo n.º 8
0
/** Open interface for reading.
 * This will create a new interface instance of the given type. The result can be
 * casted to the appropriate type.
 * @param type type of the interface
 * @param identifier identifier of the interface
 * @param owner name of entity which opened this interface. If using the BlackBoardAspect
 * to access the blackboard leave this untouched unless you have a good reason.
 * @return new fully initialized interface instance of requested type
 * @exception OutOfMemoryException thrown if there is not enough free space for
 * the requested interface.
 */
Interface *
BlackBoardInterfaceManager::open_for_reading(const char *type, const char *identifier, const char *owner)
{
  if (strlen(type) > __INTERFACE_TYPE_SIZE) {
    throw Exception("Interface type '%s' too long, maximum length is %zu",
		    type, __INTERFACE_TYPE_SIZE);
  }
  if (strlen(identifier) > __INTERFACE_ID_SIZE) {
    throw Exception("Interface ID '%s' too long, maximum length is %zu",
		    type, __INTERFACE_ID_SIZE);
  }

  mutex->lock();
  Interface *iface = NULL;
  void *ptr = NULL;
  interface_header_t *ih;
  bool created = false;

  memmgr->lock();

  ptr = find_interface_in_memory(type, identifier);

  try {
    if ( ptr != NULL ) {
      // found, instantiate new interface for given memory chunk
      iface = new_interface_instance(type, identifier, owner);
      ih  = (interface_header_t *)ptr;
      if ( (iface->hash_size() != __INTERFACE_HASH_SIZE ) ||
	   (memcmp(iface->hash(), ih->hash, __INTERFACE_HASH_SIZE) != 0) ) {
	throw BlackBoardInterfaceVersionMismatchException();
      }
      iface->set_memory(ih->serial, ptr, (char *)ptr + sizeof(interface_header_t));
      rwlocks[ih->serial]->ref();
    } else {
      created = true;
      create_interface(type, identifier, owner, iface, ptr);
      ih  = (interface_header_t *)ptr;
    }

    owner_info_[iface->uid()].readers.push_back(iface);
    iface->set_readwrite(false, rwlocks[ih->serial]);
    ih->refcount++;
    ih->num_readers++;

    memmgr->unlock();
    mutex->unlock();

    if ( created ) {
      notifier->notify_of_interface_created(type, identifier);
    }
    notifier->notify_of_reader_added(iface, iface->serial());

  } catch (Exception &e) {
    if (iface)  delete_interface_instance(iface);
    memmgr->unlock();
    mutex->unlock();
    throw;
  }

  return iface;
}
Exemplo n.º 9
0
static void
start_element(void *data, const char *element_name, const char **atts)
{
	struct parse_context *ctx = data;
	struct interface *interface;
	struct message *message;
	struct arg *arg;
	struct enumeration *enumeration;
	struct entry *entry;
	struct description *description = NULL;
	const char *name = NULL;
	const char *type = NULL;
	const char *interface_name = NULL;
	const char *value = NULL;
	const char *summary = NULL;
	const char *since = NULL;
	const char *allow_null = NULL;
	const char *enumeration_name = NULL;
	const char *bitfield = NULL;
	int i, version = 0;

	ctx->loc.line_number = XML_GetCurrentLineNumber(ctx->parser);
	for (i = 0; atts[i]; i += 2) {
		if (strcmp(atts[i], "name") == 0)
			name = atts[i + 1];
		if (strcmp(atts[i], "version") == 0) {
			version = strtouint(atts[i + 1]);
			if (version == -1)
				fail(&ctx->loc, "wrong version (%s)", atts[i + 1]);
		}
		if (strcmp(atts[i], "type") == 0)
			type = atts[i + 1];
		if (strcmp(atts[i], "value") == 0)
			value = atts[i + 1];
		if (strcmp(atts[i], "interface") == 0)
			interface_name = atts[i + 1];
		if (strcmp(atts[i], "summary") == 0)
			summary = atts[i + 1];
		if (strcmp(atts[i], "since") == 0)
			since = atts[i + 1];
		if (strcmp(atts[i], "allow-null") == 0)
			allow_null = atts[i + 1];
		if (strcmp(atts[i], "enum") == 0)
			enumeration_name = atts[i + 1];
		if (strcmp(atts[i], "bitfield") == 0)
			bitfield = atts[i + 1];
	}

	ctx->character_data_length = 0;
	if (strcmp(element_name, "protocol") == 0) {
		if (name == NULL)
			fail(&ctx->loc, "no protocol name given");

		ctx->protocol->name = xstrdup(name);
		ctx->protocol->uppercase_name = uppercase_dup(name);
	} else if (strcmp(element_name, "copyright") == 0) {

	} else if (strcmp(element_name, "interface") == 0) {
		if (name == NULL)
			fail(&ctx->loc, "no interface name given");

		if (version == 0)
			fail(&ctx->loc, "no interface version given");

		interface = create_interface(ctx->loc, name, version);
		ctx->interface = interface;
		wl_list_insert(ctx->protocol->interface_list.prev,
			       &interface->link);
	} else if (strcmp(element_name, "request") == 0 ||
		   strcmp(element_name, "event") == 0) {
		if (name == NULL)
			fail(&ctx->loc, "no request name given");

		message = create_message(ctx->loc, name);

		if (strcmp(element_name, "request") == 0)
			wl_list_insert(ctx->interface->request_list.prev,
				       &message->link);
		else
			wl_list_insert(ctx->interface->event_list.prev,
				       &message->link);

		if (type != NULL && strcmp(type, "destructor") == 0)
			message->destructor = 1;

		version = version_from_since(ctx, since);

		if (version < ctx->interface->since)
			warn(&ctx->loc, "since version not increasing\n");
		ctx->interface->since = version;
		message->since = version;

		if (strcmp(name, "destroy") == 0 && !message->destructor)
			fail(&ctx->loc, "destroy request should be destructor type");

		ctx->message = message;
	} else if (strcmp(element_name, "arg") == 0) {
		if (name == NULL)
			fail(&ctx->loc, "no argument name given");

		arg = create_arg(name);
		if (!set_arg_type(arg, type))
			fail(&ctx->loc, "unknown type (%s)", type);

		switch (arg->type) {
		case NEW_ID:
			ctx->message->new_id_count++;
			/* fallthrough */
		case OBJECT:
			if (interface_name)
				arg->interface_name = xstrdup(interface_name);
			break;
		default:
			if (interface_name != NULL)
				fail(&ctx->loc, "interface attribute not allowed for type %s", type);
			break;
		}

		if (allow_null) {
			if (strcmp(allow_null, "true") == 0)
				arg->nullable = 1;
			else if (strcmp(allow_null, "false") != 0)
				fail(&ctx->loc,
				     "invalid value for allow-null attribute (%s)",
				     allow_null);

			if (!is_nullable_type(arg))
				fail(&ctx->loc,
				     "allow-null is only valid for objects, strings, and arrays");
		}

		if (enumeration_name == NULL || strcmp(enumeration_name, "") == 0)
			arg->enumeration_name = NULL;
		else
			arg->enumeration_name = xstrdup(enumeration_name);

		if (summary)
			arg->summary = xstrdup(summary);

		wl_list_insert(ctx->message->arg_list.prev, &arg->link);
		ctx->message->arg_count++;
	} else if (strcmp(element_name, "enum") == 0) {
		if (name == NULL)
			fail(&ctx->loc, "no enum name given");

		enumeration = create_enumeration(name);

		if (bitfield == NULL || strcmp(bitfield, "false") == 0)
			enumeration->bitfield = false;
		else if (strcmp(bitfield, "true") == 0)
			enumeration->bitfield = true;
		else
			fail(&ctx->loc,
			     "invalid value (%s) for bitfield attribute (only true/false are accepted)",
			     bitfield);

		wl_list_insert(ctx->interface->enumeration_list.prev,
			       &enumeration->link);

		ctx->enumeration = enumeration;
	} else if (strcmp(element_name, "entry") == 0) {
		if (name == NULL)
			fail(&ctx->loc, "no entry name given");

		entry = create_entry(name, value);
		version = version_from_since(ctx, since);

		if (version < ctx->enumeration->since)
			warn(&ctx->loc, "since version not increasing\n");
		ctx->enumeration->since = version;
		entry->since = version;

		if (summary)
			entry->summary = xstrdup(summary);
		else
			entry->summary = NULL;
		wl_list_insert(ctx->enumeration->entry_list.prev,
			       &entry->link);
	} else if (strcmp(element_name, "description") == 0) {
		if (summary == NULL)
			fail(&ctx->loc, "description without summary");

		description = xzalloc(sizeof *description);
		description->summary = xstrdup(summary);

		if (ctx->message)
			ctx->message->description = description;
		else if (ctx->enumeration)
			ctx->enumeration->description = description;
		else if (ctx->interface)
			ctx->interface->description = description;
		else
			ctx->protocol->description = description;
		ctx->description = description;
	}
}