I am trying to detect the number that is calling me during a Linphone call. I have tried
case LinphoneCallConnected:
NSLog("callStateChanged: LinphoneCallConnected")
NSLog("CALL ID: \(linphone_call_log_get_call_id(linphone_call_get_call_log(linphone_core_get_current_call(lc)))!)")
but that is null. Is there another way?
in my app I take linphoneCore and linphoneCall and after call linphone_call_get_remote_address. Now you have linphoneAddress from which you can extract username linphone_address_get_username.
Full code here:
- (NSString *)userNameFromCurrentCall {
LinphoneCore *lc = [LinphoneManager getLc];
LinphoneCall *currentcall = linphone_core_get_current_call(lc);
if (currentcall != NULL) {
LinphoneAddress const * addr = linphone_call_get_remote_address(currentcall);
if (addr != NULL) {
return [NSString stringWithUTF8String:linphone_address_get_username(addr)];
}
}
return nil;
}
SString *)userNameFromCurrentCall {
LinphoneCore *lc = [LinphoneManager getLc];
LinphoneCall *currentcall = linphone_core_get_current_call(lc);
if (currentcall != NULL) {
LinphoneAddress const * addr = linphone_call_get_remote_address(currentcall);
if (addr != NULL) {
return [NSString stringWithUTF8String:linphone_address_get_username(addr)];
}
}
return nil;
Related
I am currently working on an app which uses a live stream from an IP camera(PnP IP/Network camera manufactured by V Star). When connected using the Api provided I get the frame o/p as PBFrames. I am having trouble displaying them. anybody who have been through it please help. Thanks in advance
void *thread_ReceiveVideo(void *arg)
{
NSLog(#"[thread_ReceiveVideo] Starting...");
int avIndex = *(int *)arg;
char *buf = malloc(VIDEO_BUF_SIZE);
unsigned int frmNo;
int ret;
FRAMEINFO_t frameInfo;
while (1)
{
ret = avRecvFrameData(avIndex, buf, VIDEO_BUF_SIZE, (char *)&frameInfo, sizeof(FRAMEINFO_t), &frmNo);
if(ret == AV_ER_DATA_NOREADY)
{
usleep(30000);
continue;
}
else if(ret == AV_ER_LOSED_THIS_FRAME)
{
NSLog(#"Lost video frame NO[%d]", frmNo);
continue;
}
else if(ret == AV_ER_INCOMPLETE_FRAME)
{
NSLog(#"Incomplete video frame NO[%d]", frmNo);
NSLog(#" the biffer is : %lu",sizeof(buf));
continue;
}
else if(ret == AV_ER_SESSION_CLOSE_BY_REMOTE)
{
NSLog(#"[thread_ReceiveVideo] AV_ER_SESSION_CLOSE_BY_REMOTE");
break;
}
else if(ret == AV_ER_REMOTE_TIMEOUT_DISCONNECT)
{
NSLog(#"[thread_ReceiveVideo] AV_ER_REMOTE_TIMEOUT_DISCONNECT");
break;
}
else if(ret == IOTC_ER_INVALID_SID)
{
NSLog(#"[thread_ReceiveVideo] Session cant be used anymore");
break;
}
NSLog(#"FRAM INFO FLAG :%hhu ",frameInfo.flags);
if(frameInfo.flags == IPC_FRAME_FLAG_PBFRAME)
{
// got an PBFrame, draw it.
NSLog(#"got a video iframe to display");
// NSString *iFramestring = [NSString stringWithUTF8String:buf];
printf("correclty recieved frame is %s",buf);
//
}
}
free(buf);
NSLog(#"[thread_ReceiveVideo] thread exit");
return 0;
}
I am using the condition,but it don't go to the if condition, every time goes to the else condition.
if ([[dict2 valueForKey:#"meeting_location"] isEqual:#""])
{
lbllocation.text = #"-----";
}
else
{
lbllocation.text = [NSString stringWithFormat:#"Location: %#",[dict2 valueForKey:#"meeting_location"]];
}
Output came from Webservice:-
"meeting_location" = "";
"meeting_time" = "";
"meeting_with" = "";
Use Below Code -
if ([[dict2 valueForKey:#"meeting_location"] length] == 0)
{
lbllocation.text = #"-----";
}
else
{
lbllocation.text = [NSString stringWithFormat:#"Location: %#",[dict2 valueForKey:#"meeting_location"]];
}
Hopefully this will work here.
This is for an app intended for the app store.
Using the code from here, I can get a list of running processes and their pids. However, I've found several apps in the appstore (like this one that have also retrieved each process's priority and start time.
(Note: I don't care whether it's uptime, for how long the process has been active, or the wall clock date/time the process started).
Is there any documented way to do this?
Here is the code to get all the process related info you want such as Name, Priority,StartDate, ParentID,Status. Here is the link to get full resource with demo.
// List of process information including PID's, Names, PPID's, and Status'
+ (NSMutableArray *)processesInformation {
// Get the list of processes and all information about them
#try {
// Make a new integer array holding all the kernel processes
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
// Make a new size of 4
size_t miblen = 4;
size_t size = 0;
int st = sysctl(mib, miblen, NULL, &size, NULL, 0);
// Set up the processes and new process struct
struct kinfo_proc *process = NULL;
struct kinfo_proc *newprocess = NULL;
// do, while loop rnning through all the processes
do {
size += size / 10;
newprocess = realloc(process, size);
if (!newprocess) {
if (process) free(process);
// Error
return nil;
}
process = newprocess;
st = sysctl(mib, miblen, process, &size, NULL, 0);
} while (st == -1 && errno == ENOMEM);
if (st == 0) {
if (size % sizeof(struct kinfo_proc) == 0) {
int nprocess = size / sizeof(struct kinfo_proc);
if (nprocess) {
NSMutableArray *array = [[NSMutableArray alloc] init];
for (int i = nprocess - 1; i >= 0; i--) {
NSString *processID = [[NSString alloc] initWithFormat:#"%d", process[i].kp_proc.p_pid];
NSString *processName = [[NSString alloc] initWithFormat:#"%s", process[i].kp_proc.p_comm];
NSString *processPriority = [[NSString alloc] initWithFormat:#"%d", process[i].kp_proc.p_priority];
NSDate *processStartDate = [NSDate dateWithTimeIntervalSince1970:process[i].kp_proc.p_un.__p_starttime.tv_sec];
NSString *processParentID = [[NSString alloc] initWithFormat:#"%d", [self parentPIDForProcess:(int)process[i].kp_proc.p_pid]];
NSString *processStatus = [[NSString alloc] initWithFormat:#"%d", (int)process[i].kp_proc.p_stat];
NSString *processFlags = [[NSString alloc] initWithFormat:#"%d", (int)process[i].kp_proc.p_flag];
// Check to make sure all values are valid (if not, make them)
if (processID == nil || processID.length <= 0) {
// Invalid value
processID = #"Unkown";
}
if (processName == nil || processName.length <= 0) {
// Invalid value
processName = #"Unkown";
}
if (processPriority == nil || processPriority.length <= 0) {
// Invalid value
processPriority = #"Unkown";
}
if (processStartDate == nil) {
// Invalid value
processStartDate = [NSDate date];
}
if (processParentID == nil || processParentID.length <= 0) {
// Invalid value
processParentID = #"Unkown";
}
if (processStatus == nil || processStatus.length <= 0) {
// Invalid value
processStatus = #"Unkown";
}
if (processFlags == nil || processFlags.length <= 0) {
// Invalid value
processFlags = #"Unkown";
}
// Create an array of the objects
NSArray *ItemArray = [NSArray arrayWithObjects:processID, processName, processPriority, processStartDate, processParentID, processStatus, processFlags, nil];
// Create an array of keys
NSArray *KeyArray = [NSArray arrayWithObjects:#"PID", #"Name", #"Priority", #"StartDate", #"ParentID", #"Status", #"Flags", nil];
// Create the dictionary
NSDictionary *dict = [[NSDictionary alloc] initWithObjects:ItemArray forKeys:KeyArray];
// Add the objects to the array
[array addObject:dict];
}
// Make sure the array is usable
if (array.count <= 0) {
// Error, nothing in array
return nil;
}
// Free the process
free(process);
// Successful
return array;
}
}
}
// Something failed
return nil;
}
#catch (NSException * ex) {
// Error
return nil;
}
}
// Parent ID for a certain PID
+ (int)parentPIDForProcess:(int)pid {
// Get the parent ID for a certain process
#try {
// Set up the variables
struct kinfo_proc info;
size_t length = sizeof(struct kinfo_proc);
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid };
if (sysctl(mib, 4, &info, &length, NULL, 0) < 0)
// Unknown value
return -1;
if (length == 0)
// Unknown value
return -1;
// Make an int for the PPID
int PPID = info.kp_eproc.e_ppid;
// Check to make sure it's valid
if (PPID <= 0) {
// No PPID found
return -1;
}
// Successful
return PPID;
}
#catch (NSException *exception) {
// Error
return -1;
}
}
I try to get ip address using asyncsocket framework. When do it via ethernet cable the following method works good.
But when try to get ip address using wifi access point it returns nil.
Here is a method:
- (NSData *)wifiAddress
{
// On iPhone, WiFi is always "en0"
NSData *result = nil;
struct ifaddrs *addrs;
const struct ifaddrs *cursor;
if ((getifaddrs(&addrs) == 0))
{
cursor = addrs;
while (cursor != NULL)
{
NSLog(#"cursor->ifa_name = %s", cursor->ifa_name);
if (strcmp(cursor->ifa_name, "en0") == 0)
{
if (cursor->ifa_addr->sa_family == AF_INET)
{
struct sockaddr_in *addr = (struct sockaddr_in *)cursor->ifa_addr;
NSLog(#"cursor->ifa_addr = %s", inet_ntoa(addr->sin_addr));
result = [NSData dataWithBytes:addr length:sizeof(struct sockaddr_in)];
cursor = NULL;
}
else
{
cursor = cursor->ifa_next;
}
}
else
{
cursor = cursor->ifa_next;
}
}
freeifaddrs(addrs);
}
return result;
}
The issue we had was that an exact match on en0 would not always return the wifi address. We have something similar to the following. Hope this helps.
NSString* wifiIp = [NetUtils getLocalAddress:#"en"];
+ (NSString *) getLocalAddress:(NSString*) interface
{
NSString *address = nil;
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = 0;
success = getifaddrs(&interfaces);
if (success == 0)
{
temp_addr = interfaces;
while(temp_addr != NULL)
{
if(temp_addr->ifa_addr->sa_family == AF_INET)
{
NSRange range = [[NSString stringWithUTF8String:temp_addr->ifa_name] rangeOfString : interface];
if(range.location != NSNotFound)
{
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
}
}
temp_addr = temp_addr->ifa_next;
}
}
freeifaddrs(interfaces);
return address;
}
I'm working on a project were I need the USB port to communicate with an external device. I have been looking for examples on the net (Apple and /developer/IOKit/usb exemple) and trying some others, but I can't even find the device.
In my code, I'm blocking at the place where the function looks for a next iterator (pointer in fact) with the function getNextIterator; but it never returns a good value, so the code is blocking. By the way, I am using toolchain and added IOKit.framework in my project. All I want right now is to communicate or do like a ping to someone on the USB bus! I'm blocking in FindDevice... I can't manage to enter in the while loop because the variable usbDevice is always = to 0... I have tested my code in a small mac program and it works...
Here is my code :
IOReturn ConfigureDevice(IOUSBDeviceInterface **dev) {
UInt8 numConfig;
IOReturn result;
IOUSBConfigurationDescriptorPtr configDesc;
//Get the number of configurations
result = (*dev)->GetNumberOfConfigurations(dev, &numConfig);
if (!numConfig) {
return -1;
}
// Get the configuration descriptor
result = (*dev)->GetConfigurationDescriptorPtr(dev, 0, &configDesc);
if (result) {
NSLog(#"Couldn't get configuration descriptior for index %d (err=%08x)\n", 0, result);
return -1;
}
#ifdef OSX_DEBUG
NSLog(#"Number of Configurations: %d\n", numConfig);
#endif
// Configure the device
result = (*dev)->SetConfiguration(dev, configDesc->bConfigurationValue);
if (result)
{
NSLog(#"Unable to set configuration to value %d (err=%08x)\n", 0, result);
return -1;
}
return kIOReturnSuccess;
}
IOReturn FindInterfaces(IOUSBDeviceInterface **dev, IOUSBInterfaceInterface ***itf) {
IOReturn kr;
IOUSBFindInterfaceRequest request;
io_iterator_t iterator;
io_service_t usbInterface;
IOUSBInterfaceInterface **intf = NULL;
IOCFPlugInInterface **plugInInterface = NULL;
HRESULT res;
SInt32 score;
UInt8 intfClass;
UInt8 intfSubClass;
UInt8 intfNumEndpoints;
int pipeRef;
CFRunLoopSourceRef runLoopSource;
NSLog(#"Debut FindInterfaces \n");
request.bInterfaceClass = kIOUSBFindInterfaceDontCare;
request.bInterfaceSubClass = kIOUSBFindInterfaceDontCare;
request.bInterfaceProtocol = kIOUSBFindInterfaceDontCare;
request.bAlternateSetting = kIOUSBFindInterfaceDontCare;
kr = (*dev)->CreateInterfaceIterator(dev, &request, &iterator);
usbInterface = IOIteratorNext(iterator);
IOObjectRelease(iterator);
NSLog(#"Interface found.\n");
kr = IOCreatePlugInInterfaceForService(usbInterface, kIOUSBInterfaceUserClientTypeID, kIOCFPlugInInterfaceID, &plugInInterface, &score);
kr = IOObjectRelease(usbInterface); // done with the usbInterface object now that I have the plugin
if ((kIOReturnSuccess != kr) || !plugInInterface)
{
NSLog(#"unable to create a plugin (%08x)\n", kr);
return -1;
}
// I have the interface plugin. I need the interface interface
res = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOUSBInterfaceInterfaceID), (LPVOID*) &intf);
(*plugInInterface)->Release(plugInInterface); // done with this
if (res || !intf)
{
NSLog(#"couldn't create an IOUSBInterfaceInterface (%08x)\n", (int) res);
return -1;
}
// Now open the interface. This will cause the pipes to be instantiated that are
// associated with the endpoints defined in the interface descriptor.
kr = (*intf)->USBInterfaceOpen(intf);
if (kIOReturnSuccess != kr)
{
NSLog(#"unable to open interface (%08x)\n", kr);
(void) (*intf)->Release(intf);
return -1;
}
kr = (*intf)->CreateInterfaceAsyncEventSource(intf, &runLoopSource);
if (kIOReturnSuccess != kr)
{
NSLog(#"unable to create async event source (%08x)\n", kr);
(void) (*intf)->USBInterfaceClose(intf);
(void) (*intf)->Release(intf);
return -1;
}
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode);
if (!intf)
{
NSLog(#"Interface is NULL!\n");
} else
{
*itf = intf;
}
NSLog(#"End of FindInterface \n \n");
return kr;
}
unsigned int FindDevice(void *refCon, io_iterator_t iterator) {
kern_return_t kr;
io_service_t usbDevice;
IOCFPlugInInterface **plugInInterface = NULL;
HRESULT result;
SInt32 score;
UInt16 vendor;
UInt16 product;
UInt16 release;
unsigned int count = 0;
NSLog(#"Searching Device....\n");
while (usbDevice = IOIteratorNext(iterator))
{
// create intermediate plug-in
NSLog(#"Found a device!\n");
kr = IOCreatePlugInInterfaceForService(usbDevice,
kIOUSBDeviceUserClientTypeID,
kIOCFPlugInInterfaceID,
&plugInInterface, &score);
kr = IOObjectRelease(usbDevice);
if ((kIOReturnSuccess != kr) || !plugInInterface) {
NSLog(#"Unable to create a plug-in (%08x)\n", kr);
continue;
}
// Now create the device interface
result = (*plugInInterface)->QueryInterface(plugInInterface,
CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID),
(LPVOID)&dev);
// Don't need intermediate Plug-In Interface
(*plugInInterface)->Release(plugInInterface);
if (result || !dev) {
NSLog(#"Couldn't create a device interface (%08x)\n",
(int)result);
continue;
}
// check these values for confirmation
kr = (*dev)->GetDeviceVendor(dev, &vendor);
kr = (*dev)->GetDeviceProduct(dev, &product);
//kr = (*dev)->GetDeviceReleaseNumber(dev, &release);
//if ((vendor != LegoUSBVendorID) || (product != LegoUSBProductID) || (release != LegoUSBRelease)) {
if ((vendor != LegoUSBVendorID) || (product != LegoUSBProductID))
{
NSLog(#"Found unwanted device (vendor = %d != %d, product = %d != %d, release = %d)\n",
vendor, kUSBVendorID, product, LegoUSBProductID, release);
(void) (*dev)->Release(dev);
continue;
}
// Open the device to change its state
kr = (*dev)->USBDeviceOpen(dev);
if (kr == kIOReturnSuccess) {
count++;
} else {
NSLog(#"Unable to open device: %08x\n", kr);
(void) (*dev)->Release(dev);
continue;
}
// Configure device
kr = ConfigureDevice(dev);
if (kr != kIOReturnSuccess) {
NSLog(#"Unable to configure device: %08x\n", kr);
(void) (*dev)->USBDeviceClose(dev);
(void) (*dev)->Release(dev);
continue;
}
break;
}
return count;
}
// USB rcx Init
IOUSBInterfaceInterface** osx_usb_rcx_init (void)
{
CFMutableDictionaryRef matchingDict;
kern_return_t result;
IOUSBInterfaceInterface **intf = NULL;
unsigned int device_count = 0;
// Create master handler
result = IOMasterPort(MACH_PORT_NULL, &gMasterPort);
if (result || !gMasterPort)
{
NSLog(#"ERR: Couldn't create master I/O Kit port(%08x)\n", result);
return NULL;
}
else {
NSLog(#"Created Master Port.\n");
NSLog(#"Master port 0x:08X \n \n", gMasterPort);
}
// Set up the matching dictionary for class IOUSBDevice and its subclasses
matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
if (!matchingDict) {
NSLog(#"Couldn't create a USB matching dictionary \n");
mach_port_deallocate(mach_task_self(), gMasterPort);
return NULL;
}
else {
NSLog(#"USB matching dictionary : %08X \n", matchingDict);
}
CFDictionarySetValue(matchingDict, CFSTR(kUSBVendorID),
CFNumberCreate(kCFAllocatorDefault, kCFNumberShortType, &LegoUSBVendorID));
CFDictionarySetValue(matchingDict, CFSTR(kUSBProductID),
CFNumberCreate(kCFAllocatorDefault, kCFNumberShortType, &LegoUSBProductID));
result = IOServiceGetMatchingServices(gMasterPort, matchingDict, &gRawAddedIter);
matchingDict = 0; // this was consumed by the above call
// Iterate over matching devices to access already present devices
NSLog(#"RawAddedIter : 0x:%08X \n", &gRawAddedIter);
device_count = FindDevice(NULL, gRawAddedIter);
if (device_count == 1)
{
result = FindInterfaces(dev, &intf);
if (kIOReturnSuccess != result)
{
NSLog(#"unable to find interfaces on device: %08x\n", result);
(*dev)->USBDeviceClose(dev);
(*dev)->Release(dev);
return NULL;
}
// osx_usb_rcx_wakeup(intf);
return intf;
}
else if (device_count > 1)
{
NSLog(#"too many matching devices (%d) !\n", device_count);
}
else
{
NSLog(#"no matching devices found\n");
}
return NULL;
}
int main(int argc, char *argv[])
{
int returnCode;
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog(#"Debut du programme \n \n");
osx_usb_rcx_init();
NSLog(#"Fin du programme \n \n");
return 0;
// returnCode = UIApplicationMain(argc, argv, #"Untitled1App", #"Untitled1App");
// [pool release];
// return returnCode;
}
IOKit is not available for iPhone applications. If you need to connect with external devices from the iPhone you need to sign up for the MFi Program which will provide you with the needed API's and documentation.
besides the appstore rules i dont think u can even touch iokit on iOS without violating the sdk's agreement.