当前位置: 首页>>代码示例>>C++>>正文


C++ Http::AddRequest方法代码示例

本文整理汇总了C++中Http::AddRequest方法的典型用法代码示例。如果您正苦于以下问题:C++ Http::AddRequest方法的具体用法?C++ Http::AddRequest怎么用?C++ Http::AddRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Http的用法示例。


在下文中一共展示了Http::AddRequest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: onAttributeSet_callback

void onAttributeSet_callback(const uint8_t requestId, const uint16_t attributeId, const uint16_t valueLen, const uint8_t *value)
{
  HttpRequest *request = NULL;
  char hue_request[1024];
  fprintf(stdout,"onAttributeSet_callback: %d len: %d %x %s\n",attributeId,valueLen,*value,value);
  switch (attributeId)
  {
fprintf(stderr,"BUTTON PRESSED!\n");
break;
        case AF_LIGHT1:
          fprintf(stdout,"AF_LIGHT1 == %d\n",*value);
          sprintf(hue_request,"%slights/1/state",hue_prefix);
          if (*value)
  request = new HttpRequest(hue_request,"{ \"on\": true, \"hue\": 25500, \"sat\": 100, \"bri\": 100 }");
          else
  request = new HttpRequest(hue_request,"{ \"on\": false, \"hue\": 25500, \"sat\": 100, \"bri\": 100 }");

 http.AddRequest(request);

        break;
        case AF_LIGHT2:
          fprintf(stdout,"AF_LIGHT2 == %d\n",*value);
          sprintf(hue_request,"%slights/2/state",hue_prefix);
          if (*value)
  request = new HttpRequest(hue_request,"{ \"on\": true, \"hue\": 25500, \"sat\": 100, \"bri\": 100 }");
          else
  request = new HttpRequest(hue_request,"{ \"on\": false, \"hue\": 25500, \"sat\": 100, \"bri\": 100 }");

 http.AddRequest(request);

        break;
        case AF_LIGHT3:
          fprintf(stdout,"AF_LIGHT3 == %d\n",*value);
          sprintf(hue_request,"%slights/3/state",hue_prefix);
fprintf(stderr,"LIGHT 3 CHANGE STATE: %s\n",hue_request);
          if (*value)
  request = new HttpRequest(hue_request,"{ \"on\": true, \"hue\": 25500, \"sat\": 100, \"bri\": 100 }");
          else
  request = new HttpRequest(hue_request,"{ \"on\": false, \"hue\": 25500, \"sat\": 100, \"bri\": 100 }");

 http.AddRequest(request);

        break;
#if 0
        case AF_LIGHT1BRI:
        {
          uint16_t *light3Value= (uint16_t *) value;
          uint8_t *light3Value2= (uint8_t *) value;
          sprintf(hue_request,"%slights/1/state",hue_prefix);
          fprintf(stdout,"AF_LIGHT3 == %d %d %d\n",*value,*light3Value,*light3Value2);
          char command[512];
          
            sprintf(command, "{ \"on\": true, \"hue\": 25500, \"sat\": 100, \"bri\": %d }",*light3Value2);
fprintf(stderr,"!!!! [%s]\n",command);
  		request = new HttpRequest(hue_request,(const char *)command);
               http.AddRequest(request);

        }
        case AF_LIGHT2BRI:
        {
          uint16_t *light3Value= (uint16_t *) value;
          uint8_t *light3Value2= (uint8_t *) value;
          sprintf(hue_request,"%slights/2/state",hue_prefix);
          fprintf(stdout,"AF_LIGHT3 == %d %d %d\n",*value,*light3Value,*light3Value2);
          char command[512];
          
            sprintf(command, "{ \"on\": true, \"hue\": 25500, \"sat\": 100, \"bri\": %d }",*light3Value2);
fprintf(stderr,"!!!! [%s]\n",command);
  		request = new HttpRequest(hue_request,(const char *)command);
               http.AddRequest(request);

        }
#endif
        case AF_LIGHT3BRI:
        {
          uint16_t *light3Value= (uint16_t *) value;
          uint8_t *light3Value2= (uint8_t *) value;
          sprintf(hue_request,"%slights/3/state",hue_prefix);
          fprintf(stdout,"AF_LIGHT3 == %d %d %d\n",*value,*light3Value,*light3Value2);
          char command[512];
          
            sprintf(command, "{ \"on\": true, \"hue\": 25500, \"sat\": 100, \"bri\": %d }",*light3Value2);
fprintf(stderr,"!!!! [%s]\n",command);
  		request = new HttpRequest(hue_request,(const char *)command);
               http.AddRequest(request);

        }
        break;
    case AF_LIGHT1LABEL:
          {
          char *light1Label= (char *) value;
          fprintf(stdout,"bAF_LIGHT1LABEL == %s %d\n",light1Label);
          }

    case AF_LIGHT2LABEL:
          {
          char *light2Label= (char *) value;
          fprintf(stdout,"bAF_LIGHT2LABEL == %s %d\n",light2Label);
          }

//.........这里部分代码省略.........
开发者ID:alanswx,项目名称:afLib,代码行数:101,代码来源:hueSample.cpp

示例2: main

int main(int argc, char *argv[])
{

  HueLightResponse *hueLightResponder= NULL;
  HueIPResponse *IPAddr= new HueIPResponse("https://www.meethue.com/api/nupnp");
  http.AddRequest(IPAddr);

  int state = HUE_STATE_NEED_IP;

        struct pollfd fdset[2];
        int nfds = 2;
        int gpio_fd, timeout, rc;
        char *buf[MAX_BUF];
        unsigned int interrupt_line= 17;/*17;*/
        unsigned int reset_line= 4;
        int len;
        int counter=0;

    Stream *theLog = new linuxLog();
        afSPI *theSPI = new linuxSPI();

        gpio_export(interrupt_line);
        gpio_set_dir(interrupt_line, 0);
        gpio_set_edge(interrupt_line, "falling");
        gpio_fd = gpio_fd_open(interrupt_line);

        timeout = POLL_TIMEOUT;

        fprintf(stdout,"Test\n");

        theLib = iafLib::create(0,isr_callback,onAttributeSet_callback,onAttributeSetComplete_callback,theLog,theSPI);
        theLib->mcuISR();

/* we need to hook up and use the reset line */
        gpio_export(reset_line);
        gpio_set_dir(reset_line, 1);
    gpio_set_value(reset_line,0);
    
        timespec sleep_time;
        timespec remaining;
        sleep_time.tv_sec=0;
        sleep_time.tv_nsec=250000;
        nanosleep(&sleep_time,&remaining);
         /* check for E_INTR? and call again? */
    gpio_set_value(reset_line,1);

        while (1) {
                counter++;
                memset((void*)fdset, 0, sizeof(fdset));

                fdset[0].fd = STDIN_FILENO;
                fdset[0].events = POLLIN;

                fdset[1].fd = gpio_fd;
                fdset[1].events = POLLPRI;

                lseek(gpio_fd, 0, SEEK_SET);    /* consume any prior interrupt */
                read(gpio_fd, buf, sizeof (buf));


                rc = poll(fdset, nfds, timeout);

                if (rc < 0) {
                        printf("\npoll() failed!\n");
                        return -1;
                }

                if (rc == 0) {
                        printf(".");
                }

                if (fdset[1].revents & POLLPRI) {
                        len = read(fdset[1].fd, buf, MAX_BUF);
                        printf("\npoll() GPIO %d interrupt occurred\n", interrupt_line);
                lseek(gpio_fd, 0, SEEK_SET);    /* consume interrupt */
                read(gpio_fd, buf, sizeof (buf));

                        theLib->mcuISR();
                }

                if (fdset[0].revents & POLLIN) {
                        (void)read(fdset[0].fd, buf, 1);
                        //printf("\npoll() stdin read 0x%2.2X\n", (unsigned int) buf[0]);
                }



        switch (state)
        {
           case HUE_STATE_NEED_IP:
            // we need to check and see if we have an IP, then we can switch
  			if (IPAddr->completed())
{
                          state = HUE_STATE_HAS_IP;
                          IPAddr->get_ip(hue_ip);
                        fprintf(stderr,"IP: %s\n",hue_ip);
            sprintf(hue_prefix,"http://%s/api/huelibrary/",hue_ip);
                        state = HUE_STATE_HAS_IP;
}
            break;
//.........这里部分代码省略.........
开发者ID:alanswx,项目名称:afLib,代码行数:101,代码来源:hueSample.cpp


注:本文中的Http::AddRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。