Move environment variable parsing to environment options 39/38639/2
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Thu, 23 Apr 2015 10:12:13 +0000 (11:12 +0100)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Thu, 23 Apr 2015 10:21:08 +0000 (11:21 +0100)
Change-Id: Ifd35a66a3c7e84d78bf9c86483dbbeee5b25309b

adaptors/base/environment-options.cpp
adaptors/base/environment-options.h
adaptors/base/environment-variables.h
adaptors/common/adaptor-impl.cpp
adaptors/common/adaptor-impl.h

index 118eb29..4859efe 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 // CLASS HEADER
 #include "environment-options.h"
 
+// EXTERNAL INCLUDES
+#include <cstdlib>
+#include <dali/integration-api/render-controller.h>
+#include <dali/public-api/math/math-utils.h>
+
+// INTERNAL INCLUDES
+#include <base/environment-variables.h>
+
 namespace Dali
 {
 
@@ -30,6 +38,42 @@ namespace Adaptor
 namespace
 {
 const unsigned int DEFAULT_STATISTICS_LOG_FREQUENCY = 2;
+
+unsigned int GetIntegerEnvironmentVariable( const char* variable, unsigned int defaultValue )
+{
+  const char* variableParameter = std::getenv(variable);
+
+  // if the parameter exists convert it to an integer, else return the default value
+  unsigned int intValue = variableParameter ? std::atoi(variableParameter) : defaultValue;
+  return intValue;
+}
+
+bool GetIntegerEnvironmentVariable( const char* variable, int& intValue )
+{
+  const char* variableParameter = std::getenv(variable);
+
+  if( !variableParameter )
+  {
+    return false;
+  }
+  // if the parameter exists convert it to an integer, else return the default value
+  intValue = std::atoi(variableParameter);
+  return true;
+}
+
+bool GetFloatEnvironmentVariable( const char* variable, float& floatValue )
+{
+  const char* variableParameter = std::getenv(variable);
+
+  if( !variableParameter )
+  {
+    return false;
+  }
+  // if the parameter exists convert it to an integer, else return the default value
+  floatValue = std::atof(variableParameter);
+  return true;
+}
+
 }
 EnvironmentOptions::EnvironmentOptions()
 : mNetworkControl(0),
@@ -50,32 +94,18 @@ EnvironmentOptions::EnvironmentOptions()
   mPanMinimumEvents(-1),
   mGlesCallTime(0),
   mWindowWidth( 0 ),
-  mWindowHeight( 0 ),
-  mLogFunction( NULL )
+  mWindowHeight( 0 )
 {
+  ParseEnvironmentOptions();
 }
 
 EnvironmentOptions::~EnvironmentOptions()
 {
 }
 
-void EnvironmentOptions::SetLogOptions( const Dali::Integration::Log::LogFunction& logFunction,
-                             unsigned int networkControl,
-                             unsigned int logFrameRateFrequency,
-                             unsigned int logupdateStatusFrequency,
-                             unsigned int logPerformanceStats,
-                             unsigned int logPerformanceStatsFrequency,
-                             unsigned int performanceTimeStampOutput,
-                             unsigned int logPanGestureLevel )
+void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
 {
   mLogFunction = logFunction;
-  mNetworkControl = networkControl;
-  mFpsFrequency = logFrameRateFrequency;
-  mUpdateStatusFrequency = logupdateStatusFrequency;
-  mPerformanceStatsLevel = logPerformanceStats;
-  mPerformanceStatsFrequency = logPerformanceStatsFrequency;
-  mPerformanceTimeStampOutput= performanceTimeStampOutput;
-  mPanGestureLoggingLevel = logPanGestureLevel;
 }
 
 void EnvironmentOptions::InstallLogFunction() const
@@ -247,6 +277,101 @@ bool EnvironmentOptions::PerformanceServerRequired() const
            ( GetNetworkControlMode() > 0) );
 }
 
