// test code
static PyObject* meth_tick_count(obj_Session* self, PyObject* /*args*/)
{
  TUint tickCount;
  TInt errCode = self->iSession.TickCount(tickCount);
  if (errCode) {
    return SPyErr_SetFromSymbianOSErr(errCode);
  }
  return Py_BuildValue("i", static_cast<TInt>(tickCount));
}
// Wraps DiscoverDevices() to provide a Python method interface.
// Arguments:
//  - boolean value of whether to perform name lookup 
//
// Returns list of (address, name, (service,major,minor)) tuples detailing the
// found devices.
static PyObject* LightBlue_DiscoverDevices(PyObject* self, PyObject* args)
{
    bool lookupNames;
    
    if (!PyArg_ParseTuple(args, "b", &lookupNames))
        return NULL;

    // run the discovery
    TDeviceDataList devDataList;
    TInt err = DiscoverDevices(&devDataList, lookupNames);
    if (err) 
        return SPyErr_SetFromSymbianOSErr(err);
    
    // put the results into a python list
    TInt i;
    TDeviceData *devData;
    TBuf8<6*2+5> addrString;
    
    PyObject *addrList = PyList_New(0);    // python list to hold results
    for( i=0; i<devDataList.Count(); i++ )
    {        
        devData = devDataList[i];
        
        // convert address to string
        DevAddressToString(devData->iDeviceAddr, addrString);
        
        PyObject *devValues;
        
        if (lookupNames) {
            THostName name = devData->iDeviceName;
            
            devValues = Py_BuildValue("(s#u#(iii))", 
                addrString.Ptr(), addrString.Length(),      // s# - address
                name.Ptr(), name.Length(),                  // u# - name
                devData->iServiceClass,                     // i  - service class
                devData->iMajorClass,                       // i  - major class
                devData->iMinorClass                        // i  - minor class
                );        
        } else {
            devValues = Py_BuildValue("(s#O(iii))", 
                addrString.Ptr(), addrString.Length(),      // s# - address
                Py_None,
                devData->iServiceClass,                     // i  - service class
                devData->iMajorClass,                       // i  - major class
                devData->iMinorClass                        // i  - minor class
                ); 
        }
        
        // add tuple to list
        PyList_Append(addrList, devValues);
    }    
    
    devDataList.ResetAndDestroy();
        
    return addrList;
}
Beispiel #3
0
static PyObject *_fn__pybtswitch__get_power_state(PyObject *aPyMod, PyObject *)
{
  CBTMCMSettings* settings = NULL;

  // The NewL takes an optional callback argument.
  TRAPD(error, settings = CBTMCMSettings::NewL());
  if ((error != KErrNone)) {
    return SPyErr_SetFromSymbianOSErr(error);
  }

  TBool powerState;
  error = settings->GetPowerState(powerState);
  delete settings;

  if ((error != KErrNone)) {
    return SPyErr_SetFromSymbianOSErr(error);
  }
  
  return Py_BuildValue("i", powerState ? 1 : 0);
}
// Wraps GetLocalName() to provide a Python method interface.
// Takes no arguments.
//
// Returns the local device name as a unicode python string.
static PyObject* LightBlue_GetLocalName(PyObject* self, PyObject* args) 
{
    TBTDeviceName deviceName;
    
    if (!PyArg_ParseTuple(args, ""))
        return NULL;
    
    TInt err = GetLocalName(deviceName);
    if (err) 
        return SPyErr_SetFromSymbianOSErr(err);
        
    return Py_BuildValue("u#", deviceName.Ptr(), deviceName.Length());
}
// Wraps GetLocalDeviceClass() to provide a Python method interface.
// Takes no arguments.
//
// Returns the local device class (an integer).
static PyObject* LightBlue_GetLocalDeviceClass(PyObject* self, PyObject* args) 
{
    //TDeviceData aDeviceData;
    TBTDeviceClass aDeviceClass;
    
    if (!PyArg_ParseTuple(args, ""))
        return NULL;
    
    TInt err = GetLocalDeviceClass(aDeviceClass);
    if (err) 
        return SPyErr_SetFromSymbianOSErr(err);
        
    return Py_BuildValue("i", aDeviceClass.DeviceClass());
}
Beispiel #6
0
static PyObject *_fn__pybtswitch__set_power_state(PyObject *aPyMod, PyObject *aPyArgs)
{
  int intPowerState;
  if (!PyArg_ParseTuple(aPyArgs, "i", &intPowerState))
    {
      return NULL;
    }
  TBool powerState = (intPowerState != EFalse);

  CBTMCMSettings* settings = NULL;
  TRAPD(error, settings = CBTMCMSettings::NewL());
  if ((error != KErrNone)) {
    return SPyErr_SetFromSymbianOSErr(error);
  }

  error = settings->SetPowerState(powerState);
  delete settings;
  
  if ((error != KErrNone)) {
    return SPyErr_SetFromSymbianOSErr(error);
  }

  RETURN_NO_VALUE;
}
PyObject* new_Session(PyObject* /*self*/, PyObject* /*args*/)
{
  PyTypeObject* typeObject = reinterpret_cast<PyTypeObject*>(SPyGetGlobalString(__MODULE_NAME__ ".Session"));
  obj_Session* self = PyObject_New(obj_Session, typeObject);
  if (self == NULL)
      return NULL;

  TInt errCode = self->iSession.Connect();
  self->iSessionOpen = (errCode == KErrNone);
  if (errCode) {
    PyObject_Del(self);
    return SPyErr_SetFromSymbianOSErr(errCode);
  }

  return reinterpret_cast<PyObject*>(self);
}
// Wraps GetLocalAddress() to provide a Python method interface.
// Takes no arguments.
//
// Returns local device address as Python string.
static PyObject* LightBlue_GetLocalAddress(PyObject* self, PyObject* args) 
{
    TBTDevAddr addr;
    TBuf8<6*2+5> addrString;
    
    if (!PyArg_ParseTuple(args, ""))
        return NULL;    
    
    TInt err = GetLocalAddress(addr);
    if (err) 
        return SPyErr_SetFromSymbianOSErr(err);
        
    DevAddressToString(addr, addrString);
    
    return Py_BuildValue("s#", addrString.Ptr(), addrString.Length());
}
// test code
static PyObject* meth_des16_len(obj_Session* self, PyObject* args)
{
  char* b;
  int l;
  if (!PyArg_ParseTuple(args, "u#", &b, &l))
  {
    return NULL;
  }
  TPtrC text((TUint16*)b, l);

  TInt desLen = 0;
  TInt errCode = self->iSession.TryEval(text, desLen);
  if (errCode) {
    return SPyErr_SetFromSymbianOSErr(errCode);
  }
  return Py_BuildValue("i", static_cast<TInt>(desLen));
}
Beispiel #10
0
static PyObject* getVideosPath(PyObject* /*self*/, PyObject* args)
	{
	Cpyfileselect* obj = Cpyfileselect::NewL();
	const char* res;
	TRAPD( err, res = obj->VideosPath());
	PyObject* result;

	if (err != KErrNone)
		{
		result = SPyErr_SetFromSymbianOSErr(err);
		}
	else
		{
		result = Py_BuildValue("s", res);
		}
	delete obj;
	return result;
	}
