ArrayDatum
ConnectionManager::get_connections( DictionaryDatum params ) const
{
  ArrayDatum connectome;

  const Token& source_t = params->lookup( names::source );
  const Token& target_t = params->lookup( names::target );
  const Token& syn_model_t = params->lookup( names::synapse_model );
  const TokenArray* source_a = 0;
  const TokenArray* target_a = 0;

  if ( not source_t.empty() )
    source_a = dynamic_cast< TokenArray const* >( source_t.datum() );
  if ( not target_t.empty() )
    target_a = dynamic_cast< TokenArray const* >( target_t.datum() );

  size_t syn_id = 0;

#ifdef _OPENMP
  std::string msg;
  msg = String::compose( "Setting OpenMP num_threads to %1.", net_.get_num_threads() );
  net_.message( SLIInterpreter::M_DEBUG, "ConnectionManager::get_connections", msg );
  omp_set_num_threads( net_.get_num_threads() );
#endif

  // First we check, whether a synapse model is given.
  // If not, we will iterate all.
  if ( not syn_model_t.empty() )
  {
    Name synmodel_name = getValue< Name >( syn_model_t );
    const Token synmodel = synapsedict_->lookup( synmodel_name );
    if ( !synmodel.empty() )
      syn_id = static_cast< size_t >( synmodel );
    else
      throw UnknownModelName( synmodel_name.toString() );
    get_connections( connectome, source_a, target_a, syn_id );
  }
  else
  {
    for ( syn_id = 0; syn_id < prototypes_[ 0 ].size(); ++syn_id )
    {
      ArrayDatum conn;
      get_connections( conn, source_a, target_a, syn_id );
      if ( conn.size() > 0 )
        connectome.push_back( new ArrayDatum( conn ) );
    }
  }

  return connectome;
}
Esempio n. 2
0
/**
 * Removes a connection object from the conn_t list.
 *
 * conn: The conn_t to free.
 */
void conn_free(conn_t *conn) {
  /* Free up chunks. */
  chunk_t *chunk, *next_chunk;
  for (chunk = conn->out_queue; chunk; chunk = next_chunk) {
    next_chunk = chunk->next;
    free(chunk);
  }

  /* Adjust pointers. */
  if (conn->next)
    conn->next->prev = conn->prev;
  if (conn->prev)
    *conn->prev = conn->next;

  if (conn == get_connections()) {
    if (SERVER)
      config->connections = NULL;
    else
      config->sconn = NULL;
  }

  /* Close pipes to program, if it's running. */
  if (run_program) {
    close(conn->stdin);
    close(conn->stdout);
  }
  free(conn);
}
Esempio n. 3
0
static void read_index_list_complete(int sk, void *buf, size_t len)
{
	struct mgmt_rp_read_index_list *rp = buf;
	uint16_t num;
	int i;

	if (len < sizeof(*rp)) {
		error("Too small read index list complete event");
		return;
	}

	num = btohs(bt_get_unaligned(&rp->num_controllers));

	if (num * sizeof(uint16_t) + sizeof(*rp) != len) {
		error("Incorrect packet size for index list event");
		return;
	}

	for (i = 0; i < num; i++) {
		uint16_t index;

		index = btohs(bt_get_unaligned(&rp->index[i]));

		add_controller(index);
		get_connections(sk, index);
		clear_uuids(index);
	}
}
Esempio n. 4
0
Variant Shader::_get(const String& p_name) const {

	if (p_name.begins_with("nodes/")) {
		int idx=p_name.get_slice("/",1).to_int();
		Dictionary data;
		data["type"]=VisualServer::shader_node_get_type_info((VS::ShaderNodeType)node_get_type(idx)).name;
		data["pos"]=node_get_pos(idx);
		data["param"]=node_get_param(idx);
		return data;
	}
	if (p_name.begins_with("conns/")) {
		int idx=p_name.get_slice("/",1).to_int();
		Dictionary data;

		List<Connection> connections;
		get_connections(&connections);
		ERR_FAIL_INDEX_V( idx,connections.size(), Variant() );
		Connection c = connections[idx];

		data["src_id"]=c.src_id;
		data["src_slot"]=c.src_slot;
		data["dst_id"]=c.dst_id;
		data["dst_slot"]=c.dst_slot;
		return data;
	}

	return Variant();
}
Esempio n. 5
0
/**
 * Delete all connections.
 */
