Embedded Segger embOS: getaddrinfo translation in gethostbyname - embedded

I am working on a project with an embedded TCP/IP-socket implementation.
My problem is my overlaying SDK needs needs the function:
getaddrinfo(
PCSTR pNodeName,
PCSTR pServiceName,
const ADDRINFOA *pHints,
PADDRINFOA *ppResult
);
but my underlying embedded "OS" is just providing the function:
struct* hostent gethostbyname(const char * sName);
Has someone an easy solution how to fake getaddrinfo() for the SDK, without the necessary to write it my self?
https://www.segger.com/downloads/emnet/UM07001 (page 273)
https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo

Related

How to create a proxy class that inherits SourceProxy, bundles ConeSource, and exposes ConeSource properties using VTK.js?

Note: This question is a bit arcane, if you don't have experience with The Visualization Toolkit (VTK.js) you may want to skip it (on the other hand, if you are a master of OOP and proxies...).
I'm attempting to build a "Hello World" implementation of VTK.js' proxies. This involves:
Creating a proxyManager that manages the proxies.
Creating a custom proxy that inherits from the SourceProxy.
This proxy should bundle ConeSource (non-proxy) and expose ConeSource's properties.
Creating a representation of the resulting geometric proxy.
Passing this representation to a view that displays inside a container on a page.
I used some code from VTK.js' documentation to create a basic geometric cone (not proxied):
import '#kitware/vtk.js/Rendering/Profiles/Geometry';
import vtkFullScreenRenderWindow from '#kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow';
import vtkActor from '#kitware/vtk.js/Rendering/Core/Actor';
import vtkMapper from '#kitware/vtk.js/Rendering/Core/Mapper';
import vtkConeSource from '#kitware/vtk.js/Filters/Sources/ConeSource';
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance();
const renderer = fullScreenRenderer.getRenderer();
const renderWindow = fullScreenRenderer.getRenderWindow();
// Create our cone
const coneSource = vtkConeSource.newInstance({ height: 1.0 });
const mapper = vtkMapper.newInstance();
mapper.setInputConnection(coneSource.getOutputPort());
const actor = vtkActor.newInstance();
actor.setMapper(mapper);
renderer.addActor(actor);
renderer.resetCamera();
renderWindow.render();
This works fine, it's moving to proxies that I'm struggling with.
I've been looking at a few successful implementations of VTK.js proxies:
Example included with VTK.js source code.
Medical Image Visualization in MIQA.
Another Medical Image Visualization application called VolView
Of these the example included in the VTK.js source code should be the simplest but it is an animation proxy so the principles don't quite translate (at least I haven't been able to get similar code working for a geometry proxy).
The example I've worked with the most is that found in MIQA. Most of the code is found inside a src/vtk folder but some important calls are made in the Vuex store (src/store/index.ts, especially shrinkProxyManager, prepareProxyManager, and swapToFrame), utils ([src/utils][9] folder (crosshairs.js and fill2DView.js), and the Vue components VtkViewer (src/components/VtkViewer.vue) and DecisionButtons (src/components/DecisionButtons.vue).
I've tried a bunch of different approaches (e.g. using the animation example, the miqa source, the volview source) including those outlined in this VTK.js Proxies thread.
In the VTK.js proxies there is a minimal implementation that looks like this:
source = proxyManager.createProxy('Sources', 'TrivialProducer', { name: 'myImage' });
source.setInputData(myImageData);
view = proxyManager.createProxy('Views', 'View3D', { name: 'my3DView' });
view.setContainer(someHTMLElement);
rep = proxyManager.getRepresentation(source, view);
view.addRepresentation(rep);
But I'm unsure how to make the source proxy something like GeometryProducer? Any help is appreciated.

aurelia-cli error when using buffer.js - global undefined