static PyObject* meth_eval_get_result(obj_Session* self, PyObject* args)
{
  char* b;
  int l;
  if (!PyArg_ParseTuple(args, "u#", &b, &l))
  {
    return NULL;
  }
  TPtrC text((TUint16*)b, l);

  TBuf<512> resultDes;
  TInt evalErrCode = 0;
  TInt errCode = self->iSession.EvalGetResult(text, evalErrCode, resultDes);
  if (errCode) {
    return SPyErr_SetFromSymbianOSErr(errCode);
  }
  return Py_BuildValue("(iu#)", evalErrCode, resultDes.Ptr(), resultDes.Length());
}
Beispiel #12
0
static PyObject* select_file(PyObject* /*self*/, PyObject* args)
	{
	TInt32 useDefaultTitle;
	char *ttext = NULL;
	TInt ttextlen = 0;

	char *ptext = NULL;
	TInt ptextlen = 0;

	TInt err = KErrNone;
	if (!PyArg_ParseTuple(args, "u#u#i", &ptext, &ptextlen, &ttext, &ttextlen,
			&useDefaultTitle))
		{
		return Py_BuildValue("s", "Cannot parse arguments.");
		}

	Cpyfileselect* obj = Cpyfileselect::NewL();
	const char* res;
	TPtrC path((TUint16*) ptext, ptextlen);
	if (useDefaultTitle == 1)
		{
		TRAPD( err, res = obj->FileSelectionDlg(path, KNullDesC) );
		}
	else
		{
		TPtrC title((TUint16*) ttext, ttextlen);
		TRAPD( err, res = obj->FileSelectionDlg(path, title));
		}

	PyObject* result;

	if (err != KErrNone)
		{
		result = SPyErr_SetFromSymbianOSErr(err);
		}
	else
		{
		result = Py_BuildValue("s", res);
		}
	delete obj;
	return result;
	}