void delete_all_connections() {
  /* Delete connections if needed. */
  conn_t *conn, *next;
  for (conn = get_connections(); conn != NULL; conn = next) {
    next = conn->next;
    if (conn->delete_me)
      conn_free(conn);
  }
}
std::ostream & t_diagnostic_system::json (std::ostream & out) const {
    out << '{';
    json_write(out, "generators")<< ':';
    json_write(out, get_generators()) << ',';
    json_write(out, "rankers")<< ':';
    json_write(out, get_rankers()) << ',';
    json_write(out, "connections")<< ':';
    json_write(out, get_connections()) << '}';
    return out;
}
Esempio n. 7
0
/**
 * gfbgraph_connectable_is_connectable_to:
 * @self: a #GFBGraphConnectable.
 * @node_type: a #GType, required a #GFBGRAPH_TYPE_NODE or children.
 *
 * Check if @self object, normally a #GFBGraphNode implementing the #GFBGraphConnectable interface,
 * has the possibility to be connected to another node of type @node_type.
 *
 * Returns: %TRUE in case that the @self object can be connected to a node of type @node_type,
 * %FALSE otherwise.
 **/
gboolean
gfbgraph_connectable_is_connectable_to (GFBGraphConnectable *self, GType node_type)
{
        GFBGraphConnectableInterface *iface;
        GHashTable *connections;

        g_return_val_if_fail (GFBGRAPH_IS_CONNECTABLE (self), FALSE);
        g_return_val_if_fail (g_type_is_a (node_type, GFBGRAPH_TYPE_NODE), FALSE);

        iface = GFBGRAPH_CONNECTABLE_GET_IFACE (self);

        connections = get_connections (iface);
        return g_hash_table_contains (connections, g_type_name (node_type));
}
Esempio n. 8
0
/**
 * gfbgraph_connectable_get_connection_path:
 * @self: a #GFBGraphConnectable.
 * @node_type: a #GType, required a #GFBGRAPH_TYPE_NODE or children.
 *
 * Get the Facebook Graph API function path to retrieve the nodes connected with @node_type
 * managed by the #GFBGraphConnectable object.
 *
 * Returns: (transfer none): a const #gchar with the function path or %NULL.
 **/
const gchar*
gfbgraph_connectable_get_connection_path (GFBGraphConnectable *self, GType node_type)
{
        GFBGraphConnectableInterface *iface;
        GHashTable *connections;

        g_return_val_if_fail (GFBGRAPH_IS_CONNECTABLE (self), NULL);
        g_return_val_if_fail (g_type_is_a (node_type, GFBGRAPH_TYPE_NODE), NULL);
        g_return_val_if_fail (gfbgraph_connectable_is_connectable_to (self, node_type), NULL);

        iface = GFBGRAPH_CONNECTABLE_GET_IFACE (self);

        connections = get_connections (iface);
        return (const gchar *) g_hash_table_lookup (connections, g_type_name (node_type));
}
Esempio n. 9
0
/**
 * Add to the conn_t list.
 *
 * conn_list: Pointer to linked list of conn_t objects.
 * conn: The new conn_t to add.
 */
void conn_add(conn_t *conn) {
  conn_t *conn_list = get_connections();

  if (conn != conn_list) {
    conn->prev = &conn_list;
    conn->next = conn_list;

    if (conn_list)
      conn_list->prev = &conn->next;
  }
  conn->out_queue_tail = &conn->out_queue;

  if (SERVER)
    config->connections = conn;
  else
    config->sconn = conn;
}
Esempio n. 10
0
/**
 * Naive filtering. Host might receive many unwanted packets or leftover
 * packets from a previous session. We drop these packets.
 *
 * sockfd: Socket file descriptor.
 * buf: Buffer to receive data into.
 * len: Length of buffer and maximum size of data to receive.
 * flags: Flags for recv.
 * rconn: Return parameter. Pointer to the connection state associated with
 *        the sender of the packet.
 *
 * returns: Length of packet if packet wasn't dropped, 0 if no packet
 *          received, and -1 on failure.
 */
