Exemplo n.º 1
0
        internal static void Throw(BluezError ret0, string descr)
        {
            int ret     = Marshal.GetLastWin32Error(); // Does work on Mono/Linux.
            int?sockErr = null;

            switch (ret)
            {
            // TODO ! Match BlueZ/Linux error codes to SocketExceptions.
            // Note need different errors for GetServiceRecords, handle here or in GSR itself?
            case 112:
                sockErr = (int)SocketError.HostDown;
                break;
            }
            if (sockErr == null)
            {
                sockErr = SocketError_NotSocket;
            }
            string stackTrace = "<disabled>";
            //-stackTrace = new StackTrace().ToString();
            var msg = "BluezUtils.Throw: '" + descr + "', ret: " + ret0 + " at: " + stackTrace;

            Debug.WriteLine(msg);
            Console.WriteLine(msg);
            throw new SocketException(sockErr.Value);
        }
Exemplo n.º 2
0
 internal static void CheckAndThrow(BluezError ret, string descr)
 {
     if (ret >= 0)
     {
         return;
     }
     Throw(ret, descr);
 }
Exemplo n.º 3
0
        List <ServiceRecord> DoSdpQuery(NativeMethods.SdpSessionSafeHandle session,
                                        Structs.uuid_t svcUuid, bool rfcommOnly)
        {
            var    listAllocs = new List <IntPtr>();
            IntPtr searchList = BluezUtils.sdp_list_append(IntPtr.Zero, svcUuid, listAllocs);

            // Attribute pattern
            IntPtr attridList;

            StackConsts.sdp_attrreq_type_t reqType;
            Console.WriteLine("rfcommOnly: " + rfcommOnly);
            if (rfcommOnly)
            {
                const UInt16 ClassListId  = (ushort)UniversalAttributeId.ServiceClassIdList;     //=1
                const UInt16 ProtoDListId = (ushort)UniversalAttributeId.ProtocolDescriptorList; //=4
                reqType    = StackConsts.sdp_attrreq_type_t.SDP_ATTR_REQ_INDIVIDUAL;
                attridList = BluezUtils.sdp_list_append(IntPtr.Zero, ClassListId, listAllocs);
                attridList = BluezUtils.sdp_list_append(attridList, ProtoDListId, listAllocs);
            }
            else
            {
                const UInt32 allAttributes = 0x0000ffff;
                reqType    = StackConsts.sdp_attrreq_type_t.SDP_ATTR_REQ_RANGE;
                attridList = BluezUtils.sdp_list_append(IntPtr.Zero, allAttributes, listAllocs);
            }

            // Query
            Console.WriteLine("sdp_service_search_attr_req in:"
                              + " {0}, attrid_list: {1}",
                              searchList, attridList);
            IntPtr     pResponseList;
            BluezError ret = NativeMethods.sdp_service_search_attr_req(session,
                                                                       searchList,
                                                                       reqType, attridList,
                                                                       out pResponseList);

            Console.WriteLine("sdp_service_search_attr_req ret: {0}, result: {1}",
                              ret, pResponseList);
            BluezUtils.CheckAndThrow(ret, "sdp_service_search_attr_req");
            //
            var rList = BuildRecordList(pResponseList);

            return(rList);
        }
Exemplo n.º 4
0
 internal static void Assert(BluezError ret, string descr)
 {
     Debug.Assert(ret >= 0, "Bluez error: "
                  + ret + "=(" + ((int)ret).ToString()
                  + "), at: " + descr);
 }
Exemplo n.º 5
0
 internal static bool IsSuccess(BluezError ret)
 {
     return(ret >= 0);
 }