Example #1
0
/// The main function. Creates a filter, configures it, launches the
/// filtering thread, handles user input, and cleans up resources when
/// exiting.  The intention is to run this program with a command line
/// argument specifying the configuration file to use.
/// @param argc Number of command line arguments
/// @param argv Command line arguments
/// @return EXIT_SUCCESS or EXIT_FAILURE
int main(int argc, char* argv[])
{
   // TODO: implement function

   char input[20];
   short mode;
   pthread_t filterThread;
   int rc;

   if (argc != 2){
       fprintf(stderr, "usage: firewall <config_file>\n");
       return EXIT_SUCCESS;
   }
   IpPktFilter filter = CreateFilter();
   if (!ConfigureFilter(filter, argv[1])){
       return EXIT_FAILURE;
   }

   rc = pthread_create(&filterThread, NULL, FilterThread, (void*) filter);

   if (rc){
      fprintf(stderr, "Could not create filter thread");
      return EXIT_FAILURE;
   }

   DisplayMenu();
   while(Mode){
      printf("> ");
      char* s = fgets(input, 20 , stdin);
      if (s){};
      mode = ((short) input[0]) -48;

      if (mode == MODE_BLOCK_ALL){
         Mode = MODE_BLOCK_ALL;
      }
      else if (mode == MODE_ALLOW_ALL){
         Mode = MODE_ALLOW_ALL;
      }
      else if (mode == MODE_FILTER){
         Mode = MODE_FILTER;
      }
      else if (mode == 0){
         Mode = 0;
         pthread_join(filterThread, NULL);
         break;
      }

   }

   DestroyFilter(filter);
   return EXIT_SUCCESS;
}
void CPorterDuffColorFilter::Update()
{
    DestroyFilter(mNativeInstance);
    mNativeInstance = NativeCreatePorterDuffFilter(mColor, mMode);
}
void CLightingColorFilter::Update()
{
    DestroyFilter(mNativeInstance);
    mNativeInstance = NativeCreateLightingFilter(mMul, mAdd);
}