int recv_filter(int sockfd, void *buf, size_t len, int flags, conn_t **rconn) {
  int r = recv(sockfd, buf, len, flags);
  if (r < 0)
    return -1;

  if (r < FULL_HDR_SIZE)
    return 0;

  /* Is this packet to us? If not, ignore it. */
  iphdr_t *ip_hdr = (iphdr_t *) buf;
  tcphdr_t *tcp_hdr = (tcphdr_t *) (buf + IP_HDR_SIZE);
  if (tcp_hdr->th_dport != htons(config->port))
    return 0;

  /* A RST packet. End connection. */
  if (tcp_hdr->th_flags & TH_RST) {
    fprintf(stderr, "[ERROR] Server sent a RST! Closing connection.\n");
    exit(EXIT_FAILURE);
  }

  /* Otherwise a SYN or SYN-ACK? */
  if (tcp_hdr->th_flags & TH_SYN)
    return r;

  /* Some other packet from somewhere where we've already established a
     connection. Must have the correct source IP, port, and a sequence
     number we expect. */
  conn_t *conn = get_connections();
  while (conn != NULL) {
    if (conn->port == ntohs(tcp_hdr->th_sport) &&
        (unix_socket || (!unix_socket && conn->ip_addr == ip_hdr->saddr)) &&
        ntohl(tcp_hdr->th_seq) >= conn->their_init_seqno &&
        ntohl(tcp_hdr->th_ack) >= conn->init_seqno) {
      /* Return associated connection. */
      if (rconn != NULL)
        *rconn = conn;

      return r;
    }
    conn = conn->next;
  }

  return 0;
}
Esempio n. 11
0
void Shader::_get_property_list( List<PropertyInfo> *p_list) const {

	List<int> nodes;
	get_node_list(&nodes);

	for(List<int>::Element *E=nodes.front();E;E=E->next()) {

		int idx=E->get();
		p_list->push_back(PropertyInfo( Variant::DICTIONARY , "nodes/"+itos(idx),PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NETWORK|PROPERTY_USAGE_STORAGE ) );
	}

	List<Connection> connections;
	get_connections(&connections);
	int idx=0;
	for(List<Connection>::Element *E=connections.front();E;E=E->next()) {
		p_list->push_back(PropertyInfo( Variant::DICTIONARY , "conns/"+itos(idx++),PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NETWORK|PROPERTY_USAGE_STORAGE ) );
	}

}
Esempio n. 12
0
Array Shader::_get_connections_helper() const {

	Array connections_ret;
	List<Connection> connections;
	get_connections(&connections);
	connections_ret.resize(connections.size());

	int idx=0;
	for(List<Connection>::Element *E=connections.front();E;E=E->next()) {

		Connection c = E->get();
		Dictionary data;
		data["src_id"]=c.src_id;
		data["src_slot"]=c.src_slot;
		data["dst_id"]=c.dst_id;
		data["dst_slot"]=c.dst_slot;
		connections_ret.set(idx++,data);
	}

	return connections_ret;
}
Esempio n. 13
0
/**
 * Main loop. Handles the following:
 *   - Input from STDIN.
 *   - Messages from programs.
 *   - Packets from the socket.
 *   - Timeouts.
 */
