webOS Nation Forums >  webOS Developers >  webOS Development > Native vs. JavaScript service
Native vs. JavaScript service
  Reply
Like Tree5Likes
  • 1 Post By eblade
  • 1 Post By GMMan
  • 1 Post By Garfonso
  • 2 Post By eblade

 
Thread Tools Display Modes
Old 12/10/2012, 08:44 PM   #1 (permalink)
Member
 
Posts: 3
I see that there are two types of service. Native(C,C++) and JavaScript(node.js). If I want to create a new service which is the best way to go? Are there any limitations or pros/cons using JS vs Native?
vinayr is offline   Reply With Quote
Old 12/10/2012, 11:22 PM   #2 (permalink)
Homebrew Developer

 
Posts: 3,209
If you're going for something to put in the catalog, you'll have to use JavaScript. Otherwise, knock yourself out. It's probably a lot easier to do in JavaScript than in native, considering there's zero native documentation since it's something that only Palm and a few other people have done. The only real con to doing something in JavaScript is that webOS phones run node 0.2, touchpad uses node 0.4, and who knows what Open webOS is going to end up using, although right now it's using the same as on the touchpad.

-- Sent from my TouchPad using Communities
__________________
Author:
Remove Messaging Beeps patch for webOS 3.0.5, Left/Right bezel gestures in LunaCE,
Whazaa! Messenger and node-wa, SynerGV 1 and 2 - Google Voice integration, XO - Subsonic Commander media streamer, AB:S Launcher
Quote:
(1:39:33 PM) halfhalo: Android multitasking is like sticking your fingers into a blender
GO OPEN WEBOS!
People asked me for a donate link for my non-catalog work, so here you are:
eblade is offline   Reply With Quote
Liked by vinayr likes this.
Thanked By: vinayr
Old 12/11/2012, 12:42 AM   #3 (permalink)
Member
 
GMMan's Avatar
 
Posts: 2,136
Native services are implemented when you need to interact with hardware or binary utilities. For example, the audio service is native because it needs access to PulseAudio. The Luna download manager is native because it needs curl (and a bit of security of App Catalog downloads). Facebook, Google, and Palm Profile are JavaScript services because they don't really deal with the hardware and only interact with online APIs.
__________________
Contact: @GMMan_BZFlag (me on Twitter)
webOS Releases: Change your App Catalog country: TouchPad/PC | TouchPad/webOS Resources | Search suggestion patch for browser | Cycling Email Notifications | Don't Doctor! Make a good support request. | How to post logs | webOS Charge Monitor
GMMan is offline   Reply With Quote
Liked by vinayr likes this.
Thanked by Remy X, vinayr
Old 12/11/2012, 02:48 AM   #4 (permalink)
Member
 
Posts: 3
I want to create a service which uses, for example, facebook API, and I want to run it for long time (may be as background service?). In this case would it be any better if I made it as native service instead of JS service?

My main concern is about node.js(or V8) memory performance. I guess each JS service runs on its own V8 instance. If each V8 instance occupies, let's say 10-15mb, then there could be issues if many such services are running.

I'm new to webOS. Please correct me if I'm wrong.
vinayr is offline   Reply With Quote
Old 12/11/2012, 03:10 AM   #5 (permalink)
Member
 
GMMan's Avatar
 
Posts: 2,136
I don't know services that well, but maybe there's something in Activity Manager that'll keep the service alive. I've also heard of a singleton pattern for it as well, but I don't know where there may be examples.

Note that every time a JavaScript is called the code with the service methods is reloaded.
__________________
Contact: @GMMan_BZFlag (me on Twitter)
webOS Releases: Change your App Catalog country: TouchPad/PC | TouchPad/webOS Resources | Search suggestion patch for browser | Cycling Email Notifications | Don't Doctor! Make a good support request. | How to post logs | webOS Charge Monitor
GMMan is offline   Reply With Quote
Old 12/11/2012, 09:29 AM   #6 (permalink)
Homebrew Developer
 
Posts: 717
A service should not run all the time... be sure that you REALLY need that. It will cost CPU, Memory and massively Battery!

The idea for services in webOs is to be started, when they are needed. They even are restricted to one minute runtime (which can be changed, but this is not recommended). Look at the activity manager... there are activities to react on database changes and stuff, or interval based wake ups (best is to keep to a smart interval)... or if you want to have a GUI app, your service will wake up whenever the GUI app calls a service function.

What do you need a connection for all the time? Maybe you want to write a synergy plugin for the messaging app? This involves heavy database lifting, as eblade reported during his work on synergv.
You can also look at other chat apps out there... I think most of them don't use a service at all, but the app stays open all the time (at least as a dashboard icon). That has the advantage that the user can get rid of it, if battery is needed. There is no way to stop a service (from a user perspective)...

And I'd say keep it as much JS as possible... I fiddled around with C++ and it was quite a ugly thing... it even was worse on the memory footprint than node.js.
Garfonso is offline   Reply With Quote
Liked by Remy X likes this.
Old 12/11/2012, 02:20 PM   #7 (permalink)
Homebrew Developer

 
Posts: 3,209
The thing that really amazes me, is that SynerGV 2 can make use of an open WebSocket (done in the app, because I couldn't seem to find anything in Node that was actually compatible with WebSocket) for push notifications, and on the TouchPad, that barely makes a difference in battery drain from what I've seen. Enabling that on a phone will kill the battery so fast you won't believe the phone isn't melting.

So, no, you don't want to have things running all the time if you don't have to
__________________
Author:
Remove Messaging Beeps patch for webOS 3.0.5, Left/Right bezel gestures in LunaCE,
Whazaa! Messenger and node-wa, SynerGV 1 and 2 - Google Voice integration, XO - Subsonic Commander media streamer, AB:S Launcher
Quote:
(1:39:33 PM) halfhalo: Android multitasking is like sticking your fingers into a blender
GO OPEN WEBOS!
People asked me for a donate link for my non-catalog work, so here you are:
eblade is offline   Reply With Quote
Liked by Grabber5.0 and Remy X like this.
Reply

 

Tags
native, node.js, services

Thread Tools
Display Modes



 


Content Relevant URLs by vBSEO 3.6.0