Detect windows time change c++ - c++-cli

I am using
CTime t = CTime::GetCurrentTime();
to get the current time from Winodws, but when the clock changes the next day and the application is still open, the time does not change. How can i make 't' be updated automatically when time changes?.
What i tried is to use TimeChanged event,
public:
event EventHandler^ TimeChanged {
static void add(EventHandler^ value);
static void remove(EventHandler^ value);
}
but how to apply this on CTime t?. Thanks in Advance

Related

How to check the load time for submodules

I am running the script where One module having 20 submodules. My task is mousehover the main module and click the desired submodule, it may take few miliseconds to get load, I do have to calculate load time for each submodules. After clicking any of the module it does not change the URL, its just get loaded/open into iframe.
I tried with following code. But its giving the negative value. Also please let me know is this aright way to do so.
public void waitForLoading() throws InterruptedException
{
long startTime = System.currentTimeMillis();
System.out.println(startTime);
int count=0;
while(loadingIcon.size()!=0 && count<10)
{
Thread.sleep(1000);
count++;
}
long finishTime = System.currentTimeMillis();
System.out.println(finishTime);
long diff = startTime-finishTime;
System.out.println(diff);
}
The output of above code is startTime = 1619460610429 finishTime = 1619460635444 & Diff = -25015.
Can it be done with the help of TestNNG Listners?
Any help will be appreciate.

How altbeacon is keeping a background service alive?