void do_loop() {
  char buf[MAX_PACKET_SIZE];
  conn_t *conn = NULL;

  while (true) {
    memset(buf, 0, MAX_PACKET_SIZE);
    poll(events, NUM_POLL + num_connected,
         need_timer_in(&last_timeout, ctcp_cfg->timer));

    /* Input from stdin. Server will only send to most-recently connected
       client. */
    if (!run_program && events[STDIN_FILENO].revents & POLLIN) {
      conn = get_connections();

      if (conn != NULL)
        ctcp_read(conn->state);
    }

    /* See if we can output more. */
    if (events[STDOUT_FILENO].revents & (POLLOUT | POLLHUP | POLLERR)) {
      for (conn = get_connections(); conn; conn = conn->next) {
        conn_drain(conn);
      }
    }

    /* Poll for output received from running programs. Send to client
       client associated with this program instance. */
    if (run_program) {
      conn = get_connections();
      while (conn != NULL) {
        if (conn->poll_fd->revents & POLLIN) {
          ctcp_read(conn->state);
        }
        conn = conn->next;
      }
    }

    /* Receive packet on socket from other hosts. Ignore packets if they are
       not large enough or not for us. */
    if (events[2].revents & POLLIN) {
      conn = NULL;
      int len = recv_filter(config->socket, buf, MAX_PACKET_SIZE, 0, &conn);
      if (len >= FULL_HDR_SIZE) {
        tcphdr_t *tcp_hdr = (tcphdr_t *) (buf + IP_HDR_SIZE);

        /* Packet from an established connection. Pass to student code. */
        if (conn != NULL) {
          ctcp_segment_t *segment = convert_to_ctcp(conn, buf, len);
          len = len - FULL_HDR_SIZE + sizeof(ctcp_segment_t);

          /* Don't log or forward to student code if it's an ACK from a new
             connection. */
          if (tcp_hdr->th_sport == new_connection &&
              (segment->flags & TH_ACK) &&
              ntohl(segment->seqno) == 1 && ntohl(segment->ackno) == 1) {
            new_connection = 0;
            free(segment);
          }
          else {
            if (log_file != -1 || test_debug_on) {
              log_segment(log_file, config->ip_addr, config->port, conn,
                          segment, len, false, unix_socket);
            }
            ctcp_receive(conn->state, segment, len);
          }
        }

        /* New connection. */
        else if (tcp_hdr->th_flags & TH_SYN) {
          conn_t *conn = tcp_new_connection(buf);

          /* Start a new program associated with this client. */
          if (run_program && conn)
            execute_program(conn);
          new_connection = tcp_hdr->th_sport;
        }
      }
    }

    /* Check if timer is up. */
    if (need_timer_in(&last_timeout, ctcp_cfg->timer) == 0) {
      ctcp_timer();
      get_time(&last_timeout);
    }

    /* Delete connections if needed. */
    delete_all_connections();
  }
}
 bool isConnected() const
   {
   auto network = App->get_network();
   return static_cast<unsigned int>(network->get_connections().size()) > 0;
   }