+void EnvironmentOptions::ParseEnvironmentOptions()
+{
+  // get logging options
+  mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
+  mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
+  mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
+  mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
+  mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
+  mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
+  mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
+
+  int predictionMode;
+  if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
+  {
+    SetPanGesturePredictionMode(predictionMode);
+  }
+  int predictionAmount(-1);
+  if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
+  {
+    if( predictionAmount < 0 )
+    {
+      // do not support times in the past
+      predictionAmount = 0;
+    }
+    SetPanGesturePredictionAmount(predictionAmount);
+  }
+  int minPredictionAmount(-1);
+  if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
+  {
+    if( minPredictionAmount < 0 )
+    {
+      // do not support times in the past
+      minPredictionAmount = 0;
+    }
+    SetPanGestureMinimumPredictionAmount(minPredictionAmount);
+  }
+  int maxPredictionAmount(-1);
+  if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
+  {
+    if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
+    {
+      // maximum amount should not be smaller than minimum amount
+      maxPredictionAmount = minPredictionAmount;
+    }
+    SetPanGestureMaximumPredictionAmount(maxPredictionAmount);
+  }
+  int predictionAmountAdjustment(-1);
+  if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
+  {
+    if( predictionAmountAdjustment < 0 )
+    {
+      // negative amount doesn't make sense
+      predictionAmountAdjustment = 0;
+    }
+    SetPanGesturePredictionAmountAdjustment(predictionAmountAdjustment);
+  }
+  int smoothingMode;
+  if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
+  {
+    SetPanGestureSmoothingMode(smoothingMode);
+  }
+  float smoothingAmount = 1.0f;
+  if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
+  {
+    smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
+    SetPanGestureSmoothingAmount(smoothingAmount);
+  }
+
+  int minimumDistance(-1);
+  if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
+  {
+    SetMinimumPanDistance( minimumDistance );
+  }
+
+  int minimumEvents(-1);
+  if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
+  {
+    SetMinimumPanEvents( minimumEvents );
+  }
+
+  int glesCallTime(0);
+  if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
+  {
+    SetGlesCallTime( glesCallTime );
+  }
+
+  int windowWidth(0), windowHeight(0);
+  if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
+  {
+    SetWindowWidth( windowWidth );
+    SetWindowHeight( windowHeight );
+  }
+
+}
+
 } // Adaptor
 
 } // Internal