I am running into a issue that is the opposite problem of this thread:
AltBeacon not detect beacon when app is closed
I have an app that uses altbeacon (http://altbeacon.org/)
The app initializes the alt-beacon implementing the interfaces at the application level as below (details omitted)
public class MyApp extends Application implements
BootstrapNotifier,
BeaconConsumer {
//some code
#Override
public void onCreate() {
super.onCreate();
initBeacons();
}
public void initBeacons() {
mBackgroundPowerSaver = new BackgroundPowerSaver(this);
org.altbeacon.beacon.BeaconManager altBeaconManager = org.altbeacon.beacon.BeaconManager.getInstanceForApplication(this);
altBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
// estimote
altBeaconManager.setBackgroundScanPeriod(5000);
altBeaconManager.setBackgroundBetweenScanPeriod(25000);
mBeaconManager = MyBeaconManager.getInstance(this, altBeaconManager);
mRegionBootstrap = new RegionBootstrap(this, MyBeaconManager.getRegions());
altBeaconManager.bind(this);
}
#Override
public void onBeaconServiceConnect() {
Thread thread = new Thread() {
public void run() {
// Try range the beacons
rangeMyBeacons();
}
};
thread.start();
}
#Override
public void didEnterRegion(Region region) {
// Some code
}
#Override
public void didExitRegion(Region region) {
// Some code
}
#Override
public void didDetermineStateForRegion(int i, Region region) {
// Some code
}
public class MyBeaconManager implements
RangeNotifier {
// some code
However, If I kill the app or restart the phone, without any special broadcasts or app permissions the alt-beacon service comes back alive. Alt-beacon re-starts itself all the time, in other words. Notice that I don't have any foreground services running. Here' is a screenshot of the app after several hours (and I rebooted the phone), with all apps closed. You can see the alt-beacon is alive and scanning the beacons.
yet when I look at alt-beacon code, it is not a foreground service
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
LogManager.i(TAG,
intent == null ?
"starting with null intent"
:
"starting with intent " + intent.toString()
);
return super.onStartCommand(intent, flags, startId);
}
I did search inside the library and I see not hits to START_REDELIVER_INTENT or START_STICKY.
My question is how does alt-beacon keep the service alive when the app is killed?
The reason I want to understand this feature is that I am writing a similar service but I can only get it do work as alt-beacon if I wrap it into a foreground service. Everything else I tried, the service gets killed as soon as the app closes.
thank you.
The Android Beacon Library uses an AlarmManager to keep the scanning service running in the background. It periodically sets an alarm for 5 minutes in the future, which causes the operating system to deliver it a BroadcastIntent which will start the scanning service if stopped. When running, the library continually reschedules this alarm.
You can see the code that does that here:
https://github.com/AltBeacon/android-beacon-library/blob/master/src/main/java/org/altbeacon/beacon/service/scanner/CycledLeScanner.java#L339
// In case we go into deep sleep, we will set up a wakeup alarm when in the background to kickoff
// off the scan cycle again
protected void setWakeUpAlarm() {
// wake up time will be the maximum of 5 minutes, the scan period, the between scan period
long milliseconds = 1000l * 60 * 5; /* five minutes */
if (milliseconds < mBetweenScanPeriod) {
milliseconds = mBetweenScanPeriod;
}
if (milliseconds < mScanPeriod) {
milliseconds = mScanPeriod;
}
AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + milliseconds, getWakeUpOperation());
LogManager.d(TAG, "Set a wakeup alarm to go off in %s ms: %s", milliseconds, getWakeUpOperation());
}
This design ensures that if the app needs to be terminated due to low memory, scanning will be restarted five minutes in the future. This allows the phone time to complete the memory intensive operation, while still allowing beacon detections in a reasonable time frame.

nullPointerException error greenfoot

I'm working on a project for an intro to programming class, and I've run into a slight problem. We're making a side scroller, and I'm working on the score counter right now. My issue is that when I try to create a reference to the counter class in anything other than the act method(called once every frame) I get a null pointer exception error. You can download the zip file with my code in it here if you want to take a look.
EDIT:
Here's the offending code:
public class HeroMissile extends Missiles
{
/**
* Act - do whatever the HeroMissile wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(8);
remove();
}
public void remove() {
if(isTouching(Drone.class)) {
removeTouching(Drone.class);
getWorld().addObject(new Explosion(), getX(), getY());
getWorld().removeObject(this);
addScore();
return;
}
}
public void addScore() {
City cityWorld = (City) getWorld();
**Counter scoreCounter = cityWorld.getCounter();**
scoreCounter.add(1);
}
}
You are calling getWorld() [in addScore()] after you removed yourself from the world. In this case, getWorld() will return null, so you will get a null pointer exception. Try changing the order in remove() to add the score before you remove yourself from the world.

time between mouse clicks processing.js

I want to get the time between successive mouse clicks in ms. This is what I have tried:
void setup(){
size(512,512);
background(100,100,0);
}
void draw(){
}
void mousePressed(){
println(new Date() - oldtime);
var oldtime=new Date();
}
The problem appears to be that processing.js does not remember the value of oldtime between calls to mousePressed().
On the first call, there has been no previous mouse click, oldtime is undefined, and the time should be NaN. But after the first click, oldtime is set, and so the above should work. I tried doing
var oldtime=new Date();
outside mousePressed() so that the first call would not be NaN, but no luck.
Thanks very much for any help.
===========================
The problem had to do with variable "scope". This works now
var oldtime=new Date();
void setup(){
size(512,512);
background(100,100,0);
}
void draw(){
}
void mousePressed(){
println(new Date() - oldtime);
oldtime=new Date();
}
There is a built in method/function for this called millis(), no need to use the Date class. There is also no reason to call var. I would also initialize your classes and variables in the setup method. Here is how these changes would look in your code in processing syntax:
int oldtime;
void setup(){
size(512,512);
background(100,100,0);
oldtime = millis()
}
void draw(){
}
void mousePressed(){
println(millis() - oldtime);
oldtime = millis()
}
If you are familiar with JavaScript you might find it beneficial use processing directly in javascript. That way it is easy to mix and match what you need and to use standard javascript debugging tools. There is a great tutorial on how to do this here:
http://processingjs.org/articles/jsQuickStart.html#javascriptonlyprocessingcode

Asynchronous callback - gwt

I am using gwt and postgres for my project. On the front end i have few widgets whose data i am trying to save on to tables at the back-end when i click on "save project" button(this also takes the name for the created project).
In the asynchronous callback part i am setting more than one table. But it is not sending the data properly. I am getting the following error:
org.postgresql.util.PSQLException: ERROR: insert or update on table "entitytype" violates foreign key constraint "entitytype_pname_fkey"
Detail: Key (pname)=(Project Name) is not present in table "project".
But when i do the select statement on project table i can see that the project name is present.
Here is how the callback part looks like:
oksave.addClickHandler(new ClickHandler(){
#Override
public void onClick(ClickEvent event) {
if(erasync == null)
erasync = GWT.create(EntityRelationService.class);
AsyncCallback<Void> callback = new AsyncCallback<Void>(){
#Override
public void onFailure(Throwable caught) {
}
#Override
public void onSuccess(Void result){ }
};
erasync.setProjects(projectname, callback);
for(int i = 0; i < boundaryPanel.getWidgetCount(); i++){
top = new Integer(boundaryPanel.getWidget(i).getAbsoluteTop()).toString();
left = new Integer(boundaryPanel.getWidget(i).getAbsoluteLeft()).toString();
if(widgetTitle.startsWith("ATTR")){
type = "regular";
erasync.setEntityAttribute(name1, name, type, top, left, projectname, callback);
} else{
erasync.setEntityType(name, top, left, projectname, callback);
}
}
}
Question:
Is it wrong to set more than one in the asynchronous callback where all the other tables are dependent on a particular table?
when i say setProjects in the above code isn't it first completed and then moved on to the next one?
Please any input will be greatly appreciated.
Thank you.
With that foreign key constraint, you must make sure the erasync.setProjects(...) has completed before you insert the rest of the stuff.
I suggest doing the erasync.setEntityAttribute(...) magic in (or from) an onsuccess callback instead of jumping right to it.
You're firing several request in which (guessing from the error message) really should be called in sequence.
Any time you call more than one rpc call; try to think that you should be able to rearrange them in any order (because that's allmost what actually happens because they're asynchronous)... If running them in reverse order does not make sense; you cannot fire them sequentially!
Two ways to fix your problem:
Nesting:
service.callFirst(someData, new AsyncCallback<Void> callback = new AsyncCallback<Void>(){
#Override
public void onFailure(Throwable caught) {/*Handle errors*/}
#Override
public void onSuccess(Void result){
service.callSecond(someOtherData, new AsyncCallback<Void> callback = new AsyncCallback<Void>(){
/* onSuccess and onFailure for second callback here */
});
}
});
Or creating one service call that does both (Recommended):
service.callFirstAndSecond(someData, someOtherData, new AsyncCallback<Void> callback = new AsyncCallback<Void>(){
#Override
public void onFailure(Throwable caught) {/*Handle errors*/}
#Override
public void onSuccess(Void result){
/* Handle success */
}
});
The second option is most likely going to be much less messy, as several nested asynch callbacks quickly grows quite wide and confusing, also you make just one request.
Because of nature of Async, don't assume setProjects(...) method will be called on the server before setEntityAttribute or setEntityType.
Personally, I prefer to have a Project class which contains all necessary info, for example:
public class Project{
private String projectName;
private List attributes = new ArrayList();
.. other properties
// Getter & Setter methods
}
Then send to the server in one round trip:
Project project = new Project();
project.setProjectName(..);
// Set other properties
erasync.saveProjects(project, callback);