Call to unavailable function 'system': not available on iOS? - ios

I am revisiting source code from a few years back and it used to compile perfectly but now there is one error in the project I can't figure out.
I have the following code:
void AssetsManager::destroyStoragePath()
{
// Delete recorded version codes.
deleteVersion();
// Remove downloaded files
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
FileUtils::getInstance()->removeDirectory(_storagePath.c_str());
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
string command = "rd /s /q ";
// Path may include space.
command += "\"" + _storagePath + "\"";
system(command.c_str());
#else
string command = "rm -r ";
// Path may include space.
command += "\"" + _storagePath + "\"";
system(command.c_str());
#endif
}
NS_CC_EXT_END;`
I get the following error:
"Call to unavailable function 'system': not available on iOS"
How do I fix this error?

There are several way besides system. You may use NSTask (Process in swift)

Related

VLC: saving a stream to a file

This code works with VLC 2.2.8 but it does not with VLC 3.0.9.2
if (it->second.handle && it->second.fDump) {
// Video/audio + file dump -> duplicate stream
transcode = "#duplicate{ dst=file{ dst=" + string(it->second.fDump) + " }, dst=display }";
}
else if (it->second.handle == NULL) {
// No video + file dump -> single stream
transcode = "#standard{ access=file, dst='" + string(it->second.fDump) + "' }";
}
I am focusing on the second branch and I wish to receive suggestions, thanks.
UPDATE:
It does not work means that it does not throw any error nor warning but it does not create the file. It seems, it ignores the option.
UPDATE 2:
I suspect that the saving option is ignored because I see this line in the application log which is related to the GPU but I have no way to see the video output:
avcodec: Using OpenGL/VAAPI backend for VDPAU for hardware decoding
It is not required decoding the stream but simply saving.
UPDATE 3:
I do not use the graphic interface but the command line and this works:
vlc rtsp://172.18.2.60:554/Streaming/Channels/1 --rtsp-user=$user --rtsp-pwd=$passwd \
--sout="#file{dst=test.mp4}" --vout=dummy -Idummy --ignore-config --quiet \
--rtsp-frame-buffer-size=500000 --network-caching=4000
However, trying to send the same trough VLC library API, it does not save the file. Then the issue should be in this piece of code which works with VLC 2.2.8:
it->second.p_lib = libvlc_new((int)argsCount, p_args);
if (!it->second.p_lib) {
HVLog("Cannot initialize VLC engine");
return -1;
}
// Set up logging
libvlc_log_set(it->second.p_lib, s_vlc_logcb, nullptr);
libvlc_media_t *p_url = libvlc_media_new_location(it->second.p_lib, url.c_str());
it->second.p_player = libvlc_media_player_new_from_media(p_url);
libvlc_media_release(p_url);
if (it->second.handle)
libvlc_media_player_set_hwnd(it->second.p_player, it->second.handle);
if (libvlc_media_player_play(it->second.p_player) < 0) {
HVLog("HVPlayOpen(%p, %d): cannot play stream %s", p_cam, channel, url.c_str());
return -1;
}
return 0;
For testing, I used this code instead and it works, obviously.
char vlcstr[1024];
snprintf(vlcstr, 1024, "vlc %s --rtsp-user=%s --rtsp-pwd=%s --sout=#file{dst=%s} --vout=dummy -Idummy "
"--ignore-config --quiet --rtsp-frame-buffer-size=500000 --network-caching=4000 &",
ss.str().c_str(), p_camera->getUser().c_str(), p_camera->getPassword().c_str(), it->second.fDump);
HVLog("HVPlayOpen(%p, %d): %s", p_cam, channel, vlcstr);
system(vlcstr);
return 0;
However, I wish to use the library API not the system().
UPDATE 4:
This is the log https://pastebin.com/9zgMQiNL
SOLVED
The issue is addressed using the libvlc_media_add_option() function as show here:
https://forum.videolan.org/viewtopic.php?t=69933

Unable to view screenshots in Jenkins reports

My jenkins reports do not show the screenshots captured in the runs. (They are run on a MAC). However, when I run the same job locally (windows machine), the reports have the screenshots.
I see the error as below in the Jenkins report.
When I try to open the image, It shows below. It's unable to find the path to the image actually.
Error : http://*****-mac:8080/job/***Test/job/******/ws/target/screenshots/2019-01-14/Sign%20In20190114154253.png
Actual: http://*****-mac:8080/job/***Test/job/******/HTML_20Report/target/screenshots/2019-01-14/Sign%20In20190114154253.png
I'm using the below code to capture the screenshot. It does capture the screenshots & I can see them in the actual location.
I don't know when I did a mistake, these images are not seen as links/not available in the report:
public void captureScreenshot() throws IOException {
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String dateForScreenshots = dateFormat.format(date);
File localScreenshots = new File(new File("target/screenshots"), dateForScreenshots);
if (!localScreenshots.exists() || !localScreenshots.isDirectory()) {
localScreenshots.mkdirs();
}
System.setProperty("org.uncommons.reportng.escape-output", "false");// this is to create a link in ReportNG
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String destination = System.getProperty("user.dir") + "/target/screenshots/" + dateForScreenshots + "/" + getDriver().getTitle() + Utils.generateRandomString() + ".png";
File screenshotName = new File(destination);
//Now add screenshot to results by copying the file
FileUtils.copyFile(scrFile, screenshotName);
Reporter.log("<br> <img src='" + destination + "' height='90' width='160' /><br>");
Reporter.log("");
}
From this line
Error : http://*****-mac:8080/job/***Test/job/******/ws/target/screenshots/2019-01-14/Sign%20In20190114154253.png
I think that Jenkins cannot find the target branch in the workspace folder (ws). Probably you need to specify the workspace folder in the Jenkins job (as in this answer) or just change the destination variable somehow to something like (added /HTML_20Report):
String destination = System.getProperty("user.dir") + "/HTML_20Report/target/screenshots/" + dateForScreenshots + "/" + getDriver().getTitle() + Utils.generateRandomString() + ".png";

Java 8 issues printing PS to network printer

Got a weird question for you. Recently upleveled my old project from java 7(jdk1.7.0_10) to java 8(1.8.0.91.x86_64). In java 7 it printed the post script file with no issues and now it is printing the postscript file as plain text instead of converting the file. This is on a redhat linux environment. Simply I am trying to print a string containing a post script file of a file itself.
Here is my original code
DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
PrintService pService = PrintServiceLookup.lookupDefaultPrintService();
// In a field environment, send to the printer
if (System.getenv("USER_DEFINED_RELTOP") == null || pfr.exists()) {
if (pService.getName().isEmpty()) {
LOGGER.error("No printer selected");
} else {
LOGGER.info("Printing to " + pService.getName());
DocPrintJob pj = pService.createPrintJob();
try {
InputStream is = new ByteArrayInputStream(data.getBytes("UTF8"));
Doc doc = new SimpleDoc(is, flavor, null);
PrintJobWatcher pjw = new PrintJobWatcher(pj);
pj.print(doc, null);
pjw.waitForDone();
is.close();
} catch (PrintException | IOException e) {
LOGGER.error(e);
} // try block
} // no printer selected
// Otherwise, send to a file
} else {
That worked fine in java 7, I updated it to the oracle spec found here for java 8.
https://docs.oracle.com/javase/8/docs/api/javax/print/PrintService.html#createPrintJob--
https://docs.oracle.com/javase/8/docs/technotes/guides/jps/spec/printing.fm6.html
DocFlavor psFlavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
attrs.add(MediaSizeName.ISO_A4);
PrintService[] pservices = PrintServiceLookup.lookupPrintServices(psFlavor,
attrs);
File pfr = new File(PFR_INDICATOR);
// In a field environment, send to the printer
if (System.getenv("USER_DEFINED_RELTOP") == null || pfr.exists()) {
//Check we have a printer capable of post script
if (pservices.length > 0) {
LOGGER.info("Printing to " + pservices[0].getName());
DocPrintJob pj = pservices[0].createPrintJob();
try {
InputStream fis = new ByteArrayInputStream(data.getBytes("UTF8"));
//byte[] ba =data.getBytes("UTF8");
Doc doc = new SimpleDoc(fis, psFlavor, null);
LOGGER.info("Doc Flavor " + doc.getDocFlavor());
PrintJobWatcher pjw = new PrintJobWatcher(pj);
LOGGER.info("PrintJob Attributes : " + pj.getAttributes());
pj.print(doc, attrs);
pjw.waitForDone();
fis.close();
} catch (IOException e) {
LOGGER.error(e);
NotificationDialog.show(NotificationDialog.NOTICE_TYPE.ERROR, PRINT_ERROR);
} catch (PrintException e) {
LOGGER.error(e);
}
} else { // no printer selected
This gives me an error java.awt.print.PrinterIOException: java.io.IOException: /usr/bin/lpr: where it looks to not find lpr.
If I keep it the way it was originally (not write to file) it prints the postscript as plain text even if adding the check to check if the printer is post script capable. If I use the new way of printing file I get a lpr not found error. If I print the PS document using the command lpr it converts it as expected and prints fine. If I use lpr -l that doesn't format it prints it document as plain text as well.
Any suggestion/help would be great. I am lost on what to do. I really don't want to convert it to an image and print that.
At a guess I'd say that your printer is an HP or at least PCL + PS printer, not a pure PostScript-only printer.
In that case you generally need to prepend the PostScript with a language selection PJL string. If you don't do this then it usually defaults to PCL and if you don't send any PCL commands (which all begin with 0x1B) then everything is treated as plain ASCII text. That would explain why both your application and lpr -l end up writing text, but lpr itself doesn't (presumably it adds the PJL).
You could try prepending the PostScript file with something like:
%-12345X#PJL JOB
#PJL ENTER LANGUAGE=POSTSCRIPT
NB the first byte there, before the % should be a 0x1b ESC character, but I can't readily paste binary....
Try sending the file with lpr -l if that works then you could try your old printing method.

php scandir produces extra elements (2 dots)

Hi,
I have the following files in a directory called content: index.php, page1.php, page2.php and page3.php ONLY.
Then I have this code:
$column = scandir("content");
foreach ($column as $value) {
$stvalue = str_replace(".php", "", $value);
echo "<div>$stvalue</div>";
}
Nevertheless, this is what I get:
<div>.</div>
<div>..</div>
<div>index</div>
<div>page1</div>
<div>page2</div>
<div>page3</div>
Whats with the first 2 elements? I dont have files named like that so I dont get it.
Thank you.
. - is a special directory referencing the current directory.
.. - is also a special directory and its referencing the parent directory.
To remove the special directories I can think of some options:
1.
foreach(glob("*.php") as $filename) {
echo "<div>$filename</div>";
}
2.
$files = array_diff(scandir("content"), array('..', '.'));
foreach($files as $file) { ... }
3.
foreach ($files as $file) {
if($file != '.' and $file != '..') { ... }
}
All of the above are alternatives. You don't need to use scandir() if you use glob() and vice versa. glob() - expects a pattern. It is possible to also provide it with the path like this:
glob("[path]/*.php") - this will list any php file located in path. glob() documentation can be found here PHP - glob()
$column = scandir("content");
foreach ($column as $value) {
$stvalue = str_replace(".php", "", $value);
if($stvalue != '.' || $stvalue != '..') {
echo "<div>$stvalue</div>";
}
}
. refers to the current directory. .. refers to the parent directory.
This is why typing cd .. on a command prompt will change to the parent directory. It's been this way in DOS, every version of Windows, Mac OS X, it's not just Linux and UNIX variants.
If you don't want to display them on your page, just skip the first two entries using array_slice.

Replacement for `__system_property_get` in Android L NDK

As of the Android L NDK, __system_property_get is removed (https://groups.google.com/a/chromium.org/forum/#!topic/chromium-reviews/keQP6L9aVyU). Is there another API in the Android L NDK to access the same property values?
I went with popen as detailed in the answer at https://stackoverflow.com/a/478960/2833126 to run getprop. Something like
std::string command = "getprop ro.product.model";
FILE* file = popen(command.c_str(), "r");
if (!file) {
// error
}
// read the property value from file
pclose(file);
what about
androidVersion = system("getprop ro.build.version.release");
printf("%s", androidVersion.c_str());

Resources