Example #1
0
        public YRETCODE HTTPRequestAsync(string request, HTTPRequestCallback callback, blockingCallbackCtx context, ref string errmsg)
        {
            YRETCODE res = default(YRETCODE);
              StringBuilder errbuf = new StringBuilder(YAPI.YOCTO_ERRMSG_LEN);
              StringBuilder b = null;
              int neededsize = 0;
              int p = 0;
              string newrequest = null;
              int written = 0;
              StringBuilder root = new StringBuilder(YAPI.YOCTO_SERIAL_LEN);
              int tmp = 0;

              if (((_flags & YAPI.HTTP_ASYNC_PENDING) != 0))
            HTTPRequestAsyncFinish(true);

              _flags = _flags | YAPI.HTTP_ASYNC_PENDING;
              _http_result = "";
              _context = context;
              _callback = callback;
              _cacheStamp = YAPI.GetTickCount();
              // invalidate cache

              if (!(_subpathinit))
              {
            res = YAPI._yapiGetDevicePath(_devdescr, root, null, 0, ref neededsize, errbuf);

            if (YAPI.YISERR(res))
            {
              _flags = _flags & ~YAPI.HTTP_ASYNC_PENDING;
              errmsg = errbuf.ToString();
              return res;
            }

            b = new StringBuilder(neededsize);
            res = YAPI._yapiGetDevicePath(_devdescr, root, b, neededsize, ref tmp, errbuf);
            if (YAPI.YISERR(res))
            {
              _flags = _flags & ~YAPI.HTTP_ASYNC_PENDING;
              errmsg = errbuf.ToString();
              return res;
            }

            _rootdevice = root.ToString();
            _subpath = b.ToString();

            _subpathinit = true;
              }

              p = request.IndexOf("/");
              newrequest = request.Substring(0, p) + _subpath + request.Substring(p + 1, request.Length - p - 1);

              res = YAPI._yapiRequestOpen(ref _iohdl, new StringBuilder(_rootdevice), errbuf);
              if (YAPI.YISERR(res))
              {
            _flags = _flags & ~YAPI.HTTP_ASYNC_PENDING;
            errmsg = errbuf.ToString();
            return res;
              }

              written = YAPI._yapiRequestWrite(ref _iohdl, new StringBuilder(newrequest), newrequest.Length, errbuf);
              if (YAPI.YISERR(written))
              {
            errmsg = errbuf.ToString();
            YAPI._yapiRequestClose(ref _iohdl, null);
            _flags = _flags & ~YAPI.HTTP_ASYNC_PENDING;
            return written;
              }

              return YAPI.SUCCESS;
        }
Example #2
0
 public static void YblockingCallback(YDevice device, ref blockingCallbackCtx context, YRETCODE returnval, string result, string errmsg)
 {
     context.res = returnval;
     context.response = result;
     context.errmsg = errmsg;
 }
Example #3
0
        public YRETCODE HTTPRequest(string request, ref string buffer, ref string errmsg)
        {
            YRETCODE res = default(YRETCODE);
              blockingCallbackCtx ctx = new blockingCallbackCtx();

              res = HTTPRequestAsync(request, YAPI.YblockingCallback, ctx, ref errmsg);

              if (YAPI.YISERR(res))
              {
            return res;
              }

              HTTPRequestAsyncFinish(true);
              buffer = ctx.response;
              errmsg = ctx.errmsg;
              return ctx.res;
        }