예제 #1
0
Channel* join_chat(User* user){
  int descriptor=user->socket;
  char buffer[BUFFER_SIZE];
  char str[BUFFER_SIZE];
  int ret;
  snprintf(str,sizeof(str),"%s",print_channel());
  int i,while_flag=1;

  while(while_flag){
  ret= send_message(descriptor,str,NULL);
  ret= receive_message(descriptor,buffer);

  if(buffer[0]=='$'){
    memset(buffer,0,sizeof(buffer));
    snprintf(buffer,sizeof(buffer),"%s",QUIT_CLIENT);
    send_message(user->socket,buffer,strlen(buffer));
    return NULL;
  }

  ret= sem_wait(&channels_sem);
  ERROR_HELPER(ret,"error on sem_wait to channels_sem");

  for(i=0; i<num_channels; i++){
    if(strcmp(buffer,channels[i]->channel_name)==0){
      while_flag=0;
      break;
    }
  }
  if(while_flag==0){
    memset(buffer,0,sizeof(buffer));
    memset(str,0,sizeof(str));
    break;
  }
  memset(str,0,sizeof(str));
  snprintf(str,sizeof(str),"%s",ERR_CHAT);
  strcat(str, print_channel());
  ret= sem_post(&channels_sem);
  ERROR_HELPER(ret,"error on sem_post to channels_sem");
  }

  channels[i]->subscribers[channels[i]->sub_num]= (User*) malloc(sizeof(User));
  memcpy(channels[i]->subscribers[channels[i]->sub_num],user,sizeof(User));
  channels[i]->sub_num+=1;
  user->user_channel= channels[i];
  printf("Aggiunto user %s con descrittore %d alla chat %s\n", channels[i]->subscribers[channels[i]->sub_num-1]->username,channels[i]->subscribers[channels[i]->sub_num-1]->socket,user->user_channel->channel_name);

  return channels[i];
}
예제 #2
0
static void print_info(const struct iwinfo_ops *iw, const char *ifname)
{
	printf("%-9s ESSID: %s\n",
		ifname,
		print_ssid(iw, ifname));
	printf("          Access Point: %s\n",
		print_bssid(iw, ifname));
	printf("          Type: %s  HW Mode(s): %s\n",
		print_type(iw, ifname),
		print_hwmodes(iw, ifname));
	printf("          Mode: %s  Channel: %s (%s)\n",
		print_mode(iw, ifname),
		print_channel(iw, ifname),
		print_frequency(iw, ifname));
	printf("          Tx-Power: %s  Link Quality: %s/%s\n",
		print_txpower(iw, ifname),
		print_quality(iw, ifname),
		print_quality_max(iw, ifname));
	printf("          Signal: %s  Noise: %s\n",
		print_signal(iw, ifname),
		print_noise(iw, ifname));
	printf("          Bit Rate: %s\n",
		print_rate(iw, ifname));
	printf("          Encryption: %s\n",
		print_encryption(iw, ifname));
	printf("          Supports VAPs: %s\n",
		print_mbssid_supp(iw, ifname));
}
예제 #3
0
파일: pwm_py.c 프로젝트: sert00/RPIO
// python function print_channel(int channel)
static PyObject*
py_print_channel(PyObject *self, PyObject *args)
{
    int channel;

    if (!PyArg_ParseTuple(args, "i", &channel))
        return NULL;

    if (print_channel(channel) == EXIT_FAILURE)
        return raise_error();

    Py_INCREF(Py_None);
    return Py_None;
}
예제 #4
0
static int cc_pwm_duty(int argc, char **argv)
{
	int percent = 0;
	int ch;
	char *e;

	if (argc < 2) {
		ccprintf("PWM channels:\n");
		for (ch = 0; ch < PWM_CH_COUNT; ch++)
			print_channel(ch);
		return EC_SUCCESS;
	}

	ch = strtoi(argv[1], &e, 0);
	if (*e || ch < 0 || ch >= PWM_CH_COUNT)
		return EC_ERROR_PARAM1;

	if (argc > 2) {
		percent = strtoi(argv[2], &e, 0);
		if (*e || percent > 100) {
			/* Bad param */
			return EC_ERROR_PARAM1;
		} else if (percent < 0) {
			/* Negative = disable */
			pwm_enable(ch, 0);
		} else {
			ccprintf("Setting channel %d to %d%%\n", ch, percent);
			pwm_enable(ch, 1);
			pwm_set_duty(ch, percent);
		}
	}

	print_channel(ch);

	return EC_SUCCESS;
}
예제 #5
0
/*
 * Check options and call the proper handler
 */
