Wednesday, October 23, 2013

How to read a character using scanf in a loop

It is tricky to read a character in a loop using scanf function.

if you use scanf like below
#include <stdio.h>
 
int main(void) {
  char ch;
  do
  {
    printf("enter a char: ");
    scanf("%c", &ch);
 
    printf("\nentered: %c\n", ch);
  } while(ch != 'q');
 
  return 0;
}

You will see an output like below
enter a char: s

entered: s
enter a char: 
entered: 

enter a char: 

The second input get automatically printed. This is because the when you reading characters using scanf, it reads all the types of characters one by one, including the special characters like "enter". Therefore, in this case it reads "s" character in the first scanf and "enter" in the next scanf. But if you read a integer (%d) using scanf then this does not happen, thats because %d discard all the special characters and only reads the integer part.

You can instruct the scanf to ignore the special characters by prefixing %c by a space character. See the following example.
#include <stdio.h>
 
int main(void) {
  char ch;
  do
  {
    printf("enter a char: ");
    scanf(" %c", &ch);
 
    printf("\nentered: %c\n", ch);
  } while(ch != 'q');
 
  return 0;
}

You will see the following output
enter a char: s

entered: s
enter a char: 

Wednesday, October 16, 2013

How to check whether the GPU support power profiling in NVIDIA Visual Profiler

CUDA 5.5 announced that NVIDIA's Visual Profiler supports power, thermal and clock profiling. I tried the profiler on a GTX 480, but it only profile the thermal values in different timestamps, but not power nor clock.

If you are wondering whether your GPU supports power profiling, you can verify it by running the following command.

nvidia-smi -q -d power

This command should return something similar to below with actual power values.

Attached GPUs                       : 1
GPU 0000:00:00.0
    Power Readings
        Power Management            : XXX
        Power Draw                  : XXX
        Power Limit                 : XXX
        Default Power Limit         : XXX
        Enforced Power Limit        : XXX
        Min Power Limit             : XXX
        Max Power Limit             : XXX

If the values are "N/A", then your GPU does not support power profiling.

Monday, May 14, 2012

Webinar - Using WSO2 Carbon to Help Convert One-Sixth of New Zealand’s Population into Mobile Telecom Customers

The webinar for my previous post - WSO2 Middleware to Enable Mobile Services for Telecommunications is scheduled on 17th May 2012.

Join Asanka Abeysinghe, WSO2 Director Solutions Architecture, and Waruna Ranasinghe, WSO2 Senior Software Engineer, along with Guest Speaker Neeraj Satja, 2degrees Mobile Software Development Manager, for a discussion on how the WSO2 Carbon enterprise middleware platform has enabled 2degrees to deliver the innovation, high volume and high performance required to be a mobile market leader.


Sunday, March 11, 2012

WSO2 Middleware to Enable Mobile Services for Telecommunications

"With WSO2 Carbon, we’ve found a strong middleware platform that is enabling us to deliver the innovation, high volume and high performance required to be a mobile market leader." says 2degrees Software Development Manager Neeraj Satija.

2Degrees Mobile, despite being the newest mobile company in New Zealand, has been able attract 1/6 of the New Zealand population. Having entered a saturated market, 2Degrees has been providing innovative services to users to attract customers from established mobile companies. WSO2 Middleware Platform (i.e WSO2 ESB) has facilitated them to enable innovative mobile services rapidly. It is the WSO2 Middleware that enabled 2Degrees to increase the response to the market by providing most suited middleware to rapidly implement mobile services. 

Currently, 2 Degrees uses WSO2 ESB, WSO2 DSS and WSO2 BPS to enable Mobile Services to the customers.

Read More...
Download the complete case-study.

Saturday, November 26, 2011

How to read HTTP headers through Synapse Config

You can use the following property mediator to read HTTP headers inside WSO2 ESB through Synapse Configuration.
<property name="Lang" expression="get-property('transport', 'Accept')"/>