index 61e692b..438c1a6 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_ADAPTOR_ENVIRONMENT_OPTIONS_H__
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -29,9 +29,9 @@ namespace Adaptor
 {
 
 /**
- * Contains environment options which define settings and the ability to install a log function.
+ * This class provides the environment options which define settings as well as
+ * the ability to install a log function.
  *
- * TODO: This file and adaptor needs cleaning up. There should not be any environment options in the adaptor class, only here!
  */
 class EnvironmentOptions
 {
@@ -50,23 +50,8 @@ public:
 
   /**
    * @param logFunction logging function
-   * @param networkControl whether network control is enabled
-   * @param logFilterOptions bitmask of the logging options defined in intergration/debug.h (e.g.
-   * @param logFrameRateFrequency frequency of how often FPS is logged out (e.g. 0 = off, 2 = every 2 seconds).
-   * @param logupdateStatusFrequency frequency of how often the update status is logged in number of frames
-   * @param logPerformanceStats performance statistics logging, 0 = disabled,  1+ =  enabled
-   * @param logPerformanceStatsFrequency statistics logging frequency in seconds
-   * @param performanceTimeStampOutput where to output performance related time stamps to
-   * @param logPanGestureLevel pan-gesture logging, 0 = disabled,  1 = enabled
-   */
-  void SetLogOptions( const Dali::Integration::Log::LogFunction& logFunction,
-                       unsigned int networkControl,
-                       unsigned int logFrameRateFrequency,
-                       unsigned int logupdateStatusFrequency,
-                       unsigned int logPerformanceStats,
-                       unsigned int logPerformanceStatsFrequency,
-                       unsigned int performanceTimeStampOutput,
-                       unsigned int logPanGestureLevel );
+   */
+  void SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction );
 
   /**
    * Install the log function for the current thread.
@@ -262,7 +247,15 @@ public:
    */
   bool PerformanceServerRequired() const;
 
-private:
+private: // Internal
+
+  /**
+   * Parses the environment options.
+   * Called from the constructor
+   */
+  void ParseEnvironmentOptions();
+
+private: // Data
 
   unsigned int mNetworkControl;                   ///< whether network control is enabled
   unsigned int mFpsFrequency;                     ///< how often fps is logged out in seconds
index 67e1c4a..9029dc1 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_ADAPTOR_ENVIRONMENT_VARIABLES_H__
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
index b8eee04..8cd32dc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
 #include "adaptor-impl.h"
 
 // EXTERNAL INCLUDES
-#include <boost/thread/tss.hpp>
 #include <dali/public-api/common/dali-common.h>
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/core.h>
@@ -30,7 +29,6 @@
 
 // INTERNAL INCLUDES
 #include <base/update-render-controller.h>
-#include <base/environment-variables.h>
 #include <base/performance-logging/performance-interface-factory.h>
 #include <base/lifecycle-observer.h>
 
@@ -41,7 +39,6 @@
 #include <render-surface.h>
 #include <tts-player-impl.h>
 #include <accessibility-manager-impl.h>
-#include <timer-impl.h>
 #include <events/gesture-manager.h>
 #include <events/event-handler.h>
 #include <feedback/feedback-controller.h>
@@ -72,43 +69,7 @@ namespace Adaptor
 
 namespace
 {
-boost::thread_specific_ptr<Adaptor> gThreadLocalAdaptor;
-
-unsigned int GetIntegerEnvironmentVariable( const char* variable, unsigned int defaultValue )
-{
-  const char* variableParameter = std::getenv(variable);
-
-  // if the parameter exists convert it to an integer, else return the default value
-  unsigned int intValue = variableParameter ? atoi(variableParameter) : defaultValue;
-  return intValue;
-}
-
-bool GetIntegerEnvironmentVariable( const char* variable, int& intValue )
-{
-  const char* variableParameter = std::getenv(variable);
-
-  if( !variableParameter )
-  {
-    return false;
-  }
-  // if the parameter exists convert it to an integer, else return the default value
-  intValue = atoi(variableParameter);
-  return true;
-}
-
-bool GetFloatEnvironmentVariable( const char* variable, float& floatValue )
-{
-  const char* variableParameter = std::getenv(variable);
-
-  if( !variableParameter )
-  {
-    return false;
-  }
-  // if the parameter exists convert it to an integer, else return the default value
-  floatValue = atof(variableParameter);
-  return true;
-}
-
+__thread Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
 } // unnamed namespace
 
 Dali::Adaptor* Adaptor::New( Any nativeWindow, RenderSurface *surface, const DeviceLayout& baseLayout,
@@ -123,111 +84,13 @@ Dali::Adaptor* Adaptor::New( Any nativeWindow, RenderSurface *surface, const Dev
   return adaptor;
 }
 
-void Adaptor::ParseEnvironmentOptions()
-{
-  // get logging options
-  unsigned int logFrameRateFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
-  unsigned int logupdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
-  unsigned int logPerformanceStats = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
-  unsigned int logPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
-  unsigned int performanceTimeStampOutput= GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
-  unsigned int networkControl= GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
-
-  unsigned int logPanGesture = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
-
-  // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
-  Dali::Integration::Log::LogFunction  logFunction(Dali::TizenPlatform::LogMessage);
-
-  mEnvironmentOptions.SetLogOptions( logFunction, networkControl, logFrameRateFrequency, logupdateStatusFrequency, logPerformanceStats, logPerformanceStatsFrequency, performanceTimeStampOutput, logPanGesture );
-
-  int predictionMode;
-  if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
-  {
-    mEnvironmentOptions.SetPanGesturePredictionMode(predictionMode);
-  }
-  int predictionAmount(-1);
-  if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
-  {
-    if( predictionAmount < 0 )
-    {
-      // do not support times in the past
-      predictionAmount = 0;
-    }
-    mEnvironmentOptions.SetPanGesturePredictionAmount(predictionAmount);
-  }
-  int minPredictionAmount(-1);
-  if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
-  {
-    if( minPredictionAmount < 0 )
-    {
-      // do not support times in the past
-      minPredictionAmount = 0;
-    }
-    mEnvironmentOptions.SetPanGestureMinimumPredictionAmount(minPredictionAmount);
-  }
-  int maxPredictionAmount(-1);
-  if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
-  {
-    if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
-    {
-      // maximum amount should not be smaller than minimum amount
-      maxPredictionAmount = minPredictionAmount;
-    }
-    mEnvironmentOptions.SetPanGestureMaximumPredictionAmount(maxPredictionAmount);
-  }
-  int predictionAmountAdjustment(-1);
-  if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
-  {
-    if( predictionAmountAdjustment < 0 )
-    {
-      // negative amount doesn't make sense
-      predictionAmountAdjustment = 0;
-    }
-    mEnvironmentOptions.SetPanGesturePredictionAmountAdjustment(predictionAmountAdjustment);
-  }
-  int smoothingMode;
-  if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
-  {
-    mEnvironmentOptions.SetPanGestureSmoothingMode(smoothingMode);
-  }
-  float smoothingAmount = 1.0f;
-  if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
-  {
-    smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
-    mEnvironmentOptions.SetPanGestureSmoothingAmount(smoothingAmount);
-  }
-
-  int minimumDistance(-1);
-  if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
-  {
-    mEnvironmentOptions.SetMinimumPanDistance( minimumDistance );
-  }
-
-  int minimumEvents(-1);
-  if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
-  {
-    mEnvironmentOptions.SetMinimumPanEvents( minimumEvents );
-  }
 
-  int glesCallTime(0);
-  if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
-  {
-    mEnvironmentOptions.SetGlesCallTime( glesCallTime );
-  }
-
-  int windowWidth(0), windowHeight(0);
-  if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
-  {
-    mEnvironmentOptions.SetWindowWidth( windowWidth );
-    mEnvironmentOptions.SetWindowHeight( windowHeight );
-  }
-
-  mEnvironmentOptions.InstallLogFunction();
-}
-
-void Adaptor::Initialize(Dali::Configuration::ContextLoss configuration)
+void Adaptor::Initialize( Dali::Configuration::ContextLoss configuration )
 {
-  ParseEnvironmentOptions();
+  // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
+  Dali::Integration::Log::LogFunction logFunction( Dali::TizenPlatform::LogMessage );
+  mEnvironmentOptions.SetLogFunction( logFunction );
+  mEnvironmentOptions.InstallLogFunction(); // install logging for main thread
 
   mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
 
@@ -323,8 +186,8 @@ Adaptor::~Adaptor()
   // Ensure stop status
   Stop();
 
-  // Release first as we do not want any access to Adaptor as it is being destroyed.
-  gThreadLocalAdaptor.release();
+  // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
+  gThreadLocalAdaptor = NULL;
 
   for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
   {
@@ -620,13 +483,13 @@ bool Adaptor::CallFromMainLoop( CallbackBase* callback )
 
 Dali::Adaptor& Adaptor::Get()
 {
-  DALI_ASSERT_ALWAYS( gThreadLocalAdaptor.get() != NULL && "Adaptor not instantiated" );
+  DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
   return gThreadLocalAdaptor->mAdaptor;
 }
 
 bool Adaptor::IsAvailable()
 {
-  return gThreadLocalAdaptor.get() != NULL;
+  return gThreadLocalAdaptor != NULL;
 }
 
 Dali::Integration::Core& Adaptor::GetCore()
@@ -920,8 +783,8 @@ Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surfac
   mPerformanceInterface(NULL),
   mObjectProfiler(NULL)
 {
-  DALI_ASSERT_ALWAYS( gThreadLocalAdaptor.get() == NULL && "Cannot create more than one Adaptor per thread" );
-  gThreadLocalAdaptor.reset(this);
+  DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
+  gThreadLocalAdaptor = this;
 }
 
 // Stereoscopy
index fa29310..dcced3b 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_ADAPTOR_IMPL_H__
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -451,11 +451,6 @@ private:
 private:
 
   /**
-   * Helper to parse log options
-   */
-  void ParseEnvironmentOptions();
-
-  /**
    * Informs core the surface size has changed
    */
   void SurfaceSizeChanged(const PositionSize& positionSize);