Created a new project using the aurelia-cli - SystemJS bundler option.
installed htmlparser2 module from npm which has buffer.js as a dependency.
getting the following error when attempting to import htmlparser2:
bluebird.core.js:3434 Error: global is not defined
Evaluating http://localhost:9000/buffer/index
upon inspecting vendor-bundle -> this is the line that creates the error:
Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
? global.TYPED_ARRAY_SUPPORT
: typedArraySupport()
found a similar issue with angualar-cli where the solution was to manually turn on node global
Node global is turned off. It works fine if I manually turn it on again.
The question is how to do this using the aurelia-cli? Any suggestions?
larger code snippet from vendor-bundle
define('buffer/index',['require','exports','module','base64-js','ieee754','isarray'],function (require, exports, module) {/*!
* The buffer module from node.js, for the browser.
*
* #author Feross Aboukhadijeh <feross#feross.org> <http://feross.org>
* #license MIT
*/
/* eslint-disable no-proto */
'use strict'
var base64 = require('base64-js')
var ieee754 = require('ieee754')
var isArray = require('isarray')
exports.Buffer = Buffer
exports.SlowBuffer = SlowBuffer
exports.INSPECT_MAX_BYTES = 50
/**
* If `Buffer.TYPED_ARRAY_SUPPORT`:
* === true Use Uint8Array implementation (fastest)
* === false Use Object implementation (most compatible, even IE6)
*
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
* Opera 11.6+, iOS 4.2+.
*
* Due to various browser bugs, sometimes the Object implementation will be used even
* when the browser supports typed arrays.
*
* Note:
*
* - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
*
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
*
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
* incorrect length in some situations.
* We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
* get the Object implementation, which is slower but behaves correctly.
*/
Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
? global.TYPED_ARRAY_SUPPORT
: typedArraySupport()
I believe you are using cli built-in bundler (I wrote it), not webpack.
Yes, nodejs global var global is currently not supported. Also nodejs global vars process and Buffer have similar issues.
The cli doc has a patch to support process and Buffer.
import process from 'process';
window.process = process;
import {Buffer} from 'buffer';
window.Buffer = Buffer;
You can try to add one more patch for global.
window.global = window;
Ok why cli has the issue
cli's tracing algorithm uses rjs (requirejs optimizer) parser, it's bit old, does not detect global vars (technically it does not do variable scope analysis).
I have another WIP bundler called dumber which solved the limitation with a new parser which detects global vars. It automatically patch nodejs global vars at module level based on need.
In long term, we will drop the code for cli built-in bundler, then wrap dumber and make it backward compatible.

Azure IoT hub C sdk blob upload example possible without low level API?

I'm trying the iothub_client/samples/iothub_client_sample_upload_to_blob from the Azure IoT hub C sdk. It compiles and works fine if I use the low-level API.
But as soon as I switch to the convenience layer (as the documentation in the app's file suggests), I get an error:
/home/user/workspaceMisc/azure-iot-sdk-c/iothub_client/samples/iothub_client_sample_upload_to_blob/iothub_client_sample_upload_to_blob.c: In function ‘iothub_client_sample_upload_to_blob_run’:
/home/user/workspaceMisc/azure-iot-sdk-c/iothub_client/samples/iothub_client_sample_upload_to_blob/iothub_client_sample_upload_to_blob.c:77:25: error: implicit declaration of function ‘IoTHubClient_UploadToBlob’ [-Werror=implicit-function-declaration]
if (IoTHubClient_UploadToBlob(iotHubClientHandle, "subdir/hello_world.txt", (const unsigned char*)HELLO_WORLD, sizeof(HELLO_WORLD) - 1) != IOTHUB_CLIENT_OK)
^
cc1: all warnings being treated as errors
iothub_client/samples/iothub_client_sample_upload_to_blob/CMakeFiles/iothub_client_sample_upload_to_blob.dir/build.make:62: recipe for target 'iothub_client/samples/iothub_client_sample_upload_to_blob/CMakeFiles/iothub_client_sample_upload_to_blob.dir/iothub_client_sample_upload_to_blob.c.o' failed
How can I upload a file with the convenience layer instead of the low level layer? Is it possible at all?
I'm using Ubuntu 16.04, gcc 5.4.0 and the latest clone of the SDK.
Actually the function name is IoTHubClient_UploadToBlobAsync, you need add Async postfix. And there is needed additional two parameters: iotHubClientFileUploadCallback and context. This document is somewhat misleading.
So you can call this function like this:
IoTHubClient_UploadToBlobAsync(iotHubClientHandle, "subdir/hello_world.txt", (const unsigned char*)HELLO_WORLD, sizeof(HELLO_WORLD) - 1, NULL, NULL);

How to get author of a pdf document with mupdf

how can I get metadata of a pdf document(e.g. title, author, creation date etc) by using mupdf library? There is not enough documentation to find out this functionality. Comments are not sufficient, too. Most probably, there is a functionality for this purpose but it is hard to find under these circumstances. The following code is what I have so far.
char info[64];
globals *glo = get_globals(env, thiz);
fz_meta(glo->doc, FZ_META_INFO, info, sizeof(info));
I have used FZ_META_INFO tag, but it doesn't work. I didn't get any info, just empty. I have checked that it has metadata. Any help is appreciated.
EDIT:
Target Android sdk:20
Min Android sdk:15
Mupdf version: 1.6
ndk: r10c
Development OS: Ubuntu 12.04
In what sense 'doesn't work' ? Throws an error ? Crashes ? Are you certain the PDF file you are using has any 'Info' metadata ?
What is the version of MuPDF ? What platform are you using ?
You need to set the relevant key in the buffer you pass to fz_meta before you call fz_mets, I notice you aren't doing that.
See win_main.c at around line 487, after you get past the macro this resolves to
char info[256]
sprintf(info, "Title");
fz_meta(doc, FZ_META_INFO, info, 256);
On return 'info' will contain the metadata associated with the Title key in the dictionary.
When in doubt, build the sample app and follow it in a debugger......
If the proper casting allow to send the key,
this casting is NOT correct to receive back a char*.
Exemple;
Proper casting to send a request
char buff[2048];
strcpy(buff,"CreationDate")
if (fz_meta(ctx,doc,FZ_META_INFO,&buff,2048)) {
buff[0] = 0;
}
Will:
find the key,
convert utf8
then will crash when copyback of the result
Proper casting to receive a request
char buff[2048];
strcpy(buff,"CreationDate")
if (fz_meta(ctx,doc,FZ_META_INFO,buff,2048)) {
buff[0] = 0;
}
Will crash during dict scanning.
looks really like a bug!
I confirm that modifying original source
info = pdf_dict_gets(ctx, info, (char *)ptr);
is the way to go. (even if strange that nobody else find it while writing code, because Meta are useful features frequently used

Play 2.1 for Http Server

I am new to play framework. My requirement is very simple. I want to create rest api server in scala using play framework. I could use play2-mini, but it seems it is outdated.
I want play 2.1 to be used in my project. Instead of setting play framework as dependency, I want only core module. So I have few questions -
What is core module of Play ? what is module name ?
Is it sufficient to use core module for creating asynchronous http server ?
This link says I can use core module instead of play-mini. If it's true, where can I get more info about it.
You can just simply setup a route and then point it to a controller that parses the data you send. Here is an example of json parsing and serving back a response with play.
http://www.playframework.com/documentation/2.1.1/ScalaJsonRequests
package controllers
import play.api._
import play.api.mvc._
import play.api.libs.json._
// you need this import to have combinators
import play.api.libs.functional.syntax._
object Application extends Controller {
implicit val rds = (
(__ \ 'name).read[String] and
(__ \ 'age).read[Long]
) tupled
def sayHello = Action { request =>
request.body.asJson.map { json =>
json.validate[(String, Long)].map{
case (name, age) => Ok("Hello " + name + ", you're "+age)
}.recoverTotal{
e => BadRequest("Detected error:"+ JsError.toFlatJson(e))
}
}.getOrElse {
BadRequest("Expecting Json data")
}
}
}
or even simpler...
def sayHello = Action(parse.json) { request =>
request.body.validate[(String, Long)].map{
case (name, age) => Ok("Hello " + name + ", you're "+age)
}.recoverTotal{
e => BadRequest("Detected error:"+ JsError.toFlatJson(e))
}
}
Play Framework is a highly modular project. Internally it consists of around 20 subprojects. Some of them you can include in your project as a library dependency if you need them, for example anorm or jdbc. Other projects (i.e. PlayExceptions, RoutesCompiler, TemplatesCompiler etc.) are essential for any Play application, so you don't need to declare dependency on them. These projects could be called a 'core' of Play Framework.
In other words, if you need a Play application with minimum dependencies, just don't declare dependencies you don't need.
Play sources: https://github.com/playframework/Play20
I don't think there is much problem here. For example, this is my build.sbt used for a very small project, that uses json, in which I wanted to use Play libraries, but not necessarily create a full Play app:
name := "my-small-project"
version := "0.0.1-SNAPSHOT"
resolvers ++= Seq(
"TypeSafe Repo" at "http://repo.typesafe.com/typesafe/releases",
"Sonatype Repo" at "http://oss.sonatype.org/content/repositories/releases"
)
libraryDependencies ++= Seq(
"org.specs2" %% "specs2" % "2.3.7" % "test",
"commons-codec" % "commons-codec" % "1.8",
"com.typesafe.play" % "play_2.10" % "2.2.1",
"com.typesafe.play" % "play-json_2.10" % "2.2.1"
)
And You could still remove some dependencies here, especially if You don't need Base64 encoding. Here I consider play_2.10 as "the core" you're interested in. You should get yourself familiar with sbt though, but it's not that hard.
Also remember, that the difference between "a Play application" and "an application that uses Play libraries" is quite fuzzy, especially if you use sbt. And this is the beauty of it, this shows how Play creators thoughtfully tried not to invent a wheel once again by creating custom system requirements for their project to build. You can enter a Play app dir and type "sbt compile" for example instead of firing a Play console and it should work just fine.