static int
print_one_device(int		skfd,
		 int		format,
		 int		wtype,
		 const char*	ifname)
{
  int ret;

  /* Check wtype */
  switch(wtype)
    {
    case WTYPE_AP:
      /* Try to print an AP */
      ret = print_ap(skfd, ifname, format);
      break;

    case WTYPE_CHANNEL:
      /* Try to print channel */
      ret = print_channel(skfd, ifname, format);
      break;

    case WTYPE_FREQ:
      /* Try to print frequency */
      ret = print_freq(skfd, ifname, format);
      break;

    case WTYPE_MODE:
      /* Try to print the mode */
      ret = print_mode(skfd, ifname, format);
      break;

    case WTYPE_PROTO:
      /* Try to print the protocol */
      ret = print_protocol(skfd, ifname, format);
      break;

    default:
      /* Try to print an ESSID */
      ret = print_essid(skfd, ifname, format);
      if(ret < 0)
	{
	  /* Try to print a nwid */
	  ret = print_nwid(skfd, ifname, format);
	}
    }

  return(ret);
}
예제 #6
0
/*
 * List channel(s) of session and domain.
 *
 * If channel_name is NULL, all channels are listed.
 */
static int list_channels(const char *channel_name)
{
	int count, i, ret = CMD_SUCCESS;
	unsigned int chan_found = 0;
	struct lttng_channel *channels = NULL;

	DBG("Listing channel(s) (%s)", channel_name ? : "<all>");

	count = lttng_list_channels(handle, &channels);
	if (count < 0) {
		switch (-count) {
		case LTTNG_ERR_KERN_CHAN_NOT_FOUND:
			if (lttng_opt_mi) {
				/* When printing mi this is not an error
				 * but an empty channels element */
				count = 0;
			} else {
				ret = CMD_SUCCESS;
				WARN("No kernel channel");
				goto error_channels;
			}
			break;
		default:
			/* We had a real error */
			ret = CMD_ERROR;
			ERR("%s", lttng_strerror(count));
			goto error_channels;
			break;
		}
	}

	if (lttng_opt_mi) {
		/* Mi print */
		ret = mi_list_channels(channels, count, channel_name);
		if (ret) {
			ret = CMD_ERROR;
			goto error;
		}
	} else {
		/* Pretty print */
		if (count) {
			MSG("Channels:\n-------------");
		}

		for (i = 0; i < count; i++) {
			if (channel_name != NULL) {
				if (strncmp(channels[i].name, channel_name, NAME_MAX) == 0) {
					chan_found = 1;
				} else {
					continue;
				}
			}
			print_channel(&channels[i]);

			/* Listing events per channel */
			ret = list_events(channels[i].name);
			if (ret) {
				goto error;
			}

			if (chan_found) {
				break;
			}
		}

		if (!chan_found && channel_name != NULL) {
			ret = CMD_ERROR;
			ERR("Channel %s not found", channel_name);
			goto error;
		}
	}
error:
	free(channels);

error_channels:
	return ret;
}
예제 #7
0
파일: list-channel.c 프로젝트: ic-hep/emi3
int tool_doit(glite_transfer_ctx *ctx, int argc, char *argv[]) {
    int i;

    if (!argc) {
        // no channel names specified; print list of channel names and exit
        char **tmp;
        int cnt;

        tmp = glite_channel_listChannels(ctx, &cnt);
        if (cnt < 0) {
            error("list: %s", glite_transfer_get_error(ctx));
            return EXIT_FAILURE;
        }

        for (i = 0; i < cnt; i++)
            printf("%s\n", tmp[i]);
        glite_freeStringArray(cnt, tmp);
        return EXIT_SUCCESS;
    }
    
    // channel names were specified; print details for each channel
    
    // check for extended options
    if (extended_list && !(isExtendedChannelListSupported())) {
        error("The server you are contacting does not support the -x (extended list) option of channel-list (it is running interface version %s).", srv_iface_ver);
        return EXIT_FAILURE;
    }

    for (i = 0; i < argc; i++) {
        if (i)
            printf("\n");

        if (extended_list) {
            if (isItVersion350()){
                glite_transfer_Channel3 *channel3;
                channel3 = glite_channel_getChannel3(ctx, argv[i]);
                if (!channel3) {
                    error("list: %s", glite_transfer_get_error(ctx));
                    return EXIT_FAILURE;
                }
                print_channel3(channel3);
                glite_transfer_Channel3_free(ctx, channel3);
            } else {
                glite_transfer_Channel2 *channel2;
                channel2 = glite_channel_getChannel2(ctx, argv[i]);
                if (!channel2) {
                    error("list: %s", glite_transfer_get_error(ctx));
                    return EXIT_FAILURE;
                }
                print_channel2(channel2);
                glite_transfer_Channel2_free(ctx, channel2);
            }
        } else { // old listing

            glite_transfer_Channel *channel;
            channel = glite_channel_getChannel(ctx, argv[i]);
            if (!channel) {
                error("list: %s", glite_transfer_get_error(ctx));
                return EXIT_FAILURE;
            }
            print_channel(channel);
            glite_transfer_Channel_free(ctx, channel);
        }

    }

    return EXIT_SUCCESS;
}