Here, the value of the HTTP header called "Accept" get assigned in to property called "Lang"

Thursday, November 24, 2011

How to apply throttling policies through service.xml

You can always apply throttling to services deployed in WSO2 AS using the Management console. But what if you want to apply the throttling policy while the service get deployed. Then you can specify the throttling policy in the service.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file was auto-generated from WSDL -->
<!-- by the Apache Axis2 version: 1.6.1-wso2v1  Built on : Jun 08, 2011 (07:37:38 IST) -->
<serviceGroup>
    <service name="echo">
        <messageReceivers>
            <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out" class="org.wso2.carbon.sample.service.echo.EchoMessageReceiverInOut"/>
        </messageReceivers>
        <parameter name="ServiceClass">org.wso2.carbon.sample.service.echo.EchoSkeleton</parameter>
        <parameter name="useOriginalwsdl">true</parameter>
        <parameter name="modifyUserWSDLPortAddress">true</parameter>
        <operation name="echoString" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://echo.services.core.carbon.wso2.org">
            <actionMapping>urn:echoString</actionMapping>
            <outputActionMapping>urn:echoStringResponse</outputActionMapping>
            <faultActionMapping faultName="echoFault">urn:echoFaultMessage</faultActionMapping>
            <faultActionMapping faultName="EchoFault">urn:echoFaultMessage</faultActionMapping>
            <faultActionMapping faultName="EchoFault_Exception">urn:echoFaultMessage</faultActionMapping>
        </operation>
        <operation name="throwAxisFault" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://echo.services.core.carbon.wso2.org">
            <actionMapping>urn:throwAxisFault</actionMapping>
            <outputActionMapping>urn:throwAxisFaultResponse</outputActionMapping>
        </operation>
        <operation name="echoStringArrays" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://echo.services.core.carbon.wso2.org">
            <actionMapping>urn:echoStringArrays</actionMapping>
            <outputActionMapping>urn:echoStringArraysResponse</outputActionMapping>
        </operation>
        <operation name="echoOMElement" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://echo.services.core.carbon.wso2.org">
            <actionMapping>urn:echoOMElement</actionMapping>
            <outputActionMapping>urn:echoOMElementResponse</outputActionMapping>
        </operation>
        <operation name="echoInt" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://echo.services.core.carbon.wso2.org">
            <actionMapping>urn:echoInt</actionMapping>
            <outputActionMapping>urn:echoIntResponse</outputActionMapping>
        </operation>
 
       <module ref="wso2throttle"/>
       <wsp:Policy wsu:Id="WSO2ServiceThrottlingPolicy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <wsp:ExactlyOne>
    <wsp:All>
      <throttle:ServiceThrottleAssertion xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle">
        <wsp:Policy>
          <throttle:ID throttle:type="DOMAIN">172.16.49.1</throttle:ID>
          <wsp:Policy>
            <throttle:Control>
              <wsp:Policy>
                <throttle:MaximumCount>2</throttle:MaximumCount>
                <throttle:UnitTime>20000</throttle:UnitTime>
                <throttle:ProhibitTimePeriod wsp:Optional="true">30000</throttle:ProhibitTimePeriod>
              </wsp:Policy>
            </throttle:Control>
          </wsp:Policy>
        </wsp:Policy>
        <wsp:Policy>
          <throttle:ID throttle:type="DOMAIN">other</throttle:ID>
          <wsp:Policy>
            <throttle:Deny/>
          </wsp:Policy>
        </wsp:Policy>
      </throttle:ServiceThrottleAssertion>
    </wsp:All>
  </wsp:ExactlyOne>
</wsp:Policy>
    </service>
</serviceGroup>

Tuesday, August 9, 2011

WSO2Con 2011

Architects, Developers, IT Managers and technology enthusiasts, WSO2Con 2011, focuses on you! Newbie or seasoned professional, WSO2Con offers a great week of learning, sharing and the opportunity to connect with experts who have shaped the future enterprise. Register here