Esempio n. 15
0
LRESULT CALLBACK TcpReceiveDlgHandler( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	TCP_RECEIVEOBJ * st;
	char writebuf[100],szdata[100];
	char readbuf[readbuflength];
	int result;
	static int actchn;

	st = (TCP_RECEIVEOBJ *) actobject;
    if ((st==NULL)||(st->type!=OB_TCP_RECEIVER)) return(FALSE);
 

	switch( message )
	{
		case WM_INITDIALOG:
				SetDlgItemText(hDlg, IDC_HOST, st->host);
			    EnableWindow(GetDlgItem(hDlg, IDC_SELECTCOMBO), FALSE);
				actchn=0;
				update_header(hDlg,&st->header);
				update_channelcombo(hDlg, st->channel, st->header.channels);
				update_channel(hDlg,st->channel,actchn);

				if (st->sock) 
				{	
					char actsession[30];

					EnableWindow(GetDlgItem(hDlg, IDC_CONNECT), FALSE);

					if (st->watching)
					{
						add_to_listbox(hDlg,IDC_LIST, "Watching Values from Server.");
						EnableWindow(GetDlgItem(hDlg, IDC_WATCH), FALSE);
						EnableWindow(GetDlgItem(hDlg, IDC_STOP), TRUE);
						EnableWindow(GetDlgItem(hDlg, IDC_CLOSE), FALSE);
					}
					else
					{
						add_to_listbox(hDlg,IDC_LIST, "Socket connected.");
						if (st->streamnum>=0)  EnableWindow(GetDlgItem(hDlg, IDC_WATCH), TRUE);
						else { EnableWindow(GetDlgItem(hDlg, IDC_WATCH), FALSE);
						EnableWindow(GetDlgItem(hDlg, IDC_SELECTCOMBO), TRUE); }
						EnableWindow(GetDlgItem(hDlg, IDC_STOP), FALSE);
						EnableWindow(GetDlgItem(hDlg, IDC_CLOSE), TRUE);
						get_connections(hDlg,st);
					}
					if (st->streamnum>=0)
					{	sprintf(actsession,"%d:EEG",st->streamnum);
						SetDlgItemText(hDlg, IDC_SELECTCOMBO, actsession);
					}
				}
				else
				{	
					add_to_listbox(hDlg,IDC_LIST, "No Socket connected.");
					EnableWindow(GetDlgItem(hDlg, IDC_CONNECT), TRUE);
					EnableWindow(GetDlgItem(hDlg, IDC_WATCH), FALSE);
					EnableWindow(GetDlgItem(hDlg, IDC_STOP), FALSE);
					EnableWindow(GetDlgItem(hDlg, IDC_CLOSE), FALSE);
				}

				return TRUE;
	
		case WM_CLOSE: 
				EndDialog(hDlg, LOWORD(wParam));
				return TRUE;
			
		case WM_COMMAND:
			switch (LOWORD(wParam)) 
			{ 
			case IDC_CONNECT:
				GetDlgItemText(hDlg, IDC_HOST, st->host, sizeof(st->host));
				if ((strlen(st->host)<8)||(!st->connect())) 
				{ 
					add_to_listbox(hDlg,IDC_LIST, "Could not connect to Server"); 
					break;
				}

				SendDlgItemMessage(hDlg,IDC_LIST, LB_ADDSTRING, 0, (LPARAM) "Socket connection successful.");
				strcpy(writebuf,"display\n");
				result = SDLNet_TCP_Send(st->sock, writebuf, strlen(writebuf));
				add_to_listbox(hDlg,IDC_LIST, "sending:DISPLAY");
	 			st->read_tcp(readbuf, readbuflength);
				strncpy(szdata,readbuf,6);szdata[6]=0;
				if (strcmp(szdata,"200 OK")) { add_to_listbox(hDlg,IDC_LIST,"Could not select Display-mode"); break;}
				add_to_listbox(hDlg,IDC_LIST, "OK");

				if (!st->sock) { add_to_listbox(hDlg,IDC_LIST,"Socket not connected"); break;}


				if (!get_connections(hDlg,st))
				 { 
					add_to_listbox(hDlg,IDC_LIST, "No Sessions available.");
					st->reset();
					InvalidateRect(ghWndMain,NULL,TRUE);
				    break;
				 }
				EnableWindow(GetDlgItem(hDlg, IDC_CONNECT), FALSE);
				EnableWindow(GetDlgItem(hDlg, IDC_STOP), FALSE);
				EnableWindow(GetDlgItem(hDlg, IDC_CLOSE), TRUE);

				break; 

			case IDC_SELECTCOMBO:
				 if (HIWORD(wParam)!=CBN_SELCHANGE) break;
  				 if (!st->sock) 
				 { 
					add_to_listbox(hDlg,IDC_LIST, "No Channels available."); 
				    st->streamnum=-1;
				    st->out[0].from_port=-1;
					st->outports=0;
				    break;
				 }
				 
				 st->streamnum=SendDlgItemMessage(hDlg,IDC_SELECTCOMBO,CB_GETITEMDATA, 
								(WPARAM) SendDlgItemMessage(hDlg,IDC_SELECTCOMBO, CB_GETCURSEL , 0, 0), 0);
				 st->clear_buffer();
				 // SELECT SESSION
				 sprintf(writebuf,"getheader %d\n",st->streamnum);
	
				 result = SDLNet_TCP_Send(st->sock, writebuf, strlen(writebuf));
				 add_to_listbox(hDlg,IDC_LIST, "sending:GETHEADER");

				 st->read_tcp(readbuf, sizeof(readbuf)-1);
				 strncpy(szdata,readbuf,6); szdata[6]=0;
				 if (strcmp(szdata,"200 OK")) {   add_to_listbox(hDlg,IDC_LIST,"Could not get EDF-header.");break;}

				 add_to_listbox(hDlg,IDC_LIST, "OK");
				 strcpy(st->edfheader,readbuf+8);
//				 report(st->edfheader);

				 EnableWindow(GetDlgItem(hDlg, IDC_SELECTCOMBO), FALSE);
				 st->syncloss=0;
				 add_to_listbox(hDlg,IDC_LIST, "Parsing Header");
				 parse_edf_header(&st->header,st->channel, st->edfheader);


 				 add_to_listbox(hDlg,IDC_LIST, "clear OK");
				 st->outports=st->header.channels;
				 st->height=CON_START+st->outports*CON_HEIGHT+5;
				 st->get_captions();
				update_header(hDlg,&st->header);
				update_channelcombo(hDlg, st->channel, st->header.channels);
				update_channel(hDlg,st->channel,actchn);
 				 add_to_listbox(hDlg,IDC_LIST, "OK");
				 EnableWindow(GetDlgItem(hDlg, IDC_WATCH), TRUE);
				 InvalidateRect(ghWndDesign,NULL,TRUE);
				 break; 

			case IDC_WATCH:
				if ((st->outports>0)&&(st->sock))
				{
					add_to_listbox(hDlg,IDC_LIST, "sending:WATCH");
					st->clear_buffer();
					st->syncloss=0;
					result=st->start_watching();
					if (result!=200) { add_to_listbox(hDlg,IDC_LIST,"Could not enter Watch-Mode"); break;}
					add_to_listbox(hDlg,IDC_LIST, "OK");
					EnableWindow(GetDlgItem(hDlg, IDC_WATCH), FALSE);
					EnableWindow(GetDlgItem(hDlg, IDC_CLOSE), FALSE);
  //				    EnableWindow(GetDlgItem(hDlg, IDC_SELECTCOMBO), FALSE);
					EnableWindow(GetDlgItem(hDlg, IDC_STOP), TRUE);
					if (!GLOBAL.running) start_timer();
					 
				} else add_to_listbox(hDlg,IDC_LIST, "No Channels available.");
				break; 
			case IDC_EMPTY:
					st->bufstart=st->bufend;
					add_to_listbox(hDlg,IDC_LIST, "buffer cleared.");
					break; 
			case IDC_STOP:
					add_to_listbox(hDlg,IDC_LIST, "sending:UNWATCH");
					st->unwatch();
					EnableWindow(GetDlgItem(hDlg, IDC_WATCH), TRUE);
					EnableWindow(GetDlgItem(hDlg, IDC_CLOSE), TRUE);
					EnableWindow(GetDlgItem(hDlg, IDC_STOP), FALSE);
//  				    EnableWindow(GetDlgItem(hDlg, IDC_SELECTCOMBO), TRUE);
					break; 

			case IDC_CLOSE: 
					add_to_listbox(hDlg,IDC_LIST, "sending:CLOSE");
					st->reset();
					EnableWindow(GetDlgItem(hDlg, IDC_CONNECT), TRUE);
//  				    EnableWindow(GetDlgItem(hDlg, IDC_SELECTCOMBO), FALSE);
					EnableWindow(GetDlgItem(hDlg, IDC_WATCH), FALSE);
					EnableWindow(GetDlgItem(hDlg, IDC_CLOSE), FALSE);
 				    InvalidateRect(ghWndDesign,NULL,TRUE);
					break;
			case IDC_CHANNELCOMBO:
					if (HIWORD(wParam)==CBN_SELCHANGE)
					{
						get_channel(hDlg, st->channel, actchn);
						actchn=SendMessage(GetDlgItem(hDlg, IDC_CHANNELCOMBO), CB_GETCURSEL , 0, 0);
						update_channel(hDlg, st->channel,actchn);
					}
				 break;

			}
			return TRUE;
		case WM_SIZE:
		case WM_MOVE:  update_toolbox_position(hDlg);
		break;
		return TRUE;
	}
    return FALSE;
} 
Esempio n. 16
0
static void vpnd_created(DBusConnection *conn, void *user_data)
{
	DBG("connection %p", conn);

	get_connections(user_data);
}