// Wraps SelectDeviceUI() to provide a Python method interface. 
// Takes no arguments.
//
// Returns None if user cancelled, otherwise returns a
// (name, address, (service,major,minor)) Python tuple.
static PyObject* LightBlue_SelectDevice(PyObject* self, PyObject* args) 
{
    if (!PyArg_ParseTuple(args, ""))
        return NULL;    
    
    TBTDeviceResponseParamsPckg response;
    TInt err = SelectDeviceUI(response);
     
    if (err) {
        if (err == KErrCancel) {
            // user cancelled
            Py_INCREF(Py_None);
            return Py_None;  
        } else {
            // some other error occured
            return SPyErr_SetFromSymbianOSErr(err);
        }
    }
    if (!(response().IsValidDeviceName())) {
        PyErr_SetString(PyExc_SymbianError, "discovery returned invalid data");
        return NULL;
    }
    
    // get device address
    TBuf8<6*2+5> addrString;
    TBTDevAddr addr = response().BDAddr();
    DevAddressToString(addr, addrString);
    
    // get device class details
    TBTDeviceClass deviceClass = response().DeviceClass();
    TUint16 service = deviceClass.MajorServiceClass();
    TUint8 major = deviceClass.MajorDeviceClass();
    TUint8 minor = deviceClass.MinorDeviceClass();
    
    return Py_BuildValue("s#u#(iii)",
        addrString.Ptr(), addrString.Length(),
        response().DeviceName().Ptr(), response().DeviceName().Length(),
        service,
        major,
        minor);
}
// Wraps LookupName() to provide a Python method interface.
// Arguments:
//  - address of the device to look up. Note that the address 
//    is expected without colons!! e.g. "000D9319C868"
//  - True/False - if True, performs a remote name request even if the device
//    name is known in the cache from a previous request.
//
// Returns the name (a Python unicode string).
static PyObject* LightBlue_LookupName(PyObject* self, PyObject* args)
{   
    const char *addr;
    bool ignoreCache;
    if (!PyArg_ParseTuple(args, "sb", &addr, &ignoreCache))
        return NULL;

    THostName deviceName;
    TBTDevAddr wantedAddr;
    
    TBuf16<128> buf;
    buf.Copy(_L8(addr));
    wantedAddr.SetReadable(buf);
    
    TInt err = LookupName(wantedAddr, &deviceName, ignoreCache);
  
    if (err) 
        return SPyErr_SetFromSymbianOSErr(err);    
        
    return Py_BuildValue("u#", deviceName.Ptr(), deviceName.Length());
}
Beispiel #15
0
static PyObject* select_folder(PyObject* /*self*/, PyObject* args)
	{
	
	
	char *ttext = NULL;
	TInt ttextlen = 0;
	TInt32 useDefaultTitle;
	
	char *rtext = NULL;
	TInt rtextlen = 0;
	TInt32 useDefaultRight;
	
	char *ltext = NULL;
	TInt ltextlen = 0;
	TInt32 useDefaultLeft;
	
	char *mtext = NULL;
	TInt mtextlen = 0;
	
	TInt32 type;
	TCommonDialogType dialogType = ECFDDialogTypeSave;
	
	
	if (!PyArg_ParseTuple(args, "iu#u#iu#iu#i", &type, &mtext, &mtextlen, &ttext, &ttextlen,&useDefaultTitle, &rtext, &rtextlen,&useDefaultRight, &ltext, &ltextlen, &useDefaultLeft))
		{
		return Py_BuildValue("s", "Cannot parse arguments.");
		}
	switch (type)
		{
		case 0:
			{
			dialogType = ECFDDialogTypeSave;
			}
		break;
		case 1:
			{
			dialogType = ECFDDialogTypeMove;
			}
		break;
		case 2:
			{
			dialogType = ECFDDialogTypeCopy;
			}
		break;
		}
	Cpyfileselect* obj = Cpyfileselect::NewL();
	const char* res;
	TPtrC titleP((TUint16*) ttext, ttextlen);
	TPtrC memory((TUint16*) mtext, mtextlen);
	TPtrC leftP((TUint16*) ltext, ltextlen);
	TPtrC rightP((TUint16*) rtext, rtextlen);
	TBuf <20> title;
	title.Append(titleP);
	TBuf <20> right;
	right.Append(rightP);
	TBuf <20> left;
	left.Append(leftP);
	if(useDefaultTitle == 1)
		{
			title = KNullDesC;
		}
	if(useDefaultRight == 1)
		{
			right = KNullDesC;
		}
	if(useDefaultLeft == 1)
		{
			left = KNullDesC;
		}
	TRAPD( err, res = obj->FolderSelectionDlg(dialogType,memory, title, right, left) );

	PyObject* result;

	if (err != KErrNone)
		{
		result = SPyErr_SetFromSymbianOSErr(err);
		}
	else
		{
		result = Py_BuildValue("s", res);
		}
	delete obj;
	return result;
	}