Smart Recent Blog Post List

Discover the power of algorithms

Complexities of algorithm, thier applicability. Optimization techniques associated with diffrent algos.

Discover Power of Blogging

What is Blogging , is it a Dream or Passion or Award or Making Money ?

Think Diffrent, be creative

Let's see how much conclusion one can draw from it. This will help testing your creativity.

Discover the power of technology

Technolgy, Programming, Optimization , Gadgets and more...

Discover the power of Blogging

Google widgets and gadgets.

Oct 1, 2013

Running bat file from the C++ source code

What to do when one has to execute batch script from the c++ source code ?

System command can solve the purpose in this context.
Here is the syntax details :-

int system(  const char *command );
int _wsystem(   const wchar_t *command );


Example :-
  Suppose if some one want to restart a service named "TestService" form the batch file.
Then c:\\sample.bat file would look like as:-

net stop TestService
net start TestService

calling it from source code:-
    system ("c:\\sample.bat");



For API refrenece
http://msdn.microsoft.com/en-us/library/277bwbdz(v=vs.90).aspx




Dec 13, 2011

How to increase service start/stop timeout ?


Windows provide SetServiceStatus function by which one can manage service time out period. It’s a very straight forward API here are its details:-
         BOOL WINAPI SetServiceStatus(
                            __in  SERVICE_STATUS_HANDLE hServiceStatus,
                            __in  LPSERVICE_STATUS lpServiceStatus
                          );

To manage timeout one need to inform SCM periodically about the current status of service. So if one have pending operations same information can be conveyed with this interface to SCM.
A common bug is for the service to have the main thread perform the initialization while a separate thread continues to call SetServiceStatus to prevent the service control manager from marking it as hung. However, if the main thread hangs, then the service start ends up in an infinite loop because the worker thread continues to report that the main thread is making progress.

Here are the details of structure

typedef struct _SERVICE_STATUS {
  DWORD dwServiceType;
  DWORD dwCurrentState;
  DWORD dwControlsAccepted;
  DWORD dwWin32ExitCode;
  DWORD dwServiceSpecificExitCode;
  DWORD dwCheckPoint;
  DWORD dwWaitHint;
} SERVICE_STAT

And following are the main parameters to be used while managing service time out duration in the structure

dwCheckPoint
The check-point value the service increments periodically to report its progress during a lengthy start, stop, pause, or continue operation. For example, the service should increment this value as it completes each step of its initialization when it is starting up. The user interface program that invoked the operation on the service uses this value to track the progress of the service during a lengthy operation. This value is not valid and should be zero when the service does not have a start, stop, pause, or continue operation pending.

dwWaitHint
The estimated time required for a pending start, stop, pause, or continue operation, in milliseconds. Before the specified amount of time has elapsed, the service should make its next call to the SetServiceStatus function with either an incremented dwCheckPoint value or a change in dwCurrentState. If the amount of time specified by dwWaitHint passes, and dwCheckPoint has not been incremented ordwCurrentState has not changed, the service control manager or service control program can assume that an error has occurred and the service should be stopped. However, if the service shares a process with other services, the service control manager cannot terminate the service application because it would have to terminate the other services sharing the process as well.

A sample code showing the use of above discussed variable :-

//
// Purpose: 
//   It will set the current service status and reports it to the SCM.
//
// Parameters:
//   dwCurrentState - The current state (see SERVICE_STATUS)
//   dwWin32ExitCode - The system error code
//   dwWaitHint - Estimated time for pending operation, 
//     in milliseconds
// 
VOID ReportServiceStatus( DWORD dwCurrentState,
                      DWORD dwWin32ExitCode,
                      DWORD dwWaitHint)
{
    static DWORD dwCheckPoint = 1;
 
    // Fill in the SERVICE_STATUS structure.
 
    gSvcStatus.dwCurrentState = dwCurrentState;
    gSvcStatus.dwWin32ExitCode = dwWin32ExitCode;
    gSvcStatus.dwWaitHint = dwWaitHint;
 
    if (dwCurrentState == SERVICE_START_PENDING)
        gSvcStatus.dwControlsAccepted = 0;
    else gSvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
 
    if ( (dwCurrentState == SERVICE_RUNNING) ||
           (dwCurrentState == SERVICE_STOPPED) )
        gSvcStatus.dwCheckPoint = 0;
    else gSvcStatus.dwCheckPoint = dwCheckPoint++;
 
    // Report the status of the service to the SCM.
    SetServiceStatus( gSvcStatusHandle, &gSvcStatus );
}


One more important thing to remember :

Ø   Do not wait longer than the wait hint. A good interval is one-tenth of the wait hint but not less than 1 second  and not more than 10 seconds.  
          Example:- 
 
        dwWaitTime = ssStatus.dwWaitHint / 10;
 
        if( dwWaitTime < 1000 )
            dwWaitTime = 1000;
        else if ( dwWaitTime > 10000 )
            dwWaitTime = 10000;



The following are some of the best practices when calling SetServiceStatus function:
  • Initialize all fields in the SERVICE_STATUS structure, ensuring that there are valid check-point and wait hint values for pending states. Use reasonable wait hints.
  • Do not register to accept controls while the status is SERVICE_START_PENDING or the service can crash. After initialization is completed, accept the SERVICE_CONTROL_STOP code.
  • Call this function with checkpoint and wait-hint values only if the service is making progress on the tasks related to the pending start, stop, pause, or continue operation. Otherwise, SCM cannot detect if your service is hung.
  • Enter the stopped state with an appropriate exit code if ServiceMain fails.
  • If the status is SERVICE_STOPPED, perform all necessary cleanup and call SetServiceStatus one time only. This function makes an LRPC call to the SCM. The first call to the function in the SERVICE_STOPPED state closes the RPC context handle and any subsequent calls can cause the process to crash.
  • Do not attempt to perform any additional work after calling SetServiceStatus with SERVICE_STOPPED, because the service process can be terminated at any time.



Dec 3, 2011

Inline function example, a sample program c++

Inline function examples :-
recommended article :- Inline Function

Lets look out one of the simple example :-
-------------------------------------------------------------------
// inline_functions_inline.cpp
#include 
#include 

inline char toupper( char a ) {
   return ((a >= 'a' && a <= 'z') ? a-('a'-'A') : a );
}

int main() {
   printf_s("Enter a character: ");
   char ch = toupper( getc(stdin) );
   printf_s( "%c", ch );
}
-------------------------------------------------------------------
Now  moving to example of using inline function inside a class :-
-------------------------------------------------------------------
// Inline_Member Function example
class CBankAccount
{
public:
    CBankAccount(double initial_balance) { balance = initial_balance; }
    double GetBalance();
    double Deposit( double Amount );
    double Withdraw( double Amount );
private:
    double balance;
};

inline double CBankAccount::GetBalance()
{
    return balance;
}

inline double CBankAccount::Deposit( double Amount )
{
    return ( balance += Amount );
}

inline double CBankAccount::Withdraw( double Amount )
{
    return ( balance -= Amount );
}

int main()
{
 CBankAccount objAccount;
 objAccount.Deposit(1000);
}
-------------------------------------------------------------------
Just as you can ask the compiler to make a regular function inline, you can make class methods inline. The keyword inline appears before the return value. In the class declaration, the functions were declared without the inline keyword. The inline keyword can be specified in the class declaration; the result is the same.
 Inline functions are best used for small functions such as accessing private data members. The main purpose of these one- or two-line "accessor" functions is to return state information about objects; short functions are sensitive to the overhead of function calls. Longer functions spend proportionately less time in the calling/returning sequence and benefit less from inlining.
 Read More :- Guidelines for using Inline function.

Check this out
----------------------------------------------------
harvard crimson tickets
hofstra pride tickets
houston baptist huskies tickets
----------------------------------------------------



Nov 22, 2011

How to start , stop perfmon from the command line in Windows ?

Logman command is the solution for it.
let's have a look at the command syntax

Syntax Verbs
Logman [create {counter | tracecollection_name ] [start collection_name] [stop collection_name] [delete collection_name] [query {collection_name|providers}] [update collection_name]

Parameter details:-

create {counter | tracecollection_name Creates collection queries for either counter or trace collections. You can use command line options to specify settings.
start collection_name Starts the data collection query collection_name. Use this option to change from scheduled collections to manual ones. Use the update parameter in the command line with begin-time (-b), end-time (-e), or repeat-time (-rt) to reschedule collections.
stop collection_name Stops the data collection query collection_name. Use this option to change from scheduled collections to manual ones. Use the update parameter in the command line with begin-time (-b), end-time (-e), or repeat-time (-rt) to reschedule collections.
delete collection_name Deletes the data collection query collection_name. If the collection_name does not exist, you will receive an error.
query {collection_name|providersIf no collection_name or providers are given, the status of all existing collection queries are displayed. Use collection_name to display the properties of a specific collection. To display the properties on remote computers, use the -s remote computer option in the command line. Use providers as your keyword in place of collection_name to display the registered providers installed on your local system. To list registered providers installed on the remote system, use the -soption in the command line.
update collection_name Updates collection queries for counter and trace collections. For counter collections, modifications to the query will stop, and then restart the collections. For trace collections, use the following parameters in the command line to query without stopping the collection: -p provider [(flags[,flags ...])Level- max n- o PathName-ft mm:ss, or -fd.


This command is very helpful in performance automation scenario.
If performance monitoring counter name is test_perf_log
then start command will go as :-
    logman start test_perf_log
on similar line stop command will go as:-
    logman stop test_perf_log


For more detail jump to page :- http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/nt_command_typeperf.mspx?mfr=true



Nov 1, 2011

Google MAP APIs to charge for usage, heavy traffic cost more

Google MAP server with their increased traffic has given a new dimension of earning to Google. With its success now Google is planning to charge for its usage.
Now one has to pay according to their usage.

Following is the cost estimation as per BBC
"The BBC is reporting that from 1 January 2012, Google will charge for the Google Maps API service when more than the limit of 25,000 map "hits" are made in a day. Google is rumoured to be charging $4 per 1,000 views in excess of the limit. Google maintains the high limit of 25,000 free hits before charging 'will only affect 0.35% of users.'"


In the Google announcement: "We understand that the introduction of these limits may be concerning. However with the continued growth in adoption of the Maps API we need to secure its long term future by ensuring that even when used by the highest volume for-profit sites, the service remains viable. By introducing these limits we are ensuring that Google can continue to offer the Maps API for free to the vast majority of developers for many years to come."

About Google Maps API

The Maps API is a free service, available for any web site that is free to consumers. Please see the terms of service for more information.
Businesses that charge fees for access, track assets or build internal applications must use Google Maps API Premier, which provides enhanced features, technical support and a service-level agreement.




indiana pacers ticketsTicketamerica.com has all of you're basketball NBA ticketing needs for teams like the indiana pacers and the milwaukee bucks as well as the atlanta hawks games, maps and seating charts.Links to follow :-  Disclosure :Pay Per Post Ad 



Oct 20, 2011

How to stop function inlining ?


__declspec(noinline) tells the compiler to never inline a particular member function (function in a class).
It may be worthwhile to not inline a function if it is small and not critical to the performance of your code.

 That is, if the function is small and not likely to be called often, such as a function that handles an error condition.

Keep in mind that if a function is marked noinline, the calling function will be smaller and thus, itself a candidate for compiler inlining.

More about inlining :-





Oct 16, 2011

Distance Calculation from Latitude/Longitude using Google MAP APIs between two locations

Here is a sample application which i have developed to get the direction, distance and duration between two location/places using Latitude/Longitude with the help of Google MAP APIs.
This application will also reveals that how can we retrieve place/city name from the Latitude/Longitude.

Let's look at the input of application :-
Just input Lat/Lng and press "get Directions with Distance/Duration!" and get the updated direction MAP with Distance and Duration.
Place A and Place B will displays the Lat/Lng resolved location.

Check out its demo :-



Google Maps API Sample, Distance from Latitude and Longitude between two locations

Maps API Directions Illustrated with Latitude and Longitude

From:    To: 
Place A:   Place B: 
Distance KM  Duration Minutes  
Language: 



Formatted DirectionsMap



Smart Recent Blog Post List